@Test public void testDistanceComputation() { double d1 = Buses.computeLatLonDistance(new PointImpl(38.898, -77.037), new PointImpl(38.897, -77.043)); assertEquals(0.330, d1, 0.001); double d2 = Buses.computeLatLonDistance(new PointImpl(38.898, -97.030), new PointImpl(38.890, -97.044)); assertEquals(0.935, d2, 0.001); double d3 = Buses.computeLatLonDistance(new PointImpl(38.958, -97.038), new PointImpl(38.890, -97.044)); assertEquals(4.712, d3, 0.001); }
public static double computeLatLonDistance(Point p1, Point p2) { double lat1 = Math.toRadians(p1.getLat()); double lon1 = Math.toRadians(p1.getLon()); double lat2 = Math.toRadians(p2.getLat()); double lon2 = Math.toRadians(p2.getLon()); double dlon = lon2 - lon1; double dlat = lat2 - lat1; double a = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dlon / 2) * Math.sin(dlon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); int earthRadius = 3961; return earthRadius * c; }
Buses { public static double computeLatLonDistance(Point p1, Point p2) { double lat1 = Math.toRadians(p1.getLat()); double lon1 = Math.toRadians(p1.getLon()); double lat2 = Math.toRadians(p2.getLat()); double lon2 = Math.toRadians(p2.getLon()); double dlon = lon2 - lon1; double dlat = lat2 - lat1; double a = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dlon / 2) * Math.sin(dlon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); int earthRadius = 3961; return earthRadius * c; } }
Buses { public static double computeLatLonDistance(Point p1, Point p2) { double lat1 = Math.toRadians(p1.getLat()); double lon1 = Math.toRadians(p1.getLon()); double lat2 = Math.toRadians(p2.getLat()); double lon2 = Math.toRadians(p2.getLon()); double dlon = lon2 - lon1; double dlat = lat2 - lat1; double a = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dlon / 2) * Math.sin(dlon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); int earthRadius = 3961; return earthRadius * c; }  }
Buses { public static double computeLatLonDistance(Point p1, Point p2) { double lat1 = Math.toRadians(p1.getLat()); double lon1 = Math.toRadians(p1.getLon()); double lat2 = Math.toRadians(p2.getLat()); double lon2 = Math.toRadians(p2.getLon()); double dlon = lon2 - lon1; double dlat = lat2 - lat1; double a = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dlon / 2) * Math.sin(dlon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); int earthRadius = 3961; return earthRadius * c; }  static void main(String... args); static List<Bus> getClosestBuses(); static Stop selectStopInteractive(List<Stop> stops); static String readConsole(String prompt); static InputStream getNextBusRequest(String... requestArgs); static double computeLatLonDistance(Point p1, Point p2); }
Buses { public static double computeLatLonDistance(Point p1, Point p2) { double lat1 = Math.toRadians(p1.getLat()); double lon1 = Math.toRadians(p1.getLon()); double lat2 = Math.toRadians(p2.getLat()); double lon2 = Math.toRadians(p2.getLon()); double dlon = lon2 - lon1; double dlat = lat2 - lat1; double a = Math.sin(dlat / 2) * Math.sin(dlat / 2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(dlon / 2) * Math.sin(dlon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); int earthRadius = 3961; return earthRadius * c; }  static void main(String... args); static List<Bus> getClosestBuses(); static Stop selectStopInteractive(List<Stop> stops); static String readConsole(String prompt); static InputStream getNextBusRequest(String... requestArgs); static double computeLatLonDistance(Point p1, Point p2);  }