List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:edu.stanford.slac.archiverappliance.PB.data.StatusSeverityTest.java
private DBR getJCASampleValue(ArchDBRTypes type, int value, int severity, int status) { switch (type) { case DBR_SCALAR_STRING: DBR_TIME_String retvalss = new DBR_TIME_String(new String[] { Integer.toString(value) }); retvalss.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalss.setSeverity(severity);//from w ww .j a v a 2s .co m retvalss.setStatus(status); return retvalss; case DBR_SCALAR_SHORT: DBR_TIME_Short retvalsh; if (0 <= value && value < 1000) { // Check for some numbers around the minimum value retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MIN_VALUE + value) }); } else if (1000 <= value && value < 2000) { // Check for some numbers around the maximum value retvalsh = new DBR_TIME_Short(new short[] { (short) (Short.MAX_VALUE - (value - 1000)) }); } else { // Check for some numbers around 0 retvalsh = new DBR_TIME_Short(new short[] { (short) (value - 2000) }); } retvalsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalsh.setSeverity(severity); retvalsh.setStatus(status); return retvalsh; case DBR_SCALAR_FLOAT: DBR_TIME_Float retvalfl; if (0 <= value && value < 1000) { // Check for some numbers around the minimum value retvalfl = new DBR_TIME_Float(new float[] { Float.MIN_VALUE + value }); } else if (1000 <= value && value < 2000) { // Check for some numbers around the maximum value retvalfl = new DBR_TIME_Float(new float[] { Float.MAX_VALUE - (value - 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[] { (value - 2000.0f) / value }); } retvalfl.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalfl.setSeverity(severity); retvalfl.setStatus(status); return retvalfl; case DBR_SCALAR_ENUM: DBR_TIME_Enum retvalen; retvalen = new DBR_TIME_Enum(new short[] { (short) (value) }); retvalen.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalen.setSeverity(severity); retvalen.setStatus(status); return retvalen; case DBR_SCALAR_BYTE: DBR_TIME_Byte retvalby; retvalby = new DBR_TIME_Byte(new byte[] { ((byte) (value % 255)) }); retvalby.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalby.setSeverity(severity); retvalby.setStatus(status); return retvalby; case DBR_SCALAR_INT: DBR_TIME_Int retvalint; if (0 <= value && value < 1000) { // Check for some numbers around the minimum value retvalint = new DBR_TIME_Int(new int[] { Integer.MIN_VALUE + value }); } else if (1000 <= value && value < 2000) { // Check for some numbers around the maximum value retvalint = new DBR_TIME_Int(new int[] { Integer.MAX_VALUE - (value - 1000) }); } else { // Check for some numbers around 0 retvalint = new DBR_TIME_Int(new int[] { (value - 2000) }); } retvalint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvalint.setSeverity(severity); retvalint.setStatus(status); return retvalint; case DBR_SCALAR_DOUBLE: DBR_TIME_Double retvaldb; if (0 <= value && value < 1000) { // Check for some numbers around the minimum value retvaldb = new DBR_TIME_Double(new double[] { (Double.MIN_VALUE + value) }); } else if (1000 <= value && value < 2000) { // Check for some numbers around the maximum value retvaldb = new DBR_TIME_Double(new double[] { (Double.MAX_VALUE - (value - 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[] { ((value - 2000.0) / (value * 1000000)) }); } retvaldb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvaldb.setSeverity(severity); retvaldb.setStatus(status); 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(value, Integer.toString(value)).toArray(new String[0])); retvst.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvst.setSeverity(severity); retvst.setStatus(status); return retvst; case DBR_WAVEFORM_SHORT: DBR_TIME_Short retvsh; retvsh = new DBR_TIME_Short( ArrayUtils.toPrimitive(Collections.nCopies(1, (short) value).toArray(new Short[0]))); retvsh.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvsh.setSeverity(severity); retvsh.setStatus(status); 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(value, (float) Math.cos(value * Math.PI / 3600)).toArray(new Float[0]))); retvf.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvf.setSeverity(severity); retvf.setStatus(status); return retvf; case DBR_WAVEFORM_ENUM: DBR_TIME_Enum retven; retven = new DBR_TIME_Enum( ArrayUtils.toPrimitive(Collections.nCopies(1024, (short) value).toArray(new Short[0]))); retven.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retven.setSeverity(severity); retven.setStatus(status); 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 * value, ((byte) (value % 255))).toArray(new Byte[0]))); retvb.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvb.setSeverity(severity); retvb.setStatus(status); 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(value, value * value).toArray(new Integer[0]))); retvint.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvint.setSeverity(severity); retvint.setStatus(status); 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(value, Math.sin(value * Math.PI / 3600)).toArray(new Double[0]))); retvd.setTimeStamp(convertSecondsIntoYear2JCATimeStamp(value)); retvd.setSeverity(severity); retvd.setStatus(status); 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:com.kircherelectronics.accelerationexplorer.filter.ImuLaKfQuaternion.java
/** * Create an angle-axis vector, in this case a unit quaternion, from the * provided Euler angle's (presumably from SensorManager.getOrientation()). * //from w ww . j ava2s .c om * Equation from * http://www.euclideanspace.com/maths/geometry/rotations/conversions * /eulerToQuaternion/ * * @param orientation */ private void getRotationVectorFromAccelMag(float[] orientation) { // Assuming the angles are in radians. // getOrientation() values: // values[0]: azimuth, rotation around the Z axis. // values[1]: pitch, rotation around the X axis. // values[2]: roll, rotation around the Y axis. // Heading, Azimuth, Yaw double c1 = Math.cos(orientation[0] / 2); double s1 = Math.sin(orientation[0] / 2); // Pitch, Attitude // The equation assumes the pitch is pointed in the opposite direction // of the orientation vector provided by Android, so we invert it. double c2 = Math.cos(-orientation[1] / 2); double s2 = Math.sin(-orientation[1] / 2); // Roll, Bank double c3 = Math.cos(orientation[2] / 2); double s3 = Math.sin(orientation[2] / 2); double c1c2 = c1 * c2; double s1s2 = s1 * s2; double w = c1c2 * c3 - s1s2 * s3; double x = c1c2 * s3 + s1s2 * c3; double y = s1 * c2 * c3 + c1 * s2 * s3; double z = c1 * s2 * c3 - s1 * c2 * s3; // The quaternion in the equation does not share the same coordinate // system as the Android gyroscope quaternion we are using. We reorder // it here. // Android X (pitch) = Equation Z (pitch) // Android Y (roll) = Equation X (roll) // Android Z (azimuth) = Equation Y (azimuth) vectorAccelMag[0] = z; vectorAccelMag[1] = x; vectorAccelMag[2] = y; vectorAccelMag[3] = w; if (!hasOrientation) { quatAccelMag = new Quaternion(w, z, x, y); } }
From source file:com.example.gps_project.Places.java
public static double GetDistance(double lat1, double lng1, double lat2, double lng2) { double radLat1 = rad(lat1); double radLat2 = rad(lat2); double a = radLat1 - radLat2; double b = rad(lng1) - rad(lng2); double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * EARTH_RADIUS;/*from ww w. ja v a2s. co m*/ s = Math.round(s * 10000) / 10000; return s; }
From source file:com.bitnine.tadpole.graph.core.editor.extension.browserHandler.CypherFunctionService.java
/** * Sigma.js ?? ? .//from w w w . j ava 2 s. c o m * * @param nodeJsonString * @return */ protected String loadDataWithSigma(final String nodeJsonString) { String result = ""; JsonObject jsonNode = JsonObject.readFrom(nodeJsonString); ResultSet rs = null; java.sql.Connection javaConn = null; Statement statement = null; try { SqlMapClient client = TadpoleSQLManager.getInstance(userDB); String reqQuery = "match (n)-[r]->(p) where id(n) = '" + jsonNode.get("id").asString() + "' return n, r, p UNION match (n)-[r]->(p) where id(p) = '" + jsonNode.get("id").asString() + "' return n, r, p"; if (logger.isDebugEnabled()) logger.debug("Execute Math CQL : " + reqQuery); javaConn = client.getDataSource().getConnection(); statement = javaConn.createStatement(); rs = statement.executeQuery(reqQuery); ResultSetMetaData rsmt = rs.getMetaData(); SigmaGraph graph = new SigmaGraph(); Node node = null; GEdge edge = null; long row = 0; double parentAngle = 0; double angleDeg = 0; double nx = 0; double ny = 0; while (rs.next()) { row++; for (int columnIndex = 1; columnIndex <= rsmt.getColumnCount(); columnIndex++) { Object obj = rs.getObject(columnIndex); if (obj instanceof Vertex) { node = new Node(); Vertex vertex = (Vertex) obj; node.setLabel(vertex.getLabel()); angleDeg = (((360 / (rsmt.getColumnCount() * 10)) * (columnIndex * row))); nx = jsonNode.get("x").asDouble() + (100 * Math.cos((angleDeg * (Math.PI / 180)) - parentAngle)); ny = jsonNode.get("y").asDouble() + (100 * Math.sin((angleDeg * (Math.PI / 180)) - parentAngle)); node.setX(nx); node.setY(ny); node.setColor(AgensUtils.getRandomRGB()); node.setSize(500); graph.addNode(node); } else if (obj instanceof Edge) { edge = new GEdge(); Edge relation = (Edge) obj; edge.setId(relation.getEdgeId().getOid() + "." + relation.getEdgeId().getId()); edge.setLabel(relation.getLabel()); edge.setSource( relation.getStartVertexId().getOid() + "." + relation.getStartVertexId().getId()); edge.setTarget( relation.getEndVertexid().getOid() + "." + relation.getEndVertexid().getId()); edge.setType("arrow");//'line', 'curve', 'arrow', 'curvedArrow' edge.setColor(AgensUtils.getRandomRGB("100")); edge.setSize(0.5); if (logger.isDebugEnabled()) logger.debug("Relation is " + relation.toString() + ", edge is " + edge.toString()); graph.addEdge(edge); } else { if (logger.isDebugEnabled()) logger.debug("Unknow Class " + obj.getClass().toString()); } } } Gson gson = new Gson(); result = gson.toJson(graph); if (logger.isDebugEnabled()) logger.debug("##### Graph ####====>" + result); } catch (Exception e) { logger.error(e); } finally { try { if (statement != null) statement.close(); } catch (Exception e) { } try { if (rs != null) rs.close(); } catch (Exception e) { } try { if (javaConn != null) javaConn.close(); } catch (Exception e) { } } return result; }
From source file:uk.ac.cam.cl.dtg.util.locations.PostCodeIOLocationResolver.java
/** * @param lat1/*from www. ja v a 2s .c o m*/ * - latitude 1 * @param lon1 * - longitude 1 * @param lat2 * - latitude 2 * @param lon2 * - longitude 2 * @return - distance in miles */ private double getLatLonDistanceInMiles(final double lat1, final double lon1, final double lat2, final double lon2) { // borrowed from http://www.movable-type.co.uk/scripts/latlong.html int R = 6371000; double phi1 = Math.toRadians(lat1); double phi2 = Math.toRadians(lat2); double deltaPhi = Math.toRadians(lat2 - lat1); double deltaLambda = Math.toRadians(lon2 - lon1); double a = Math.sin(deltaPhi / 2) * Math.sin(deltaPhi / 2) + Math.cos(phi1) * Math.cos(phi2) * Math.sin(deltaLambda / 2) * Math.sin(deltaLambda / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double d = R * c; // convert from metres to miles d = (d / 1000) * 0.621371; return d; }
From source file:es.emergya.geo.util.Lambert.java
private LatLon Clark2GRS80(LatLon lambert) { double lat = lambert.lat(); // in radian double lon = lambert.lon(); // Lambert geographic => Lambert cartesian double N = Ellipsoid.clarke.a / (Math.sqrt(1.0 - Ellipsoid.clarke.e2 * Math.sin(lat) * Math.sin(lat))); double X = (N/* +height */) * Math.cos(lat) * Math.cos(lon); double Y = (N/* +height */) * Math.cos(lat) * Math.sin(lon); double Z = (N * (1.0 - Ellipsoid.clarke.e2)/* + height */) * Math.sin(lat); // Lambert => WGS84 ellipsoide similarity X += -168.0;//from w w w. j a v a 2 s. c o m Y += -60.0; Z += 320.0; // WGS84 cartesian => WGS84 geographic return Geographic(X, Y, Z, Ellipsoid.GRS80); }
From source file:com.samknows.measurement.activity.SamKnowsMapActivity.java
private LatLng getPoint(LatLng center, int radius, double angle) { // Get the coordinates of a circle point at the given angle double east = radius * Math.cos(angle); double north = radius * Math.sin(angle); double cLat = center.latitude; double cLng = center.longitude; double latRadius = 6371000 * Math.cos(cLat / 180 * Math.PI); double newLat = cLat + (north / 6371000 / Math.PI * 180); double newLng = cLng + (east / latRadius / Math.PI * 180); return new LatLng(newLat, newLng); }
From source file:com.bolatu.gezkoncsvlogger.GyroOrientation.ImuOCfQuaternion.java
/** * Create an angle-axis vector, in this case a unit quaternion, from the * provided Euler angle's (presumably from SensorManager.getOrientation()). * //from ww w. j a v a 2 s .c om * Equation from * http://www.euclideanspace.com/maths/geometry/rotations/conversions * /eulerToQuaternion/ * * @param orientation */ private void getRotationVectorFromAccelMag(float[] orientation) { // Assuming the angles are in radians. // getOrientation() values: // values[0]: azimuth, rotation around the Z axis. // values[1]: pitch, rotation around the X axis. // values[2]: roll, rotation around the Y axis. // Heading, Azimuth, Yaw double c1 = Math.cos(-orientation[0] / 2); double s1 = Math.sin(-orientation[0] / 2); // Pitch, Attitude // The equation assumes the pitch is pointed in the opposite direction // of the orientation vector provided by Android, so we invert it. double c2 = Math.cos(-orientation[1] / 2); double s2 = Math.sin(-orientation[1] / 2); // Roll, Bank double c3 = Math.cos(orientation[2] / 2); double s3 = Math.sin(orientation[2] / 2); double c1c2 = c1 * c2; double s1s2 = s1 * s2; double w = c1c2 * c3 - s1s2 * s3; double x = c1c2 * s3 + s1s2 * c3; double y = s1 * c2 * c3 + c1 * s2 * s3; double z = c1 * s2 * c3 - s1 * c2 * s3; // The quaternion in the equation does not share the same coordinate // system as the Android gyroscope quaternion we are using. We reorder // it here. // Android X (pitch) = Equation Z (pitch) // Android Y (roll) = Equation X (roll) // Android Z (azimuth) = Equation Y (azimuth) quatAccelMag = new Quaternion(w, z, x, y); }
From source file:com.kircherelectronics.accelerationexplorer.filter.ImuLaCfQuaternion.java
/** * Create an angle-axis vector, in this case a unit quaternion, from the * provided Euler angle's (presumably from SensorManager.getOrientation()). * /*from w w w. j a v a 2 s . c om*/ * Equation from * http://www.euclideanspace.com/maths/geometry/rotations/conversions * /eulerToQuaternion/ * * @param orientation */ private void getRotationVectorFromAccelMag(float[] orientation) { // Assuming the angles are in radians. // getOrientation() values: // values[0]: azimuth, rotation around the Z axis. // values[1]: pitch, rotation around the X axis. // values[2]: roll, rotation around the Y axis. // Heading, Azimuth, Yaw double c1 = Math.cos(orientation[0] / 2); double s1 = Math.sin(orientation[0] / 2); // Pitch, Attitude // The equation assumes the pitch is pointed in the opposite direction // of the orientation vector provided by Android, so we invert it. double c2 = Math.cos(-orientation[1] / 2); double s2 = Math.sin(-orientation[1] / 2); // Roll, Bank double c3 = Math.cos(orientation[2] / 2); double s3 = Math.sin(orientation[2] / 2); double c1c2 = c1 * c2; double s1s2 = s1 * s2; double w = c1c2 * c3 - s1s2 * s3; double x = c1c2 * s3 + s1s2 * c3; double y = s1 * c2 * c3 + c1 * s2 * s3; double z = c1 * s2 * c3 - s1 * c2 * s3; // The quaternion in the equation does not share the same coordinate // system as the Android gyroscope quaternion we are using. We reorder // it here. // Android X (pitch) = Equation Z (pitch) // Android Y (roll) = Equation X (roll) // Android Z (azimuth) = Equation Y (azimuth) quatAccelMag = new Quaternion(w, z, x, y); }
From source file:MyJava3D.java
public void setViewAngle(Vector3d angle) { this.viewAngle = angle; // System.out.println( "ViewAngle: " + viewAngle ); CT = Math.cos(DEG_TO_RAD * viewAngle.x); ST = Math.sin(DEG_TO_RAD * viewAngle.x); CP = Math.cos(DEG_TO_RAD * viewAngle.y); SP = Math.sin(DEG_TO_RAD * viewAngle.y); view.x = (float) (-CP * ST); view.y = (float) (-CP * CT); view.z = (float) SP; if (lightRelativeToView != false) { lightAngle.x = viewAngle.x + lightAngleOffset.x; lightAngle.y = viewAngle.y + lightAngleOffset.y; lightAngle.z = viewAngle.z + lightAngleOffset.z; setLightAngle(lightAngle);/*from w w w . j ava2s .co m*/ } }