List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
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[] bd_encrypt(double gg_lat, double gg_lon) { double x = gg_lon, y = gg_lat; 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 bd_lon = z * Math.cos(theta) + 0.0065; double bd_lat = z * Math.sin(theta) + 0.006; return new double[] { bd_lon, bd_lat }; }
From source file:Main.java
public static double[] getGaoDePos(double[] baiDu) { double X_PI = 3.14159265358979324 * 3000.0 / 180.0; double x = baiDu[0] - 0.0065, y = baiDu[1] - 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[] gaode = new double[2]; gaode[0] = z * Math.cos(theta); gaode[1] = z * Math.sin(theta); return gaode; }
From source file:Main.java
public static double[] bd_decrypt(double bd_lat, double bd_lon) { double x = bd_lon - 0.0065, y = bd_lat - 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); return new double[] { gg_lon, gg_lat }; }
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
public static PointF rotatePoint(PointF point, PointF centerPoint, float rotate) { float x = point.x; float y = point.y; float sinA = (float) Math.sin(Math.toRadians(rotate)); float cosA = (float) Math.cos(Math.toRadians(rotate)); float newX = centerPoint.x + (x - centerPoint.x) * cosA - (y - centerPoint.y) * sinA; float newY = centerPoint.y + (y - centerPoint.y) * cosA + (x - centerPoint.x) * sinA; return new PointF(newX, newY); }
From source file:Main.java
/** * conmputes hann window for given size//from w w w . j av a 2 s. c om * * @param n the length of the window * @return a Hann window as double[] */ public static double[] getHannWindow(int n) { double[] hann = new double[n]; for (int i = 0; i < n; i++) { hann[i] = 0.5 * (1 - Math.cos((2.0 * Math.PI * i) / (n - 1))); } return hann; }
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);// w w w . j ava2s . co 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; }