List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:com.kircherelectronics.accelerationexplorer.filter.ImuLaCfQuaternion.java
/** * Calculates a rotation vector from the gyroscope angular speed values. * /*from w w w.jav a 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(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 ava2 s . c om * @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:edu.umn.cs.spatialHadoop.core.SpatialSite.java
/** * Returns the global index (partitions) of a file that is indexed using * the index command. If the file is not indexed, it returns null. * The return value is of type {@link GlobalIndex} where the generic * parameter is specified as {@link Partition}. * @param fs//w w w.ja va 2s . c o m * @param dir * @return */ public static GlobalIndex<Partition> getGlobalIndex(FileSystem fs, Path dir) { try { FileStatus[] allFiles; if (OperationsParams.isWildcard(dir)) { allFiles = fs.globStatus(dir); } else { allFiles = fs.listStatus(dir); } FileStatus masterFile = null; int nasaFiles = 0; for (FileStatus fileStatus : allFiles) { if (fileStatus.getPath().getName().startsWith("_master")) { if (masterFile != null) throw new RuntimeException("Found more than one master file in " + dir); masterFile = fileStatus; } else if (fileStatus.getPath().getName().toLowerCase() .matches(".*h\\d\\dv\\d\\d.*\\.(hdf|jpg|xml)")) { // Handle on-the-fly global indexes imposed from file naming of NASA data nasaFiles++; } } if (masterFile != null) { ShapeIterRecordReader reader = new ShapeIterRecordReader(fs.open(masterFile.getPath()), 0, masterFile.getLen()); Rectangle dummy = reader.createKey(); reader.setShape(new Partition()); ShapeIterator values = reader.createValue(); ArrayList<Partition> partitions = new ArrayList<Partition>(); while (reader.next(dummy, values)) { for (Shape value : values) { partitions.add((Partition) value.clone()); } } GlobalIndex<Partition> globalIndex = new GlobalIndex<Partition>(); globalIndex.bulkLoad(partitions.toArray(new Partition[partitions.size()])); String extension = masterFile.getPath().getName(); extension = extension.substring(extension.lastIndexOf('.') + 1); globalIndex.setCompact(GridRecordWriter.PackedIndexes.contains(extension)); globalIndex.setReplicated(GridRecordWriter.ReplicatedIndexes.contains(extension)); return globalIndex; } else if (nasaFiles > allFiles.length / 2) { // A folder that contains HDF files // Create a global index on the fly for these files based on their names Partition[] partitions = new Partition[allFiles.length]; for (int i = 0; i < allFiles.length; i++) { final Pattern cellRegex = Pattern.compile(".*(h\\d\\dv\\d\\d).*"); String filename = allFiles[i].getPath().getName(); Matcher matcher = cellRegex.matcher(filename); Partition partition = new Partition(); partition.filename = filename; if (matcher.matches()) { String cellname = matcher.group(1); int h = Integer.parseInt(cellname.substring(1, 3)); int v = Integer.parseInt(cellname.substring(4, 6)); partition.cellId = v * 36 + h; // Calculate coordinates on MODIS Sinusoidal grid partition.x1 = h * 10 - 180; partition.y2 = (18 - v) * 10 - 90; partition.x2 = partition.x1 + 10; partition.y1 = partition.y2 - 10; // Convert to Latitude Longitude double lon1 = partition.x1 / Math.cos(partition.y1 * Math.PI / 180); double lon2 = partition.x1 / Math.cos(partition.y2 * Math.PI / 180); partition.x1 = Math.min(lon1, lon2); lon1 = partition.x2 / Math.cos(partition.y1 * Math.PI / 180); lon2 = partition.x2 / Math.cos(partition.y2 * Math.PI / 180); partition.x2 = Math.max(lon1, lon2); } else { partition.set(-180, -90, 180, 90); partition.cellId = allFiles.length + i; } partitions[i] = partition; } GlobalIndex<Partition> gindex = new GlobalIndex<Partition>(); gindex.bulkLoad(partitions); return gindex; } else { return null; } } catch (IOException e) { LOG.info("Error retrieving global index of '" + dir + "'"); LOG.info(e); return null; } }
From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java
/** * Rotate the given tree layout// ww w .j a va 2 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);//w w w .j a va 2 s. 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:edu.stanford.slac.archiverappliance.PB.data.BoundaryConditionsSimulationValueGenerator.java
public DBR getJCASampleValue(ArchDBRTypes type, int secondsIntoYear) { switch (type) { case DBR_SCALAR_STRING: DBR_TIME_String retvalss = new DBR_TIME_String(new String[] { Integer.toString(secondsIntoYear) }); retvalss.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalss.setSeverity(1);/* w w w.j av a2s. c om*/ retvalss.setStatus(0); return retvalss; case DBR_SCALAR_SHORT: DBR_TIME_Short retvalsh; if (0 <= secondsIntoYear && secondsIntoYear < 1000) { // Check for some numbers around the minimum value retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MIN_VALUE + secondsIntoYear) }); } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) { // Check for some numbers around the maximum value retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MAX_VALUE - (secondsIntoYear - 1000)) }); } else { // Check for some numbers around 0 retvalsh = new DBR_TIME_Short(new short[] { (short) (secondsIntoYear - 2000) }); } retvalsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalsh.setSeverity(1); retvalsh.setStatus(0); return retvalsh; case DBR_SCALAR_FLOAT: DBR_TIME_Float retvalfl; if (0 <= secondsIntoYear && secondsIntoYear < 1000) { // Check for some numbers around the minimum value retvalfl = new DBR_TIME_Float(new float[] { Float.MIN_VALUE + secondsIntoYear }); } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) { // Check for some numbers around the maximum value retvalfl = new DBR_TIME_Float(new float[] { Float.MAX_VALUE - (secondsIntoYear - 1000) }); } else { // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits retvalfl = new DBR_TIME_Float(new float[] { (secondsIntoYear - 2000.0f) / secondsIntoYear }); } retvalfl.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalfl.setSeverity(1); retvalfl.setStatus(0); return retvalfl; case DBR_SCALAR_ENUM: DBR_TIME_Enum retvalen; retvalen = new DBR_TIME_Enum(new short[] { (short) (secondsIntoYear) }); retvalen.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalen.setSeverity(1); retvalen.setStatus(0); return retvalen; case DBR_SCALAR_BYTE: DBR_TIME_Byte retvalby; retvalby = new DBR_TIME_Byte(new byte[] { ((byte) (secondsIntoYear % 255)) }); retvalby.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalby.setSeverity(1); retvalby.setStatus(0); return retvalby; case DBR_SCALAR_INT: DBR_TIME_Int retvalint; if (0 <= secondsIntoYear && secondsIntoYear < 1000) { // Check for some numbers around the minimum value retvalint = new DBR_TIME_Int(new int[] { Integer.MIN_VALUE + secondsIntoYear }); } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) { // Check for some numbers around the maximum value retvalint = new DBR_TIME_Int(new int[] { Integer.MAX_VALUE - (secondsIntoYear - 1000) }); } else { // Check for some numbers around 0 retvalint = new DBR_TIME_Int(new int[] { (secondsIntoYear - 2000) }); } retvalint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvalint.setSeverity(1); retvalint.setStatus(0); return retvalint; case DBR_SCALAR_DOUBLE: DBR_TIME_Double retvaldb; if (0 <= secondsIntoYear && secondsIntoYear < 1000) { // Check for some numbers around the minimum value retvaldb = new DBR_TIME_Double(new double[] { (Double.MIN_VALUE + secondsIntoYear) }); } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) { // Check for some numbers around the maximum value retvaldb = new DBR_TIME_Double(new double[] { (Double.MAX_VALUE - (secondsIntoYear - 1000)) }); } else { // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits retvaldb = new DBR_TIME_Double( new double[] { ((secondsIntoYear - 2000.0) / (secondsIntoYear * 1000000)) }); } retvaldb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvaldb.setSeverity(1); retvaldb.setStatus(0); return retvaldb; case DBR_WAVEFORM_STRING: DBR_TIME_String retvst; // Varying number of copies of a typical value retvst = new DBR_TIME_String( Collections.nCopies(secondsIntoYear, Integer.toString(secondsIntoYear)).toArray(new String[0])); retvst.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvst.setSeverity(1); retvst.setStatus(0); return retvst; case DBR_WAVEFORM_SHORT: DBR_TIME_Short retvsh; retvsh = new DBR_TIME_Short( ArrayUtils.toPrimitive(Collections.nCopies(1, (short) secondsIntoYear).toArray(new Short[0]))); retvsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvsh.setSeverity(1); retvsh.setStatus(0); return retvsh; case DBR_WAVEFORM_FLOAT: DBR_TIME_Float retvf; // Varying number of copies of a typical value retvf = new DBR_TIME_Float(ArrayUtils.toPrimitive( Collections.nCopies(secondsIntoYear, (float) Math.cos(secondsIntoYear * Math.PI / 3600)) .toArray(new Float[0]))); retvf.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvf.setSeverity(1); retvf.setStatus(0); return retvf; case DBR_WAVEFORM_ENUM: DBR_TIME_Enum retven; retven = new DBR_TIME_Enum(ArrayUtils .toPrimitive(Collections.nCopies(1024, (short) secondsIntoYear).toArray(new Short[0]))); retven.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retven.setSeverity(1); retven.setStatus(0); return retven; case DBR_WAVEFORM_BYTE: DBR_TIME_Byte retvb; // Large number of elements in the array retvb = new DBR_TIME_Byte(ArrayUtils.toPrimitive(Collections .nCopies(65536 * secondsIntoYear, ((byte) (secondsIntoYear % 255))).toArray(new Byte[0]))); retvb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvb.setSeverity(1); retvb.setStatus(0); return retvb; case DBR_WAVEFORM_INT: DBR_TIME_Int retvint; // Varying number of copies of a typical value retvint = new DBR_TIME_Int(ArrayUtils.toPrimitive(Collections .nCopies(secondsIntoYear, secondsIntoYear * secondsIntoYear).toArray(new Integer[0]))); retvint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvint.setSeverity(1); retvint.setStatus(0); return retvint; case DBR_WAVEFORM_DOUBLE: DBR_TIME_Double retvd; // Varying number of copies of a typical value retvd = new DBR_TIME_Double(ArrayUtils.toPrimitive(Collections .nCopies(secondsIntoYear, Math.sin(secondsIntoYear * Math.PI / 3600)).toArray(new Double[0]))); retvd.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(secondsIntoYear)); retvd.setSeverity(1); retvd.setStatus(0); return retvd; case DBR_V4_GENERIC_BYTES: throw new RuntimeException("Currently don't support " + type + " when generating sample data"); default: throw new RuntimeException("We seemed to have missed a DBR type when generating sample data"); } }
From source file:Matrix4x4.java
/** * Apply rotation around z axis to this matrix. * /*from ww w .j a v a 2s .co 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 {/* www . j a v a2 s.c o m*/ 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:ddf.catalog.source.opensearch.OpenSearchSiteUtil.java
/** * Takes in a point radius search and converts it to a (rough approximation) bounding box. * * @param lon latitude in decimal degrees (WGS-84) * @param lat longitude in decimal degrees (WGS-84) * @param radius radius, in meters/*from w ww . j av a 2 s .c o m*/ * @return Array of bounding box coordinates in the following order: West South East North. Also * described as minX, minY, maxX, maxY (where longitude is the X-axis, and latitude is * the Y-axis). */ public static double[] createBBoxFromPointRadius(double lon, double lat, double radius) { double minX; double minY; double maxX; double maxY; double lonDifference = radius / (LAT_DEGREE_M * Math.cos(lat)); double latDifference = radius / LAT_DEGREE_M; minX = lon - lonDifference; if (minX < MIN_LON) { minX += MAX_ROTATION; } maxX = lon + lonDifference; if (maxX > MAX_LON) { maxX -= MAX_ROTATION; } minY = lat - latDifference; if (minY < MIN_LAT) { minY = Math.abs(minY + MAX_LAT) - MAX_LAT; } maxY = lat + latDifference; if (maxY > MAX_LAT) { maxY = MAX_LAT - (maxY - MAX_LAT); } return new double[] { minX, minY, maxX, maxY }; }
From source file:electrical_parameters.Carson.java
public void calcXg() { // this.Xg = this.Dik.copy(); // this.Xg = clearMatrix(this.Xg); double[] b;// w ww .ja v a2 s . c om double[] c; double[] d; double kik_xg; double fik; b = b(); c = c(); d = d(); calckik(); for (int i = 0; i < this.kik.getRowDimension(); i++) { for (int j = 0; j < this.kik.getColumnDimension(); j++) { fik = this.Fik.getEntry(i, j); kik_xg = this.kik.getEntry(i, j); this.Xg.setEntry(i, j, (4e-4) * omega * (((double) 1 / 2) * (0.6159315 - Math.log(kik_xg)) + b[0] * kik_xg * Math.cos(fik) - d[1] * pow(kik_xg, 2) * Math.cos(2 * fik) + b[2] * pow(kik_xg, 3) * Math.cos(3 * fik) - b[3] * ((c[3] - Math.log(kik_xg)) * pow(kik_xg, 4) * Math.cos(4 * fik) + fik * pow(kik_xg, 4) * Math.sin(4 * fik)) + b[4] * kik_xg * Math.cos(fik) - d[5] * pow(kik_xg, 2) * Math.cos(2 * fik) + b[6] * pow(kik_xg, 3) * Math.cos(3 * fik) - b[7] * ((c[7] - Math.log(kik_xg)) * pow(kik_xg, 4) * Math.cos(4 * fik) + fik * pow(kik_xg, 4) * Math.sin(4 * fik)))); } } }