List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:Main.java
/************************************************************************************************************************************ This routine calculates the distance between two points (given the latitude/longitude of those points). It is being used to calculate the distance between two locations/*www.j a v a2 s . c o m*/ Definitions: South latitudes are negative, east longitudes are positive Passed to function: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) unit = the unit you desire for results where: 'M' is statute miles 'K' is kilometers (default) 'N' is nautical miles *************************************************************************************************************************************/ public static double Distance(double lat1, double lon1, double lat2, double lon2, String unit) { double radius = 6371.0090667; lat1 = lat1 * Math.PI / 180.0; lon1 = lon1 * Math.PI / 180.0; lat2 = lat2 * Math.PI / 180.0; lon2 = lon2 * Math.PI / 180.0; double dlon = lon1 - lon2; double distance = Math .acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(dlon)) * radius; if (unit == "K") { return distance; } else if (unit == "M") { return (distance * 0.621371192); } else if (unit == "F") { //FEET return ((distance * 0.621371192) * 5280); } else if (unit == "N") { return (distance * 0.539956803); } else { return 0; } }
From source file:org.apache.usergrid.client.QueryTestCase.java
public static float distFrom(float lat1, float lng1, float lat2, float lng2) { double earthRadius = 6371000; //meters double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return (float) (earthRadius * c); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle(""); Group root = new Group(); Scene scene = new Scene(root, 300, 250, Color.WHITE); int w = 220;/*www . j av a2 s . c o m*/ int h = 100; FloatMap map = new FloatMap(); map.setWidth(w); map.setHeight(h); for (int i = 0; i < w; i++) { double v = (Math.sin(i / 20.0 * Math.PI) - 0.5) / 40.0; for (int j = 0; j < h; j++) { map.setSamples(i, j, 0.0f, (float) v); } } Group g = new Group(); DisplacementMap dm = new DisplacementMap(); dm.setMapData(map); g.setEffect(dm); g.setCache(true); Rectangle r = new Rectangle(); r.setX(20.0); r.setY(20.0); r.setWidth(w); r.setHeight(h); r.setFill(Color.BLUE); g.getChildren().add(r); Text t = new Text(); t.setX(40.0); t.setY(80.0); t.setText("Wavy Text"); t.setFill(Color.YELLOW); t.setFont(Font.font(null, FontWeight.BOLD, 36)); g.getChildren().add(t); root.getChildren().add(g); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
static double distanceFromArc(double dA, double dB, double dAB) { // In spherical trinagle ABC // a is length of arc BC, that is dB // b is length of arc AC, that is dA // c is length of arc AB, that is dAB // We rename parameters so following formulas are more clear: double a = dB; double b = dA; double c = dAB; // First, we calculate angles alpha and beta in spherical triangle ABC // and based on them we decide how to calculate the distance: if (Math.sin(b) * Math.sin(c) == 0.0 || Math.sin(c) * Math.sin(a) == 0.0) { // It probably means that one of distance is n*pi, which gives around 20000km for n = 1, // unlikely for Denmark, so we should be fine. return -1.0; }//from w w w . j a v a 2 s .c o m double alpha = Math.acos((Math.cos(a) - Math.cos(b) * Math.cos(c)) / (Math.sin(b) * Math.sin(c))); double beta = Math.acos((Math.cos(b) - Math.cos(c) * Math.cos(a)) / (Math.sin(c) * Math.sin(a))); // It is possible that both sinuses are too small so we can get nan when dividing with them if (Double.isNaN(alpha) || Double.isNaN(beta)) { // double cosa = cos(a); // double cosbc = cos(b) * cos(c); // double minus1 = cosa - cosbc; // double sinbc = sin(b) * sin(c); // double div1 = minus1 / sinbc; // // double cosb = cos(b); // double cosca = cos(a) * cos(c); // double minus2 = cosb - cosca; // double sinca = sin(a) * sin(c); // double div2 = minus2 / sinca; return -1.0; } // If alpha or beta are zero or pi, it means that C is on the same circle as arc AB, // we just need to figure out if it is between AB: if (alpha == 0.0 || beta == 0.0) { return (dA + dB > dAB) ? Math.min(dA, dB) : 0.0; } // If alpha is obtuse and beta is acute angle, then // distance is equal to dA: if (alpha > Math.PI / 2 && beta < Math.PI / 2) return dA; // Analogously, if beta is obtuse and alpha is acute angle, then // distance is equal to dB: if (beta > Math.PI / 2 && alpha < Math.PI / 2) return dB; // If both alpha and beta are acute or both obtuse or one of them (or both) are right, // distance is the height of the spherical triangle ABC: // Again, unlikely, since it would render at least pi/2*EARTH_RADIUS_IN_METERS, which is too much. if (Math.cos(a) == 0.0) return -1; double x = Math.atan(-1.0 / Math.tan(c) + (Math.cos(b) / (Math.cos(a) * Math.sin(c)))); // Similar to previous edge cases... if (Math.cos(x) == 0.0) return -1.0; return Math.acos(Math.cos(a) / Math.cos(x)); }
From source file:Main.java
private static double transformLon(double x, double y) { double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x)); ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0; ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0; ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0; return ret;/*from w w w .j av a 2 s. c o m*/ }
From source file:com.opengamma.analytics.math.function.special.GammaFunction.java
@Override public Double evaluate(final Double x) { if (x > 0.0) { return Math.exp(Gamma.logGamma(x)); }/* w ww . j av a 2 s. com*/ return Math.PI / Math.sin(Math.PI * x) / evaluate(1 - x); }
From source file:com.opengamma.strata.math.impl.function.special.GammaFunction.java
@Override public double applyAsDouble(double x) { if (x > 0.0) { return Math.exp(Gamma.logGamma(x)); }// w ww . j ava2s .c o m return Math.PI / Math.sin(Math.PI * x) / applyAsDouble(1 - x); }
From source file:fungus.VisualizerTransformers.java
public static Shape createRegularPolygon(int sides, int radius) { Polygon p = new Polygon(); double a = 2 * Math.PI / sides; for (int i = 0; i < sides; i++) p.addPoint((int) (radius * Math.sin(a * i)), (int) (radius * -Math.cos(a * i))); return p;/* w ww . j a va2 s . com*/ }
From source file:org.jfree.chart.demo.VectorPlotDemo1.java
private static VectorXYDataset createDataset() { VectorSeries vectorseries = new VectorSeries("Series 1"); for (double d = 0.0D; d < 20D; d++) { for (double d1 = 0.0D; d1 < 20D; d1++) vectorseries.add(d + 10D, d1 + 10D, Math.sin(d / 5D) / 2D, Math.cos(d1 / 5D) / 2D); }/*from w ww. ja va2s . c om*/ VectorSeriesCollection dataset = new VectorSeriesCollection(); dataset.addSeries(vectorseries); return dataset; }
From source file:de.termininistic.serein.examples.benchmarks.functions.multimodal.LevyFunction.java
@Override public double map(RealVector v) { double[] x = v.toArray(); double sum = Math.pow(Math.sin(Math.PI * w(x[0])), 2); for (int i = 0; i < x.length - 1; i++) { sum += Math.pow((w(x[i]) - 1), 2) * (1 + 10 * Math.pow(Math.sin(2 * Math.PI * w(x[0]) + 1), 2) + Math.pow(w(x[x.length - 1]) - 1, 2) * (1 + Math.pow(Math.sin(2 * Math.PI * w(x[x.length - 1]) + 1), 2))); }//from w w w. j av a 2s .c o m return sum; }