List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:Main.java
public static double GetDistance(double lat1, double lng1, double lat2, double lng2) { double radLat1 = rad(lat1); double radLat2 = rad(lat2); double a = radLat1 - radLat2; double b = rad(lng1) - rad(lng2); 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.jav a 2 s .c om*/ s = Math.round(s * 10000) / 10000; return s; }
From source file:Main.java
private static double[] bdToGaoDe(double bd_lat, double bd_lon) { double[] gd_lat_lon = new double[2]; double PI = 3.1415926535897932384626 * 3000.0 / 180.0; double x = bd_lon - 0.0065, y = bd_lat - 0.006; double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * PI); double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * PI); gd_lat_lon[0] = z * Math.cos(theta); gd_lat_lon[1] = z * Math.sin(theta); return gd_lat_lon; }
From source file:Main.java
public static double DistanceOfTwoPoints(double lat1, double lng1, double lat2, double lng2) { double radLat1 = rad(lat1); double radLat2 = rad(lat2); double a = radLat1 - radLat2; double b = rad(lng1) - rad(lng2); 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;// w w w . j a v a 2s . co m s = Math.round(s * 10000) / 10000; return s; }
From source file:Main.java
/** * Returns bounding box centered on location * //from w ww . jav a2 s. co m * @param loc * @param radius, in meters * @return long lat long lat */ public static double[] getBoundingBoxCoords(Location loc, Double radius) { double dY = 360 * radius / EARTH_RADIUS; double dX = dY * Math.cos(Math.toRadians(loc.getLatitude())); return new double[] { loc.getLongitude() - dX, loc.getLatitude() - dY, loc.getLongitude() + dX, loc.getLatitude() + dY }; }
From source file:Main.java
public static double getDistance(double lat1, double lng1, double lat2, double lng2) { double radLat1 = rad(lat1); double radLat2 = rad(lat2); double a = radLat1 - radLat2; double b = rad(lng1) - rad(lng2); double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin((double) a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2))); s = s * EARTH_RADIUS;//w w w .j a va2 s .c om return s; }
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 w w w.j a va2 s.co m dist = (((int) (dist * 100)) / 100.0); } return dist; }
From source file:Main.java
public static double haversine(double lat1, double lon1, double lat2, double lon2) { final double R = 6372.8; // In kilometers double dLat = Math.toRadians(lat2 - lat1); double dLon = Math.toRadians(lon2 - lon1); lat1 = Math.toRadians(lat1);//w w w . j av a2s . c om lat2 = Math.toRadians(lat2); double a = Math.pow(Math.sin(dLat / 2), 2) + Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.asin(Math.sqrt(a)); return R * c; }
From source file:Main.java
public static double distance(double lat1, double lon1, double lat2, double lon2) { if (lat1 == lat2 && lon1 == lon2) { return 0; }/* w ww . ja v a 2s .c om*/ // haversine great circle distance approximation, returns meters double theta = lon1 - lon2; double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta)); if (dist > 1) { return 0; } dist = Math.acos(dist); dist = rad2deg(dist); dist = dist * 60; // 60 nautical miles per degree of separation dist = dist * 1852; // 1852 meters per nautical mile return dist / 1000; }
From source file:Main.java
public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) { double Lat1 = rad(latitude1); double Lat2 = rad(latitude2); double a = Lat1 - Lat2; double b = rad(longitude1) - rad(longitude2); double s = 2 * Math.asin(Math.sqrt( Math.pow(Math.sin(a / 2), 2) + Math.cos(Lat1) * Math.cos(Lat2) * Math.pow(Math.sin(b / 2), 2))); s = s * EARTH_RADIUS;/*from w w w .j a va2s . c om*/ s = Math.round(s * 10000) / 10000; return s; }
From source file:Main.java
public static void setRotateM(float[] rm, float a, float x, float y, float z) { rm[3] = 0;/*from w ww . java2 s.c o m*/ rm[7] = 0; rm[11] = 0; rm[12] = 0; rm[13] = 0; rm[14] = 0; rm[15] = 1; a *= (float) (Math.PI / 180.0f); float s = (float) Math.sin(a); float c = (float) Math.cos(a); if (1.0f == x && 0.0f == y && 0.0f == z) { rm[5] = c; rm[10] = c; rm[6] = s; rm[9] = -s; rm[1] = 0; rm[2] = 0; rm[4] = 0; rm[8] = 0; rm[0] = 1; } else if (0.0f == x && 1.0f == y && 0.0f == z) { rm[0] = c; rm[10] = c; rm[8] = s; rm[2] = -s; rm[1] = 0; rm[4] = 0; rm[6] = 0; rm[9] = 0; rm[5] = 1; } else if (0.0f == x && 0.0f == y && 1.0f == z) { rm[0] = c; rm[5] = c; rm[1] = s; rm[4] = -s; rm[2] = 0; rm[6] = 0; rm[8] = 0; rm[9] = 0; rm[10] = 1; } else { float len = length(x, y, z); if (1.0f != len) { float recipLen = 1.0f / len; x *= recipLen; y *= recipLen; z *= recipLen; } float nc = 1.0f - c; float xy = x * y; float yz = y * z; float zx = z * x; float xs = x * s; float ys = y * s; float zs = z * s; rm[0] = x * x * nc + c; rm[4] = xy * nc - zs; rm[8] = zx * nc + ys; rm[1] = xy * nc + zs; rm[5] = y * y * nc + c; rm[9] = yz * nc - xs; rm[2] = zx * nc - ys; rm[6] = yz * nc + xs; rm[10] = z * z * nc + c; } }