Class GeodesicLine

java.lang.Object
com.irurueta.navigation.geodesic.GeodesicLine

public class GeodesicLine extends Object
A geodesic line GeodesicLine facilitates the determination of a series of points on a single geodesic. The starting point (lat1, lon1) and the azimuth azi1 are specified in the constructor; alternatively, the Geodesic.line(double, double, double) method can be used to create a GeodesicLine. position(double) returns the location of point 2 a distance s12 along the geodesic. Alternatively arcPosition(double) gives the position of point 2 an arc length a12 along the geodesic. You can register the position of a reference point 3 a distance (arc length), s13 (a13) along the geodesic with the setDistance(double) (setArc(double)) functions. Points a fractional distance along the line can be found by providing, for example, 0.5 * getDistance() as an argument to position(double). The Geodesic.inverseLine(double, double, double, double) or Geodesic.directLine(double, double, double, double) methods return GeodesicLine objects with point 3 set to the point 2 of the corresponding geodesic problem. GeodesicLine objects created with the public constructor or with Geodesic.line(double, double, double) have s13 and a13 set to NaNs. The calculations are accurate to better than 15 nm (15 nanometers). See Sec. 9 of arXiv:1102.1215v1 for details. The algorithms used by this class are based on series expansions using the flattening f as a small parameter. These are only accurate for |f < 0.02; however reasonably accurate results will be obtained for |f < 0.2. The algorithms are described in Here's an example of using this class
 
 import net.sf.geographiclib.*;
 public class GeodesicLineTest {
   public static void main(String[] args) {
     // Print waypoints between JFK and SIN
     Geodesic geod = Geodesic.WGS84;
     double
       lat1 = 40.640, lon1 = -73.779, // JFK
       lat2 =  1.359, lon2 = 103.989; // SIN
     GeodesicLine line = geod.InverseLine(lat1, lon1, lat2, lon2,
                                          GeodesicMask.DISTANCE_IN |
                                          GeodesicMask.LATITUDE |
                                          GeodesicMask.LONGITUDE);
     double ds0 = 500e3;     // Nominal distance between points = 500 km
     // The number of intervals
     int num = (int)(Math.ceil(line.Distance() / ds0));
     {
       // Use intervals of equal length
       double ds = line.Distance() / num;
       for (int i = 0; i <= num; ++i) {
         GeodesicData g = line.Position(i * ds,
                                        GeodesicMask.LATITUDE |
                                        GeodesicMask.LONGITUDE);
         System.out.println(i + " " + g.lat2 + " " + g.lon2);
       }
     }
     {
       // Slightly faster, use intervals of equal arc length
       double da = line.Arc() / num;
       for (int i = 0; i <= num; ++i) {
         GeodesicData g = line.ArcPosition(i * da,
                                           GeodesicMask.LATITUDE |
                                           GeodesicMask.LONGITUDE);
         System.out.println(i + " " + g.lat2 + " " + g.lon2);
       }
     }
   }
 }
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double[]
     
    private double[]
     
    private double
     
    private double[]
     
    private double[]
     
    private double[]
     
    private double
     
    private double
     
    private int
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
    private double
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    GeodesicLine(Geodesic g, double lat1, double lon1, double azi1)
    Constructor for a geodesic line staring at latitude lat1, longitude lon1, and azimuth azi1 (all in degrees).
    protected
    GeodesicLine(Geodesic g, double lat1, double lon1, double azi1, double salp1, double calp1, int caps, boolean arcmode, double s13A13)
     
     
    GeodesicLine(Geodesic g, double lat1, double lon1, double azi1, int caps)
    Constructor for a geodesic line starting at latitude lat1, longitude lon1, and azimuth azi1 (all in degrees) with a subset of the capabilities included.
  • Method Summary

    Modifier and Type
    Method
    Description
    arcPosition(double a12)
    Compute the position of point 2 which is an arc length a12 (degrees) from point 1.
    arcPosition(double a12, int outmask)
    Compute the position of point 2 which is an arc length a12 (degrees) from point 1 and with a subset of th geodesic results returned.
    boolean
    capabilities(int testcaps)
    Indicates whether this GeodesicLine object has all tested capabilities
    double
    genDistance(boolean arcmode)
    The distance or arc length to point 3.
    void
    genSetDistance(boolean arcmode, double s13A13)
    Specify position of point 3 in terms of either distance or arc length.
    double
    Gets the arc length to point 3 (degrees).
    double
    Gets the azimuth (degrees) of the geodesic line at point 1.
    Gets a pair of sine and cosine of azi1 the azimuth (degrees) of the geodesic line at point 1.
    int
    Gets the computational capabilities that this object was constructed with.
    double
    Gets the distance to point 3 (meters).
    double
    Gets the arc length (degrees) between the northward equatorial crossing and point 1.
    double
    Gets the azimuth (degrees) of the geodesic line as it crosses the equator in a northward direction.
    Gets a pair of sine and cosine of azi0 the azimuth of the godesic line as it crosses the equator in a northward direction.
    double
    Gets the flattening of the ellipsoid.
    double
    Gets the latitude of point 1 (degrees).
    double
    Gets the longitude of point 1 (degrees).
    double
    Gets the equatorial radius of the ellipsoid (meters).
    private boolean
     
    private void
    lineInit(Geodesic g, double lat1, double lon1, double azi1, double salp1, double calp1, int caps)
     
    position(boolean arcmode, double s12A12, int outmask)
    The general position function.
    position(double s12)
    Compute the position of point 2 which is a distance s12 (meters) from point 1.
    position(double s12, int outmask)
    Compute the position of point 2 which is a distance s12 (meters) from point 1 and with a subset of the geodesic results returned.
    (package private) void
    setArc(double a13)
    Specify position of point 3 in terms of arc length.
    void
    setDistance(double s13)
    Specify position of point 3 in terms of distance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NC1

      private static final int NC1
      See Also:
    • NC1P

      private static final int NC1P
      See Also:
    • NC2

      private static final int NC2
      See Also:
    • NC3

      private static final int NC3
      See Also:
    • NC4

      private static final int NC4
      See Also:
    • lat1

      private double lat1
    • lon1

      private double lon1
    • azi1

      private double azi1
    • a

      private double a
    • f

      private double f
    • b

      private double b
    • c2

      private double c2
    • f1

      private double f1
    • salp0

      private double salp0
    • calp0

      private double calp0
    • k2

      private double k2
    • salp1

      private double salp1
    • calp1

      private double calp1
    • ssig1

      private double ssig1
    • csig1

      private double csig1
    • dn1

      private double dn1
    • stau1

      private double stau1
    • ctau1

      private double ctau1
    • somg1

      private double somg1
    • comg1

      private double comg1
    • a1m1

      private double a1m1
    • a2m1

      private double a2m1
    • a3c

      private double a3c
    • b11

      private double b11
    • b21

      private double b21
    • b31

      private double b31
    • a4

      private double a4
    • b41

      private double b41
    • a13

      private double a13
    • s13

      private double s13
    • c1a

      private double[] c1a
    • c1pa

      private double[] c1pa
    • c2a

      private double[] c2a
    • c3a

      private double[] c3a
    • c4a

      private double[] c4a
    • caps

      private int caps
  • Constructor Details

    • GeodesicLine

      public GeodesicLine(Geodesic g, double lat1, double lon1, double azi1)
      Constructor for a geodesic line staring at latitude lat1, longitude lon1, and azimuth azi1 (all in degrees). If the point is at a pole, the azimuth is defined by keeping lon1 fixed, writing lat1 = ±(90° − ε), and taking the limit ε → 0+.
      Parameters:
      g - a Geodesic object used to compute the necessary information about the GeodesicLine
      lat1 - latitude of point 1 (degrees). lat1 should be in the range [−90°, 90°].
      lon1 - longitude of point 1 (degrees).
      azi1 - azimuth at point 1 (degrees).
    • GeodesicLine

      public GeodesicLine(Geodesic g, double lat1, double lon1, double azi1, int caps)
      Constructor for a geodesic line starting at latitude lat1, longitude lon1, and azimuth azi1 (all in degrees) with a subset of the capabilities included. The GeodesicMask values are:
      Parameters:
      g - a Geodesic object used to compute the necessary information about the GeodesicLine.
      lat1 - latitude of point 1 (degrees).
      lon1 - longitude of point 1 (degrees).
      azi1 - azimuth at point 1 (degrees).
      caps - bitor'ed combination of GeodesicMask values specifying the capabilities the GeodesicLine object should possess, i.e., which quantities can be returned in calls to position(double).
    • GeodesicLine

      protected GeodesicLine(Geodesic g, double lat1, double lon1, double azi1, double salp1, double calp1, int caps, boolean arcmode, double s13A13)
  • Method Details

    • position

      public GeodesicData position(double s12)
      Compute the position of point 2 which is a distance s12 (meters) from point 1. The values of lon2 and azi2 returned are in the range [−180°, 180°]. The GeodesicLine object must have been constructed with caps |= GeodesicMask.DISTANCE_IN; otherwise no parameters are set.
      Parameters:
      s12 - distance from point 1 to point 2 (meters); it can be negative.
      Returns:
      a GeodesicData object with the following fields: lat1, lon1, azi1, lat2, lon2, azi2, s12, a12. Some of these results may be missing if the GeodesicLine did not include the relevant capability.
    • position

      public GeodesicData position(double s12, int outmask)
      Compute the position of point 2 which is a distance s12 (meters) from point 1 and with a subset of the geodesic results returned. The GeodesicLine object must have been constructed with caps |= GeodesicMask.DISTANCE_IN; otherwise no parameters are set. Requesting a value which the GeodesicLine object is not capable of computing is not an error (no parameters will be set). The value of lon2 returned is normally in the range [−180°, 180°]; however if the outmask includes the GeodesicMask.LONG_UNROLL flag, the longitude is "unrolled" so that the quantity lon2lon1 indicates how many times and in what sense the geodesic encircles the ellipsoid.
      Parameters:
      s12 - distance from point 1 to point 2 (meters); it can be negative.
      outmask - a bitor'ed combination of GeodesicMask values specifying which results should be returned.
      Returns:
      a GeodesicData object including the requested results.
    • arcPosition

      public GeodesicData arcPosition(double a12)
      Compute the position of point 2 which is an arc length a12 (degrees) from point 1. The values of lon2 and azi2 returned are in the range [−180°, 180°]. The GeodesicLine object must have been constructed with caps |= GeodesicMask.DISTANCE_IN; otherwise no parameters are set.
      Parameters:
      a12 - arc length from point 1 to point 2 (degrees); it can be negative.
      Returns:
      a GeodesicData object with the following fields: lat1, lon1, azi1, lat2, lon2, azi2, s12, a12. Some of these results may be missing if the GeodesicLine did not include the relevant capability.
    • arcPosition

      public GeodesicData arcPosition(double a12, int outmask)
      Compute the position of point 2 which is an arc length a12 (degrees) from point 1 and with a subset of th geodesic results returned. Requesting a value which the GeodesicLine object is not capable of computing is not an error (no parameters will be set). The value of lon2 returned is in the range [−180°, 180°], unless the outmask includes the GeodesicMask.LONG_UNROLL flags.
      Parameters:
      a12 - arc length from point 1 to point 2 (degrees); it can be negative.
      outmask - a bitor'ed combination of GeodesicMask values specifying which results should be returned.
      Returns:
      a GeodesicData object giving lat1, lon2, azi2, and a12.
    • position

      public GeodesicData position(boolean arcmode, double s12A12, int outmask)
      The general position function. position(double, int) and arcPosition(double, int) are defined in terms of this function. The GeodesicMask values possible for outmask are
      Parameters:
      arcmode - boolean flag determining the meaning of the second parameter; if arcmode is false, then the GeodesicLine object must have been constructed with caps |= GeodesicMask.DISTANCE_IN.
      s12A12 - if arcmode is false, this is the distance between point 1 and point 2 (meters); otherwise it is the arc length between point 1 and point 2 (degrees); it can be negative.
      outmask - a bitor'ed combination of GeodesicMask values specifying which results should be returned.
      Returns:
      a GeodesicData object with the requested results. Requesting a value which the GeodesicLine object is not capable of computing is not an error; Double.NaN is returned instead.
    • setDistance

      public void setDistance(double s13)
      Specify position of point 3 in terms of distance. This is only useful if the GeodesicLine object has been constructed with caps |= GeodesicMask.DISTANCE_IN.
      Parameters:
      s13 - the distance from point 1 to point 3 (meters); it can be negative.
    • genSetDistance

      public void genSetDistance(boolean arcmode, double s13A13)
      Specify position of point 3 in terms of either distance or arc length.
      Parameters:
      arcmode - boolean flag determining the meaning of the second parameter; if arcmode is false, then the GeodesicLine object must have been constructed with caps |= GeodesicMask.DISTANCE_IN.
      s13A13 - if arcmode is false, this is the distance from point 1 to point 3 (meters); otherwise it is the arc length from point 1 to point 3 (degrees); it can be negative.
    • getLatitude

      public double getLatitude()
      Gets the latitude of point 1 (degrees).
      Returns:
      lat1 the latitude of point 1 (degrees).
    • getLongitude

      public double getLongitude()
      Gets the longitude of point 1 (degrees).
      Returns:
      lon1 the longitude of point 1 (degrees).
    • getAzimuth

      public double getAzimuth()
      Gets the azimuth (degrees) of the geodesic line at point 1.
      Returns:
      azi1 the azimuth (degrees) of the geodesic line at point 1.
    • getAzimuthCosines

      public Pair getAzimuthCosines()
      Gets a pair of sine and cosine of azi1 the azimuth (degrees) of the geodesic line at point 1.
      Returns:
      pair of sine and cosine of azi1 the azimuth (degrees) of the geodesic line at point 1.
    • getEquatorialAzimuth

      public double getEquatorialAzimuth()
      Gets the azimuth (degrees) of the geodesic line as it crosses the equator in a northward direction.
      Returns:
      azi0 the azimuth (degrees) of the geodesic line as it crosses the equator in a northward direction.
    • getEquatorialAzimuthCosines

      public Pair getEquatorialAzimuthCosines()
      Gets a pair of sine and cosine of azi0 the azimuth of the godesic line as it crosses the equator in a northward direction.
      Returns:
      pair of sine and cosine of azi0 the azimuth of the godesic line as it crosses the equator in a northward direction.
    • getEquatorialArc

      public double getEquatorialArc()
      Gets the arc length (degrees) between the northward equatorial crossing and point 1.
      Returns:
      a1 the arc length (degrees) between the northward equatorial crossing and point 1.
    • getMajorRadius

      public double getMajorRadius()
      Gets the equatorial radius of the ellipsoid (meters). This is the value inherited from the Geodesic object used in the constructor.
      Returns:
      a the equatorial radius of the ellipsoid (meters).
    • getFlattening

      public double getFlattening()
      Gets the flattening of the ellipsoid. This is the value inherited from the Geodesic object used in the constructor.
      Returns:
      f the flattening of the ellipsoid.
    • getCapabilities

      public int getCapabilities()
      Gets the computational capabilities that this object was constructed with. LATITUDE and AZIMUTH are always included.
      Returns:
      caps the computation capabilities that this object was constructed with.
    • capabilities

      public boolean capabilities(int testcaps)
      Indicates whether this GeodesicLine object has all tested capabilities
      Parameters:
      testcaps - a set of bitor'ed GeodesicMask values.
      Returns:
      true if the GeodesicLine object has all these capabilities.
    • genDistance

      public double genDistance(boolean arcmode)
      The distance or arc length to point 3.
      Parameters:
      arcmode - boolean flag determining the meaning of returned value.
      Returns:
      s13 if arcmode is false; a13 if arcmode is true.
    • getDistance

      public double getDistance()
      Gets the distance to point 3 (meters).
      Returns:
      s13 the disance to point 3 (meters).
    • getArc

      public double getArc()
      Gets the arc length to point 3 (degrees).
      Returns:
      a13 the arc length to point 3 (degrees).
    • setArc

      void setArc(double a13)
      Specify position of point 3 in terms of arc length. The distance s13 is only set if the GeodesicLine object has been constructed with caps |= GeodesicMask.DISTANCE.
      Parameters:
      a13 - the arc length from point 1 to point 3 (degrees); it can be negative.
    • init

      private boolean init()
      Returns:
      true if the object has been initialized.
    • lineInit

      private void lineInit(Geodesic g, double lat1, double lon1, double azi1, double salp1, double calp1, int caps)