List of usage examples for java.lang Math asin
public static double asin(double a)
From source file:org.moeaframework.util.tree.NodeTest.java
@Test public void testAsin() { Node node = new Asin().setArgument(0, new Constant(Math.PI / 4.0)); Assert.assertTrue(// w w w. j a va 2 s. c o m NumberArithmetic.equals(Math.asin(Math.PI / 4.0), (Number) node.evaluate(new UnusedEnvironment()))); }
From source file:org.renjin.primitives.MathGroup.java
@Deferrable @Builtin//from w w w.j a va 2s. co m @DataParallel(value = PreserveAttributeStyle.ALL, passNA = true) public static double asin(double val) { return Math.asin(val); }
From source file:com.ccxt.whl.utils.CommonUtils.java
/** * ??(?)?//from w ww . j av a 2 s . c o m * * @param long1 * ? * @param lat1 * * @param long2 * ? * @param lat2 * * @return ? ?? */ public static double Distance(double long1, double lat1, double long2, double lat2) { double a, b, R; R = 6378137; // ?? lat1 = lat1 * Math.PI / 180.0; lat2 = lat2 * Math.PI / 180.0; a = lat1 - lat2; b = (long1 - long2) * Math.PI / 180.0; double d; double sa2, sb2; sa2 = Math.sin(a / 2.0); sb2 = Math.sin(b / 2.0); d = 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2 * sb2)); return d; }
From source file:org.opensextant.util.GeodeticUtility.java
/** Haversine distance using LL1 to LL2; * * @param p1 geodesy API LatLon/*from w w w . j av a 2 s .co m*/ * @param p2 geodesy API LatLon * @return distance in meters. */ public final static long distanceMeters(LatLon p1, LatLon p2) { double lat1 = p1.getLatitude(); double lon1 = p1.getLongitude(); double lat2 = p2.getLatitude(); double lon2 = p2.getLongitude(); /* Courtesy of http://rosettacode.org/wiki/Haversine_formula#Java */ double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); lat1 = Math.toRadians(lat1); lat2 = Math.toRadians(lat2); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.asin(Math.sqrt(a)); return (long) (EARTH_RADIUS * c); }
From source file:dnimp.Statistics.java
/** *Returns the linear distance between 2 geographical coordinates; for sQTBA *@param x Latitude/*w w w . java 2s . c o m*/ *@param y Longitude *@param xR receptor site latitude *@param yR receptor site longitude */ public double haversineV(double x, double y, double xR, double yR) { double re = 6378.1369; //equatorial earth's radius double pi360 = Math.PI / 360.0; double pi180 = Math.PI / 180.0; double term1 = Math.sin(pi360 * (x - xR)); double term2 = Math.cos(pi180 * xR); double term3 = Math.cos(pi180 * x); double term4 = Math.sin(pi360 * (y - yR)); double sqrtauxV = 2 * re * Math.asin(Math.sqrt(Math.pow(term1, 2.0) + (term2 * term3 * Math.pow(term4, 2.0)))); return sqrtauxV; }
From source file:org.apache.drill.exec.fn.impl.TestNewMathFunctions.java
@Test public void testTrigoMathFunc() throws Throwable { final Object[] expected = new Object[] { Math.sin(45), Math.cos(45), Math.tan(45), Math.asin(45), Math.acos(45), Math.atan(45), Math.sinh(45), Math.cosh(45), Math.tanh(45) }; runTest(expected, "functions/testTrigoMathFunctions.json"); }
From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java
/** * data provider generator for single-value tests * @return data/*from w w w. ja v a 2 s . c o m*/ */ @DataProvider public static Object[] singlevaluegenerate() { return Stream.concat( singlevaluetestcase( Stream.of(2.5, 9.1, 111.7, 889.9), Stream.of(CNextPrime.class), (i) -> (double) Primes.nextPrime(i.intValue())), singlevaluetestcase( Stream.of(-2, -6, 4, -1, -5, 3, 49, 30, 6, 5, 1.3, 2.8, 9.7, 1, 8, 180, Math.PI), Stream.of(CAbs.class, CACos.class, CASin.class, CATan.class, CCeil.class, CCos.class, CCosh.class, CDegrees.class, CExp.class, CIsPrime.class, CLog.class, CLog10.class, CFloor.class, CRadians.class, CRound.class, CSignum.class, CSin.class, CSinh.class, CSqrt.class, CTan.class, CTanh.class), (i) -> Math.abs(i.doubleValue()), (i) -> Math.acos(i.doubleValue()), (i) -> Math.asin(i.doubleValue()), (i) -> Math.atan(i.doubleValue()), (i) -> Math.ceil(i.doubleValue()), (i) -> Math.cos(i.doubleValue()), (i) -> Math.cosh(i.doubleValue()), (i) -> Math.toDegrees(i.doubleValue()), (i) -> Math.exp(i.doubleValue()), (i) -> Primes.isPrime(i.intValue()), (i) -> Math.log(i.doubleValue()), (i) -> Math.log10(i.doubleValue()), (i) -> Math.floor(i.doubleValue()), (i) -> Math.toRadians(i.doubleValue()), (i) -> Math.round(i.doubleValue()), (i) -> Math.signum(i.doubleValue()), (i) -> Math.sin(i.doubleValue()), (i) -> Math.sinh(i.doubleValue()), (i) -> Math.sqrt(i.doubleValue()), (i) -> Math.tan(i.doubleValue()), (i) -> Math.tanh(i.doubleValue())) ).toArray(); }
From source file:ActualizadorLocal.Clientes.ClienteNodos.java
public void procesarDatos(String datos) throws SQLException { //Preprocesamos los datos, para darle un nombre al array: datos = "{\"nodos\":" + datos + "}"; JSONParser parser = new JSONParser(); try {// w w w .java 2 s . c om JSONObject obj = (JSONObject) parser.parse(datos); JSONArray lista = (JSONArray) obj.get("nodos"); for (int i = 0; i < lista.size(); i++) { long a0 = (long) ((JSONObject) lista.get(i)).get("idNodo"); String a1 = (String) ((JSONObject) lista.get(i)).get("nombre"); double a2 = (double) ((JSONObject) lista.get(i)).get("latitud"); double a3 = (double) ((JSONObject) lista.get(i)).get("longitud"); nodos.add(a0); //Tenemos que calcular el polgono para la visualizacin de los datos mediante GOOGLE FUSION TABLES: double lat = Math.toRadians(new Double(a2)); double lon = Math.toRadians(new Double(a3)); double radio = 50.0 / 6378137.0; String cadena_poligono = "<Polygon><outerBoundaryIs><LinearRing><coordinates>"; for (int j = 0; j <= 360; j = j + 15) { double r = Math.toRadians(j); double lat_rad = Math .asin(Math.sin(lat) * Math.cos(radio) + Math.cos(lat) * Math.sin(radio) * Math.cos(r)); double lon_rad = Math.atan2(Math.sin(r) * Math.sin(radio) * Math.cos(lat), Math.cos(radio) - Math.sin(lat) * Math.sin(lat_rad)); double lon_rad_f = ((lon + lon_rad + Math.PI) % (2 * Math.PI)) - Math.PI; cadena_poligono = cadena_poligono + Math.toDegrees(lon_rad_f) + "," + Math.toDegrees(lat_rad) + ",0.0 "; } cadena_poligono = cadena_poligono + "</coordinates></LinearRing></outerBoundaryIs></Polygon>"; this.InsertarDatos("\"" + (String) Long.toString(a0) + "\",\"" + a1 + "\",\"" + Double.toString(a2) + "\",\"" + Double.toString(a3) + "\",\"" + cadena_poligono + "\""); } } catch (Exception e) { System.err.println(e.getMessage()); } syncDB(); }
From source file:edu.ucsf.valelab.saim.calculations.SaimCalc.java
/** * Calculates the angle of incidence for light traveling through a medium * with known refractive index and angle of incidence into a medium with * another known refractive index using Snell's law: sin(1)/sin(2) = n2/n1 * See: https://en.wikipedia.org/wiki/Snell%27s_law * /*from www. j a va 2 s. c o m*/ * @param angle1 angle with respect to the normal in radiance in medium 1 * @param ri1 Refractive index of medium 1 * @param ri2 Refractive index of medium 2 * @return angle of incidence in medium 2 in radiance */ public static double snell2(double angle1, double ri1, double ri2) { double sinAngle2 = ri1 * Math.sin(angle1) / ri2; return Math.asin(sinAngle2); }
From source file:com.alvermont.terraj.planet.project.MollweideProjection.java
/** * Carry out the projection/*from ww w .j av a 2 s . c om*/ */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; depth = (3 * ((int) (log2(scale * height)))) + 6; log.debug("MollweideProjection starting with depth set to " + depth); progress.progressStart(height, "Generating Terrain"); double x; double y; double y1; double zz; double scale1; double cos2; double theta1; double theta2; int i; int j; int i1 = 1; int k; for (j = 0; j < height; ++j) { progress.progressStep(j); y1 = (2 * ((2.0 * j) - height)) / width / scale; if (Math.abs(y1) >= 1.0) { for (i = 0; i < width; ++i) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } } else { zz = Math.sqrt(1.0 - (y1 * y1)); y = 2.0 / Math.PI * ((y1 * zz) + Math.asin(y1)); cos2 = Math.sqrt(1.0 - (y * y)); if (cos2 > 0.0) { scale1 = (scale * width) / height / cos2 / Math.PI; depth = (3 * ((int) (log2(scale1 * height)))) + 3; for (i = 0; i < width; ++i) { theta1 = (Math.PI / zz * ((2.0 * i) - width)) / width / scale; if (Math.abs(theta1) > Math.PI) { colours[i][j] = backgroundColour; if (doShade) { shades[i][j] = 255; } } else { theta1 += (lon - (0.5 * Math.PI)); colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2); if (doShade) { shades[i][j] = shade; } } } } } } progress.progressComplete("Terrain Generated"); log.debug("MollweideProjection complete"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -ProjectionConstants.RIGHT_ANGLE_DEGREES; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < ProjectionConstants.RIGHT_ANGLE_DEGREES; theta1 += hgrid) { theta2 = Math.abs(theta1); x = Math.floor(theta2 / 5.0); y = (theta2 / 5.0) - x; y = ((1.0 - y) * mollTable[(int) x]) + (y * mollTable[(int) x + 1]); if (theta1 < 0.0) { y = -y; } j = (height / 2) + (int) (0.25 * y * width * scale); if ((j >= 0) && (j < height)) { for (i = Math.max(0, (width / 2) - (int) (0.5 * width * scale * Math.sqrt(1.0 - (y * y)))); i < Math.min( width, (width / 2) + (int) (0.5 * width * scale * Math.sqrt(1.0 - (y * y)))); ++i) colours[i][j] = BLACK; } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta1 = 0.0; theta1 > -ProjectionConstants.CIRCLE_DEGREES; theta1 -= vgrid) ; for (theta1 = theta1; theta1 < ProjectionConstants.CIRCLE_DEGREES; theta1 += vgrid) { if (((Math.toRadians(theta1) - lon + (0.5 * Math.PI)) > -Math.PI) && ((Math.toRadians(theta1) - lon + (0.5 * Math.PI)) <= Math.PI)) { x = (0.5 * (Math.toRadians(theta1) - lon + (0.5 * Math.PI)) * width * scale) / Math.PI; j = Math.max(0, (height / 2) - (int) (0.25 * width * scale)); y = (2 * ((2.0 * j) - height)) / width / scale; i = (int) ((width / 2) + (x * Math.sqrt(1.0 - (y * y)))); for (; j <= Math.min(height, (height / 2) + (int) (0.25 * width * scale)); ++j) { y1 = (2 * ((2.0 * j) - height)) / width / scale; if (Math.abs(y1) <= 1.0) { i1 = (int) ((width / 2) + (x * Math.sqrt(1.0 - (y1 * y1)))); if ((i1 >= 0) && (i1 < width)) { colours[i1][j] = BLACK; } } if (Math.abs(y) <= 1.0) { if (i < i1) { for (k = i + 1; k < i1; ++k) { if ((k > 00) && (k < width)) { colours[k][j] = BLACK; } } } else if (i > i1) { for (k = i - 1; k > i1; --k) { if ((k >= 0) && (k < width)) { colours[k][j] = BLACK; } } } } y = y1; i = i1; } } } } if (doShade) { smoothshades(); } doOutlining(); }