OpenMap-java/openmap

Geo.distanceKM() and Geo.distanceNM() return inconsistent results

tdox opened this issue · 5 comments

tdox commented

The following JUnit test should pass but it fails because distanceKM and distanceNM return inconsistent results. This is because the constants used to define Length for KM and NM are inconsistent.


import org.junit.Assert;
import org.junit.Test;

import com.bbn.openmap.geo.Geo;

public class TestOpenMap {

     @Test
      public void testLatLonConversion2() {
        System.out.println("@Test - testLatLonConversion");

        double bosLat =   42.366978;
        double bosLon =  -71.022362;
        double sfoLat =   37.615223;
        double sfoLon = -122.389977;


        double distNM = Geo.distanceNM(bosLat, bosLon, sfoLat, sfoLon);
        System.out.println("distNM: " + distNM);
        double distKM1 = distNM * Geo.METERS_PER_NM / 1000;
        System.out.println("distKM1: " + distKM1);

        double distKM2 = Geo.distanceKM(bosLat, bosLon, sfoLat, sfoLon);
        System.out.println("distKM2: " + distKM2);

        // from Planet.java
        double wgs84_earthEquatorialRadiusMeters_D = 6378137.0;
        double circumferenceMeters = wgs84_earthEquatorialRadiusMeters_D * 2.0 * Math.PI;
        double wgs84_earthEquatorialCircumferenceNMiles_D = 21600.0;

        double circumf_meters_per_nm = circumferenceMeters / wgs84_earthEquatorialCircumferenceNMiles_D;

        System.out.println("circumf_meters_per_nm: " + circumf_meters_per_nm);
        System.out.println("Geo.METERS_PER_NM: " + Geo.METERS_PER_NM);

        Assert.assertEquals(distKM1, distKM2, 1);
      }
}

The output from this is:

@Test - testLatLonConversion
distNM: 2349.072077502113
distKM1: 4350.481487533914
distKM2: 4358.291791737208
circumf_meters_per_nm: 1855.3248465545596
Geo.METERS_PER_NM: 1852.0

What version are you running your test against? My results are different, running against the latest release and the current branches:

@test - testLatLonConversion
distNM: 2353.289243031874
distKM1: 4358.291678095031
distKM2: 4358.291791737208
circumf_meters_per_nm: 1855.3248465545596
Geo.METERS_PER_NM: 1852.0

tdox commented

5.1.6

On May 19, 2016, at 6:19 PM, Don Dietrick notifications@github.com wrote:

What version are you running your test against? My results are different, running against the latest release and the current branches:

@test https://github.com/Test - testLatLonConversion
distNM: 2353.289243031874
distKM1: 4358.291678095031
distKM2: 4358.291791737208
circumf_meters_per_nm: 1855.3248465545596
Geo.METERS_PER_NM: 1852.0


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub #24 (comment)

tdox commented

I will try again with the latest version.

I've updated the repository with some slight changes that resolve the inconsistencies completely, if the Planet.java values in the test case are replaced with the Planet.java values.

tdox commented

I tried version 5.1.13 and the distanceKM vs distanceNM issue is fixed for me. Thanks for your help!