@Test public void testGreatCircleDistance_AcrossDateline() throws Exception { Location west = new Location(0, -157.5); Location east = new Location(0, 157.5); double sideToSide = west.greatCircleDistance(east); assertEquals("157.5 east to 157.5 west", Math.toRadians(45), sideToSide, TOLERANCE); }
public double greatCircleDistance(Location location) { if (location == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Location", "greatCircleDistance", "missingLocation")); } double lat1Radians = Math.toRadians(this.latitude); double lon1Radians = Math.toRadians(this.longitude); double lat2Radians = Math.toRadians(location.latitude); double lon2Radians = Math.toRadians(location.longitude); if (lat1Radians == lat2Radians && lon1Radians == lon2Radians) { return 0; } double a = Math.sin((lat2Radians - lat1Radians) / 2.0); double b = Math.sin((lon2Radians - lon1Radians) / 2.0); double c = a * a + Math.cos(lat1Radians) * Math.cos(lat2Radians) * b * b; double distanceRadians = 2.0 * Math.asin(Math.sqrt(c)); return Double.isNaN(distanceRadians) ? 0 : distanceRadians; }
Location { public double greatCircleDistance(Location location) { if (location == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Location", "greatCircleDistance", "missingLocation")); } double lat1Radians = Math.toRadians(this.latitude); double lon1Radians = Math.toRadians(this.longitude); double lat2Radians = Math.toRadians(location.latitude); double lon2Radians = Math.toRadians(location.longitude); if (lat1Radians == lat2Radians && lon1Radians == lon2Radians) { return 0; } double a = Math.sin((lat2Radians - lat1Radians) / 2.0); double b = Math.sin((lon2Radians - lon1Radians) / 2.0); double c = a * a + Math.cos(lat1Radians) * Math.cos(lat2Radians) * b * b; double distanceRadians = 2.0 * Math.asin(Math.sqrt(c)); return Double.isNaN(distanceRadians) ? 0 : distanceRadians; } }
Location { public double greatCircleDistance(Location location) { if (location == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Location", "greatCircleDistance", "missingLocation")); } double lat1Radians = Math.toRadians(this.latitude); double lon1Radians = Math.toRadians(this.longitude); double lat2Radians = Math.toRadians(location.latitude); double lon2Radians = Math.toRadians(location.longitude); if (lat1Radians == lat2Radians && lon1Radians == lon2Radians) { return 0; } double a = Math.sin((lat2Radians - lat1Radians) / 2.0); double b = Math.sin((lon2Radians - lon1Radians) / 2.0); double c = a * a + Math.cos(lat1Radians) * Math.cos(lat2Radians) * b * b; double distanceRadians = 2.0 * Math.asin(Math.sqrt(c)); return Double.isNaN(distanceRadians) ? 0 : distanceRadians; } Location();  Location(double latitude, double longitude);  Location(Location location); }
Location { public double greatCircleDistance(Location location) { if (location == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Location", "greatCircleDistance", "missingLocation")); } double lat1Radians = Math.toRadians(this.latitude); double lon1Radians = Math.toRadians(this.longitude); double lat2Radians = Math.toRadians(location.latitude); double lon2Radians = Math.toRadians(location.longitude); if (lat1Radians == lat2Radians && lon1Radians == lon2Radians) { return 0; } double a = Math.sin((lat2Radians - lat1Radians) / 2.0); double b = Math.sin((lon2Radians - lon1Radians) / 2.0); double c = a * a + Math.cos(lat1Radians) * Math.cos(lat2Radians) * b * b; double distanceRadians = 2.0 * Math.asin(Math.sqrt(c)); return Double.isNaN(distanceRadians) ? 0 : distanceRadians; } Location();  Location(double latitude, double longitude);  Location(Location location); static Location fromDegrees(double latitudeDegrees, double longitudeDegrees); static Location fromRadians(double latitudeRadians, double longitudeRadians); static Location fromTimeZone(TimeZone timeZone); static double normalizeLatitude(double degrees); static double normalizeLongitude(double degrees); static double clampLatitude(double degrees); static double clampLongitude(double degrees); static boolean locationsCrossAntimeridian(List<? extends Location> locations); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Location set(double latitude, double longitude); Location set(Location location); Location interpolateAlongPath(Location endLocation, @WorldWind.PathType int pathType, double amount,
                                         Location result); double greatCircleAzimuth(Location location); double greatCircleDistance(Location location); Location greatCircleLocation(double azimuthDegrees, double distanceRadians, Location result); double rhumbAzimuth(Location location); double rhumbDistance(Location location); Location rhumbLocation(double azimuthDegrees, double distanceRadians, Location result); double linearAzimuth(Location location); double linearDistance(Location location); Location linearLocation(double azimuthDegrees, double distanceRadians, Location result); }
Location { public double greatCircleDistance(Location location) { if (location == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Location", "greatCircleDistance", "missingLocation")); } double lat1Radians = Math.toRadians(this.latitude); double lon1Radians = Math.toRadians(this.longitude); double lat2Radians = Math.toRadians(location.latitude); double lon2Radians = Math.toRadians(location.longitude); if (lat1Radians == lat2Radians && lon1Radians == lon2Radians) { return 0; } double a = Math.sin((lat2Radians - lat1Radians) / 2.0); double b = Math.sin((lon2Radians - lon1Radians) / 2.0); double c = a * a + Math.cos(lat1Radians) * Math.cos(lat2Radians) * b * b; double distanceRadians = 2.0 * Math.asin(Math.sqrt(c)); return Double.isNaN(distanceRadians) ? 0 : distanceRadians; } Location();  Location(double latitude, double longitude);  Location(Location location); static Location fromDegrees(double latitudeDegrees, double longitudeDegrees); static Location fromRadians(double latitudeRadians, double longitudeRadians); static Location fromTimeZone(TimeZone timeZone); static double normalizeLatitude(double degrees); static double normalizeLongitude(double degrees); static double clampLatitude(double degrees); static double clampLongitude(double degrees); static boolean locationsCrossAntimeridian(List<? extends Location> locations); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); Location set(double latitude, double longitude); Location set(Location location); Location interpolateAlongPath(Location endLocation, @WorldWind.PathType int pathType, double amount,
                                         Location result); double greatCircleAzimuth(Location location); double greatCircleDistance(Location location); Location greatCircleLocation(double azimuthDegrees, double distanceRadians, Location result); double rhumbAzimuth(Location location); double rhumbDistance(Location location); Location rhumbLocation(double azimuthDegrees, double distanceRadians, Location result); double linearAzimuth(Location location); double linearDistance(Location location); Location linearLocation(double azimuthDegrees, double distanceRadians, Location result); public double latitude; public double longitude; }