List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:com.bolatu.gezkoncsvlogger.GyroOrientation.ImuOCfQuaternion.java
/** * Calculates a rotation vector from the gyroscope angular speed values. * //from w w w.j a va 2 s. c o m * @param gyroValues * @param deltaRotationVector * @param timeFactor * @see http://developer.android * .com/reference/android/hardware/SensorEvent.html#values */ private void getRotationVectorFromGyro() { // Calculate the angular speed of the sample float magnitude = (float) Math .sqrt(Math.pow(vGyroscope[0], 2) + Math.pow(vGyroscope[1], 2) + Math.pow(vGyroscope[2], 2)); // Normalize the rotation vector if it's big enough to get the axis if (magnitude > EPSILON) { vGyroscope[0] /= magnitude; vGyroscope[1] /= magnitude; vGyroscope[2] /= magnitude; } // Integrate around this axis with the angular speed by the timestep // in order to get a delta rotation from this sample over the timestep // We will convert this axis-angle representation of the delta rotation // into a quaternion before turning it into the rotation matrix. float thetaOverTwo = magnitude * dT / 2.0f; float sinThetaOverTwo = (float) Math.sin(thetaOverTwo); float cosThetaOverTwo = (float) Math.cos(thetaOverTwo); vDeltaGyroscope[0] = sinThetaOverTwo * vGyroscope[0]; vDeltaGyroscope[1] = sinThetaOverTwo * vGyroscope[1]; vDeltaGyroscope[2] = sinThetaOverTwo * vGyroscope[2]; vDeltaGyroscope[3] = cosThetaOverTwo; // Create a new quaternion object base on the latest rotation // measurements... quatGyroDelta = new Quaternion(vDeltaGyroscope[3], Arrays.copyOfRange(vDeltaGyroscope, 0, 3)); // Since it is a unit quaternion, we can just multiply the old rotation // by the new rotation delta to integrate the rotation. quatGyro = quatGyro.multiply(quatGyroDelta); }
From source file:com.kircherelectronics.accelerationexplorer.filter.ImuLaCfQuaternion.java
/** * Calculates a rotation vector from the gyroscope angular speed values. * /*from w w w . j av a 2 s.c om*/ * @param gyroValues * @param deltaRotationVector * @param timeFactor * @see http://developer.android * .com/reference/android/hardware/SensorEvent.html#values */ private void getRotationVectorFromGyro(float timeFactor) { // Calculate the angular speed of the sample float magnitude = (float) Math .sqrt(Math.pow(gyroscope[0], 2) + Math.pow(gyroscope[1], 2) + Math.pow(gyroscope[2], 2)); // Normalize the rotation vector if it's big enough to get the axis if (magnitude > EPSILON) { gyroscope[0] /= magnitude; gyroscope[1] /= magnitude; gyroscope[2] /= magnitude; } // Integrate around this axis with the angular speed by the timestep // in order to get a delta rotation from this sample over the timestep // We will convert this axis-angle representation of the delta rotation // into a quaternion before turning it into the rotation matrix. float thetaOverTwo = magnitude * timeFactor / 2.0f; float sinThetaOverTwo = (float) Math.sin(thetaOverTwo); float cosThetaOverTwo = (float) Math.cos(thetaOverTwo); deltaVectorGyro[0] = sinThetaOverTwo * gyroscope[0]; deltaVectorGyro[1] = sinThetaOverTwo * gyroscope[1]; deltaVectorGyro[2] = sinThetaOverTwo * gyroscope[2]; deltaVectorGyro[3] = cosThetaOverTwo; // Create a new quaternion object base on the latest rotation // measurements... quatGyroDelta = new Quaternion(deltaVectorGyro[3], Arrays.copyOfRange(deltaVectorGyro, 0, 3)); // Since it is a unit quaternion, we can just multiply the old rotation // by the new rotation delta to integrate the rotation. quatGyro = quatGyro.multiply(quatGyroDelta); }
From source file:Matrix4x4.java
/** * Apply rotation around Y axis to this matrix. * //from ww w.j a v a 2 s . c o m * @param angle Angle to rotate [radians]. */ public void rotateY(double angle) { Matrix4x4 rotationMatrix = new Matrix4x4(); double cosAngle = Math.cos(angle); double sinAngle = Math.sin(angle); rotationMatrix.setElement(0, 0, cosAngle); rotationMatrix.setElement(0, 2, -sinAngle); rotationMatrix.setElement(2, 0, sinAngle); rotationMatrix.setElement(2, 2, cosAngle); multiply(rotationMatrix); }
From source file:au.org.ala.biocache.web.MapController.java
public int convertLatToPixel(double lat) { return (int) Math.round(map_offset - map_radius * Math.log((1 + Math.sin(lat * Math.PI / 180)) / (1 - Math.sin(lat * Math.PI / 180))) / 2); }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Rotate the given tree layout//from w w w . j a va2 s.c o m * @param treeLayout * the layout to rotate * @param thetaRadians * the rotation in radians */ private void rotateTreeLayout(VisualTreeNode treeLayout, double thetaRadians) { double cosTheta = Math.cos(thetaRadians); double sinTheta = Math.sin(thetaRadians); this.rotateTreeLayoutRecursive(treeLayout, cosTheta, sinTheta); }
From source file:TexCoordTest.java
BranchGroup createDemLandscape() { final double LAND_WIDTH = 200; final double LAND_LENGTH = 200; final double nTileSize = 10; final double yMaxHeight = LAND_WIDTH / 8; // calculate how many vertices we need to store all the "tiles" that // compose the QuadArray. final int nNumTiles = (int) (((LAND_LENGTH / nTileSize) * 2) * ((LAND_WIDTH / nTileSize) * 2)); final int nVertexCount = 4 * nNumTiles; Point3f[] coordArray = new Point3f[nVertexCount]; Point2f[] texCoordArray = new Point2f[nVertexCount]; // create the Appearance for the landscape and initialize all // the texture coordinate generation parameters createAppearance(yMaxHeight);// www .j a va2s . c o m // create the parent BranchGroup BranchGroup bg = new BranchGroup(); // create the geometry and populate a QuadArray // we use a simple sin/cos function to create an undulating surface // in the X/Z dimensions. Y dimension is the distance "above sea-level". int nItem = 0; double yValue0 = 0; double yValue1 = 0; double yValue2 = 0; double yValue3 = 0; final double xFactor = LAND_WIDTH / 5; final double zFactor = LAND_LENGTH / 3; // loop over all the tiles in the environment for (double x = -LAND_WIDTH; x <= LAND_WIDTH; x += nTileSize) { for (double z = -LAND_LENGTH; z <= LAND_LENGTH; z += nTileSize) { // if we are not on the last row or column create a "tile" // and add to the QuadArray. Use CCW winding if (z < LAND_LENGTH && x < LAND_WIDTH) { yValue0 = yMaxHeight * Math.sin(x / xFactor) * Math.cos(z / zFactor); yValue1 = yMaxHeight * Math.sin(x / xFactor) * Math.cos((z + nTileSize) / zFactor); yValue2 = yMaxHeight * Math.sin((x + nTileSize) / xFactor) * Math.cos((z + nTileSize) / zFactor); yValue3 = yMaxHeight * Math.sin((x + nTileSize) / xFactor) * Math.cos(z / zFactor); // note, we do not assign any texture coordinates! coordArray[nItem++] = new Point3f((float) x, (float) yValue0, (float) z); coordArray[nItem++] = new Point3f((float) x, (float) yValue1, (float) (z + nTileSize)); coordArray[nItem++] = new Point3f((float) (x + nTileSize), (float) yValue2, (float) (z + nTileSize)); coordArray[nItem++] = new Point3f((float) (x + nTileSize), (float) yValue3, (float) z); } } } // create a GeometryInfo and assign the coordinates GeometryInfo gi = new GeometryInfo(GeometryInfo.QUAD_ARRAY); gi.setCoordinates(coordArray); // generate Normal vectors for the QuadArray that was populated. NormalGenerator normalGenerator = new NormalGenerator(); normalGenerator.generateNormals(gi); // wrap the GeometryArray in a Shape3D Shape3D shape = new Shape3D(gi.getGeometryArray(), m_Appearance); // add the Shape3D to a BranchGroup and return bg.addChild(shape); return bg; }
From source file:cpsControllers.ConversionController.java
private double sinc(double t) { if (t == 0) { return 1; } else {//w w w.j a v a2 s. c om return Math.sin(Math.PI * t) / (Math.PI * t); } }
From source file:Matrix4x4.java
/** * Apply rotation around z axis to this matrix. * //from w ww . ja v a 2 s . c o m * @param angle Angle to rotate [radians]. */ public void rotateZ(double angle) { Matrix4x4 rotationMatrix = new Matrix4x4(); double cosAngle = Math.cos(angle); double sinAngle = Math.sin(angle); rotationMatrix.setElement(0, 0, cosAngle); rotationMatrix.setElement(0, 1, sinAngle); rotationMatrix.setElement(1, 0, -sinAngle); rotationMatrix.setElement(1, 1, cosAngle); multiply(rotationMatrix); }
From source file:convcao.com.agent.ConvcaoNeptusInteraction.java
private double[] getBeamMeasurement(EstimatedState state, Distance d) { double[] ret = new double[4]; // H = Ca + Cb double varH = d.getValue(); double varCa = Math.cos(DVL_ANGLE) * varH; double varCb = Math.sin(DVL_ANGLE) * varH; String beamId = d.getEntityName(); if (beamId == null) beamId = "DVL Filtered"; double tide = 0; if (subtractTide) { try {/*from w ww .j a v a 2 s . com*/ tide = TidePredictionFactory.getTideLevel(state.getDate()); } catch (Exception e) { NeptusLog.pub().warn(e); } } double depth = state.getDepth(); double heading = state.getPsi(); /* DVL Beams * (0) | * | *(3) ---+--- (1) * | * | (2) */ switch (beamId) { // pointing down case "DVL Filtered": varCb = 0; varCa = varH; break; case "DVL Beam 1": heading += Math.toRadians(90); break; case "DVL Beam 2": heading += Math.toRadians(180); break; case "DVL Beam 3": heading += Math.toRadians(270); break; default: break; } LocationType ground = IMCUtils.getLocation(state); ground.setOffsetDistance(varCb); ground.setAzimuth(Math.toDegrees(heading)); ground.convertToAbsoluteLatLonDepth(); double c[] = coords.convert(ground); ret[0] = c[0]; ret[1] = c[1]; ret[2] = state.getDepth(); ret[3] = varCa + depth - tide; return ret; }
From source file:com.celements.photo.image.GenerateThumbnail.java
private void drawWatermark(String watermark, Graphics2D g2d, int width, int height) { //TODO implement 'secure' watermark (i.e. check if this algorithm secure or can it be easily reversed?) g2d.setColor(new Color(255, 255, 150)); AlphaComposite transprency = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.45f); g2d.setComposite(transprency);/*from w ww. j a v a 2s . c om*/ FontMetrics metrics = calcWatermarkFontSize(watermark, width, g2d); g2d.setFont(calcWatermarkFontSize(watermark, width, g2d).getFont()); // rotate around image center double angle = (Math.sin(height / (double) width)); g2d.rotate(-angle, width / 2.0, height / 2.0); g2d.drawString(watermark, (width - metrics.stringWidth(watermark)) / 2, ((height - metrics.getHeight()) / 2) + metrics.getAscent()); // undo rotation for correct copyright positioning g2d.rotate(angle, width / 2.0, height / 2.0); }