List of usage examples for java.lang Math atan2
@HotSpotIntrinsicCandidate public static double atan2(double y, double x)
From source file:Main.java
/** * Rotate a set of coordinates by a given angle * @param c_x//from w w w . j a va 2s . c o m * @param c_y * @param thetab * @param x * @param y * @return */ public static double[] rotateCoord(double c_x, double c_y, double thetab, double x, double y) { double prc_x = x - c_x; double prc_y = y - c_y; double r = Math.sqrt(prc_x * prc_x + prc_y * prc_y); double theta = Math.atan2(prc_y, prc_x); theta = theta + thetab * Math.PI / 180.0; double pc_x = r * Math.cos(theta); double pc_y = r * Math.sin(theta); double p[] = new double[2]; p[0] = pc_x + c_x; p[1] = pc_y + c_y; return p; }
From source file:Main.java
public static double distFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 3958.75; 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 = earthRadius * c; int meterConversion = 1609; return dist * meterConversion; }
From source file:Main.java
public static double distance(double lat1, double lng1, double lat2, double 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)); double distance = (double) (earthRadius * c); return distance; }
From source file:Main.java
public static double distFrom(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 3958.75; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double sindLat = Math.sin(dLat / 2); double sindLng = Math.sin(dLng / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c; if (dist >= 1000) { int distInInt = (int) dist; dist = (int) distInInt; } else if (dist >= 100) { dist = (((int) (dist * 10)) / 10.0); } else {/*from ww w . j ava 2s . com*/ dist = (((int) (dist * 100)) / 100.0); } return dist; }
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
public static Double getDistance(double lat1, double lat2, double lon1, double lon2, double el1, double el2) { final int R = 6371; // Radius of the earth Double latDistance = Math.toRadians(lat2 - lat1); Double lonDistance = Math.toRadians(lon2 - lon1); Double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2); Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = R * c; // convert to meters double height = el1 - el2; distance = Math.pow(distance, 2) + Math.pow(height, 2); return Math.sqrt(distance); }
From source file:Main.java
public static double getBearing(double lat1, double lng1, double lat2, double lng2) { double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); lat1 = Math.toRadians(lat1);//from w ww .ja v a2s. c o m lat2 = Math.toRadians(lat2); lng1 = Math.toRadians(lng1); lng2 = Math.toRadians(lng2); double y = Math.sin(dLng) * Math.cos(lat2); double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLng); double brng = Math.toDegrees(Math.atan2(y, x)); return brng; }
From source file:Main.java
public static void transformBaidu(double wgLat, double wgLon, double[] latlng) { double d[] = new double[2]; transform(wgLat, wgLon, d);//from ww w. j a v a2 s . c o m double x = d[1], y = d[0]; 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); latlng[1] = z * Math.cos(theta) + 0.0065; latlng[0] = z * Math.sin(theta) + 0.006; }
From source file:Main.java
/** * Calculates the distance between two locations in KM *///from w w w . ja va 2 s .c om public static double checkDistance(double lat1, double lng1, double lat2, double lng2) { double earthRadius = 6371; double dLat = Math.toRadians(lat2 - lat1); double dLng = Math.toRadians(lng2 - lng1); double sindLat = Math.sin(dLat / 2); double sindLng = Math.sin(dLng / 2); double a = Math.pow(sindLat, 2) + Math.pow(sindLng, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double dist = earthRadius * c * 1000; return dist; // in meter }
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);// w w w. ja v a 2 s . 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 }