/** * Calculate the spherical distance from this LatLong to another. * <p/> * Use vincentyDistance for more accuracy but less performance. * * @param other The LatLong to calculate the distance to * @return the distance in meters as a double */ public double sphericalDistance(LatLong other) { return LatLongUtils.sphericalDistance(this, other); }
@Test public void sphericalDistance_originToNorthPole_returnQuarterOfEarthEquatorCircumference() { // This is the origin of the WGS-84 reference system LatLong zeroZero = new LatLong(0d, 0d); // Calculating the distance between the north pole and the equator LatLong northPole = new LatLong(90d, 0d); double spherical = LatLongUtils.sphericalDistance(zeroZero, northPole); assertEquals(EARTH_EQUATOR_CIRCUMFERENCE / 4, spherical, 0d); }
@Test public void sphericalDistance_nearOfSriLankaToIslaGenovesa_returnHalfOfEarthEquatorCircumference() { // These coordinates are 1/4 Earth circumference from zero on the equator LatLong nearSriLanka = new LatLong(0d, 90d); // These coordinates are 1/4 Earth circumference from zero on the equator LatLong islaGenovesa = new LatLong(0d, -90d); // These points are as far apart as they could be, half way around the earth double spherical = LatLongUtils.sphericalDistance(nearSriLanka, islaGenovesa); assertEquals(EARTH_EQUATOR_CIRCUMFERENCE / 2, spherical, 0d); }
@Test public void sphericalDistance_originToIslaGenovesa_returnQuarterOfEarthEquatorCircumference() { // This is the origin of the WGS-84 reference system LatLong zeroZero = new LatLong(0d, 0d); // These coordinates are 1/4 Earth circumference from zero on the equator LatLong islaGenovesa = new LatLong(0d, -90d); double spherical = LatLongUtils.sphericalDistance(zeroZero, islaGenovesa); assertEquals(EARTH_EQUATOR_CIRCUMFERENCE / 4, spherical, 0d); }
@Test public void sphericalDistance_originToNearOfSriLanka_returnQuarterOfEarthEquatorCircumference() { // This is the origin of the WGS-84 reference system LatLong zeroZero = new LatLong(0d, 0d); // These coordinates are 1/4 Earth circumference from zero on the equator LatLong nearSriLanka = new LatLong(0d, 90d); double spherical = LatLongUtils.sphericalDistance(zeroZero, nearSriLanka); assertEquals(EARTH_EQUATOR_CIRCUMFERENCE / 4, spherical, 0d); }
/** * Calculate the spherical distance from this LatLong to another. * <p/> * Use vincentyDistance for more accuracy but less performance. * * @param other The LatLong to calculate the distance to * @return the distance in meters as a double */ public double sphericalDistance(LatLong other) { return LatLongUtils.sphericalDistance(this, other); }
@Test public void sphericalDistanceAndVincentyDistance_originToNearOfSriLanka_bothShouldBeNearlyTheSame() { // This is the origin of the WGS-84 reference system LatLong zeroZero = new LatLong(0d, 0d); // These coordinates are 1/4 Earth circumference from zero on the equator LatLong nearSriLanka = new LatLong(0d, 90d); // On the equator the result of the different distance calculation methods should be // about the same double spherical = LatLongUtils.sphericalDistance(zeroZero, nearSriLanka); double vincenty = LatLongUtils.vincentyDistance(zeroZero, nearSriLanka); assertEquals(spherical, vincenty, 1E-4); }