List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:Main.java
private static double getDistanceFromXtoY(double lat_a, double lng_a, double lat_b, double lng_b) { double pk = 180 / 3.14169; double a1 = lat_a / pk; double a2 = lng_a / pk; double b1 = lat_b / pk; double b2 = lng_b / pk; double t1 = Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2); double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2); double t3 = Math.sin(a1) * Math.sin(b1); double tt = Math.acos(t1 + t2 + t3); return 6366000 * tt; }
From source file:Main.java
/** * Calculate the azimuth to the target location from local. *///from ww w . java 2 s . c o m private static int getPosDirection(final double startlat, final double startlong, final double endlat, final double endlon) { double slat = Math.toRadians(startlat); double elat = Math.toRadians(endlat); double slng = Math.toRadians(startlong); double elng = Math.toRadians(endlon); double Y = Math.sin(elng - slng) * Math.cos(elat); double X = Math.cos(slat) * Math.sin(elat) - Math.sin(slat) * Math.cos(elat) * Math.cos(elng - slng); double deg = Math.toDegrees(Math.atan2(Y, X)); double angle = (deg + 360) % 360; return (int) (Math.abs(angle) + (1 / 7200)); }
From source file:Main.java
public static double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) { double radLat1 = (lat_a * Math.PI / 180.0); double radLat2 = (lat_b * Math.PI / 180.0); double a = radLat1 - radLat2; double b = (lng_a - lng_b) * Math.PI / 180.0; 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 w w w. ja va 2 s . co m s = Math.round(s * 10000) / 10000; return s; }
From source file:Main.java
public static int[] getMapTileFromCoordinates(final double aLat, final double aLon, final int zoom) { final int[] out = new int[2]; final double E2 = (double) aLat * Math.PI / 180; final long sradiusa = 6378137; final long sradiusb = 6356752; final double J2 = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa; final double M2 = (double) Math.log((1 + Math.sin(E2)) / (1 - Math.sin(E2))) / 2 - J2 * Math.log((1 + J2 * Math.sin(E2)) / (1 - J2 * Math.sin(E2))) / 2; final double B2 = (double) (1 << zoom); out[0] = (int) Math.floor(B2 / 2 - M2 * B2 / 2 / Math.PI); out[1] = (int) Math.floor((aLon + 180) / 360 * (1 << zoom)); return out;/*from w w w. j a v a 2 s. c o m*/ }
From source file:Main.java
public static double distanceFrom(double lat1, double lng1, double lat2, double lng2) { // Implementation of the Haversine distance formula lat1 = Math.toRadians(lat1);//from ww w . ja v a 2s.co m lng1 = Math.toRadians(lng1); lat2 = Math.toRadians(lat2); lng2 = Math.toRadians(lng2); double dlon = lng2 - lng1; double dlat = lat2 - lat1; double a = Math.pow((Math.sin(dlat / 2)), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(dlon / 2), 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return 3958.75 * c; // 3958: Earth radius in miles }
From source file:Main.java
public static double distanceTo(double fromLat, double fromLng, double toLat, double toLng) { double fromLatRad = calculateRadian(fromLat); double fromLngRad = calculateRadian(fromLng); double toLatRad = calculateRadian(toLat); double toLngRad = calculateRadian(toLng); return EARTH_RADIUS * (Math.PI / 2 - Math.asin(Math.sin(fromLatRad) * Math.sin(toLatRad) + Math.cos(fromLngRad - toLngRad) * Math.cos(toLatRad) * Math.cos(fromLatRad))); }
From source file:Main.java
/** * Calculate the equation of center for the sun. This value is a correction * to add to the geometric mean longitude in order to get the "true" longitude * of the sun.// ww w .j av a 2 s .com * * @param t number of Julian centuries since J2000. * @return Equation of center in degrees. */ private static double sunEquationOfCenter(final double t) { final double m = Math.toRadians(sunGeometricMeanAnomaly(t)); return Math.sin(1 * m) * (1.914602 - t * (0.004817 + 0.000014 * t)) + Math.sin(2 * m) * (0.019993 - t * (0.000101)) + Math.sin(3 * m) * (0.000289); }
From source file:Main.java
static Path getWavePath(float width, float height, float amplitude, float shift, float divide) { Path path = new Path(); float quadrant = height - amplitude; float x, y;//from www . j a v a2s . com path.moveTo(0, 0); path.lineTo(0, quadrant); for (int i = 0; i < width + 10; i = i + 10) { x = (float) i; y = quadrant + amplitude * (float) Math.sin(((i + 10) * Math.PI / 180) / divide + shift); path.lineTo(x, y); } path.lineTo(width, 0); path.close(); return path; }
From source file:Main.java
public static void untransformBaidu(double wgLat, double wgLon, double[] latlng) { double x = wgLon - 0.0065, y = wgLat - 0.006; double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi); double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi); double gg_lon = z * Math.cos(theta); double gg_lat = z * Math.sin(theta); untransform(gg_lat, gg_lon, latlng); }
From source file:Main.java
/** * From http://stackoverflow.com/a/19498994/423980 * @return distance between 2 points, stored as 2 pair location; *//*from www. j a va 2 s .c o m*/ public static double distanceFrom(double lat1, double lng1, double lat2, double lng2) { 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)); double dist = EARTH_RADIOUS * c; return Double.valueOf(dist * METER_CONVERSION).floatValue(); }