@Test public void testDistance() { double distance = Contour.distance(1, 1, 1, 2); assertEquals(111177.99068882648, distance, 1e-10); double distance2 = Contour.distance(1, 1, 0.5, -0.5); assertEquals(111177.99068882648, distance2, 1e-10); }
public static double distance(double lat1, double lat2, double lon1, double lon2) { final int R = 6371; 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 * 1000; distance = Math.pow(distance, 2); return Math.sqrt(distance); }
Contour { public static double distance(double lat1, double lat2, double lon1, double lon2) { final int R = 6371; 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 * 1000; distance = Math.pow(distance, 2); return Math.sqrt(distance); } }
Contour { public static double distance(double lat1, double lat2, double lon1, double lon2) { final int R = 6371; 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 * 1000; distance = Math.pow(distance, 2); return Math.sqrt(distance); } Contour(GraphHopperStorage ghStorage, NodeAccess nodeAccess, IsochroneNodeStorage isochroneNodeStorage, CellStorage cellStorage); }
Contour { public static double distance(double lat1, double lat2, double lon1, double lon2) { final int R = 6371; 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 * 1000; distance = Math.pow(distance, 2); return Math.sqrt(distance); } Contour(GraphHopperStorage ghStorage, NodeAccess nodeAccess, IsochroneNodeStorage isochroneNodeStorage, CellStorage cellStorage); static double distance(double lat1, double lat2, double lon1,
                                  double lon2); void calculateContour(); Contour setGhStorage(GraphHopperStorage ghStorage); }
Contour { public static double distance(double lat1, double lat2, double lon1, double lon2) { final int R = 6371; 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 * 1000; distance = Math.pow(distance, 2); return Math.sqrt(distance); } Contour(GraphHopperStorage ghStorage, NodeAccess nodeAccess, IsochroneNodeStorage isochroneNodeStorage, CellStorage cellStorage); static double distance(double lat1, double lat2, double lon1,
                                  double lon2); void calculateContour(); Contour setGhStorage(GraphHopperStorage ghStorage);  }