Menu

Possible Bug In Java Implementation

Anonymous
2016-02-13
2016-02-13
  • Anonymous

    Anonymous - 2016-02-13

    To whom it may concern,
    When I browse here:

    http://geographiclib.sourceforge.net/cgi-bin/GeodSolve

    ...and enter the following values:

    90.0 10.0 180.0 -1000000.0

    ...to solve the direct problem using all default values,
    I get what appears to be a reasonable latitude and longitude
    for the second point:

    lat2 lon2 fazi2 (°) = 81.04623282 -170.00000000 0.00000000

    But, when I download GeographicLib-1.45.zip from here:

    https://sourceforge.net/projects/geographiclib/files/distrib/

    ...and then compile and run the Java
    version, I get the following instead:

    lat2 lon2 fazi2 (°) = 81.04623281595062 10.0 0.0

    The longitude in the Java version appears to be incorrect.
    I would expect these two approaches to yield the same result.
    My test code:

    public static void main(String[] args)
    {
    GeodesicData geo = Geodesic.WGS84.Direct(90.0, 10.0, 180.0, -1000000.0);
    System.out.println("lat2 lon2 fazi2 (°) = " + geo.lat2 + " "
    + geo.lon2 + " " + geo.azi2);
    }

    This same behavior occurs at the south pole as well.
    I compiled the Java code with Java V1.8.0_74 64-bit on
    Windows 7. Maybe I'm not using the classes correctly?
    Any help would be appreciated.

     
  • Charles Karney

    Charles Karney - 2016-02-13

    Yes, this is a bug which was introduced in version 1.44 and it is
    present also in version 1.45. It's fixed in version 1.46-SNAPSHOT.
    Here's the patch to 1.45

    diff --git a/java/src/main/java/net/sf/geographiclib/GeodesicLine.java b/java/src/main/java/net/sf/geographiclib/GeodesicLine.java
    index 307b316..9e7cc62 100644
    --- a/java/src/main/java/net/sf/geographiclib/GeodesicLine.java
    +++ b/java/src/main/java/net/sf/geographiclib/GeodesicLine.java
    @@ -179,7 +179,8 @@ public class GeodesicLine {
         { Pair p = GeoMath.sincosd(GeoMath.AngRound(_lat1));
           sbet1 = _f1 * p.first; cbet1 = p.second; }
         // Ensure cbet1 = +epsilon at poles
    -    { Pair p = GeoMath.norm(sbet1, cbet1); sbet1 = p.first; cbet1 = p.second; }
    +    { Pair p = GeoMath.norm(sbet1, cbet1);
    +      sbet1 = p.first; cbet1 = Math.max(Geodesic.tiny_, p.second); }
         _dn1 = Math.sqrt(1 + g._ep2 * GeoMath.sq(sbet1));
    
         // Evaluate alp0 from sin(alp1) * cos(bet1) = sin(alp0),
    

    I'll add a unit test to cover this issue.

    Thanks for bringing this to my attention.

     

Anonymous
Anonymous

Add attachments
Cancel