/** * Calculate the spherical distance from this LatLong to another. * <p/> * Use "distance" for faster computation with less accuracy. * * @param other The LatLong to calculate the distance to * @return the distance in meters as a double */ public double vincentyDistance(LatLong other) { return LatLongUtils.vincentyDistance(this, other); } }
@Test public void vincentyDistance_southPoleToNorthPole_returnTwiceOfDistanceFromPoleToEquator() { // Calculating the distance between the north pole and the equator LatLong northPole = new LatLong(90d, 0d); // Check if the distance from pole to pole works as well in the vincentyDistance LatLong southPole = new LatLong(-90d, 0d); double vincenty = LatLongUtils.vincentyDistance(southPole, northPole); assertEquals(2 * DISTANCE_POLE_TO_EQUATOR, vincenty, 1); }
@Test public void vincentyDistance_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 vincenty = LatLongUtils.vincentyDistance(zeroZero, nearSriLanka); assertEquals(EARTH_EQUATOR_CIRCUMFERENCE / 4, vincenty, 1E-4); }
@Test public void vincentyDistance_originToNorthPole_returnDistanceFromPoleToEquator() { // 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 vincenty = LatLongUtils.vincentyDistance(zeroZero, northPole); assertEquals(DISTANCE_POLE_TO_EQUATOR, vincenty, 1); }
/** * Calculate the spherical distance from this LatLong to another. * <p/> * Use "distance" for faster computation with less accuracy. * * @param other The LatLong to calculate the distance to * @return the distance in meters as a double */ public double vincentyDistance(LatLong other) { return LatLongUtils.vincentyDistance(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); }