List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:Main.java
/** * Calculate the corrected obliquity of the ecliptic. * * @param t number of Julian centuries since J2000. * @return Corrected obliquity in degrees. */// ww w .jav a 2 s. c o m private static double obliquityCorrected(final double t) { final double e0 = meanObliquityOfEcliptic(t); final double omega = Math.toRadians(125.04 - 1934.136 * t); return e0 + 0.00256 * Math.cos(omega); }
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:com.opengamma.analytics.financial.model.finitedifference.ChebyshevMeshing.java
@Override public Double evaluate(final Integer i) { Validate.isTrue(i >= 0 && i < getNumberOfPoints(), "i out of range"); return _a + _r * (1 - Math.cos(i * Math.PI / _n)); }
From source file:Main.java
private static double getCosY(long diffTime) { return 0.5f * Math.cos(3 * diffTime / 1000.0f) + 0.5; }
From source file:com.atomiton.watermanagement.ngo.util.WaterMgmtNGOUtility.java
public static double getDistance(double lat1, double lon1, double lat2, double lon2) { int R = 6371; double phi1 = deg2rad(lat1); double phi2 = deg2rad(lat2); double lambda1 = deg2rad(lon1); double lambda2 = deg2rad(lon2); double x = (lambda2 - lambda1) * Math.cos((phi1 + phi2) / 2.0); double y = phi2 - phi1; double distKm = Math.sqrt(x * x + y * y) * R; //return distKm / 1.60934; // in miles return distKm; }
From source file:Main.java
public static double[] gcj02towgs84(double lng, double lat) { if (out_of_china(lng, lat)) { return new double[] { lng, lat }; }//w ww.j a v a 2 s. com double dlat = transformlat(lng - 105.0, lat - 35.0); double dlng = transformlng(lng - 105.0, lat - 35.0); double radlat = lat / 180.0 * pi; double magic = Math.sin(radlat); magic = 1 - ee * magic * magic; double sqrtmagic = Math.sqrt(magic); dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi); dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * pi); double mglat = lat + dlat; double mglng = lng + dlng; return new double[] { lng * 2 - mglng, lat * 2 - mglat }; }
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;//from w w w . j av a 2s . co m }
From source file:edu.columbia.sel.grout.util.TileUtils.java
/** * For a description see://from w w w . j a va2 s. c o m * * @see http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames For a * code-description see: * @see http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames# * compute_bounding_box_for_tile_number * @param aLat * latitude to get the {@link OSMTileInfo} for. * @param aLon * longitude to get the {@link OSMTileInfo} for. * @return The {@link OSMTileInfo} providing 'x' 'y' and 'z'(oom) for the * coordinates passed. */ public static OSMTileInfo getMapTileFromCoordinates(final double aLat, final double aLon, final int zoom) { final int y = (int) Math .floor((1 - Math.log(Math.tan(aLat * Math.PI / 180) + 1 / Math.cos(aLat * Math.PI / 180)) / Math.PI) / 2 * (1 << zoom)); final int x = (int) Math.floor((aLon + 180) / 360 * (1 << zoom)); return new OSMTileInfo(x, y, zoom); }
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 . java 2 s .c om*/ 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: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 www.ja va 2 s . c o m*/ VectorSeriesCollection dataset = new VectorSeriesCollection(); dataset.addSeries(vectorseries); return dataset; }