Package com.irurueta.navigation.geodesic
Class GeodesicLine
java.lang.Object
com.irurueta.navigation.geodesic.GeodesicLine
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
- C. F. F. Karney, Algorithms for geodesics, J. Geodesy 87, 43–55 (2013) (addenda).
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
FieldsModifier and TypeFieldDescriptionprivate 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
ConstructorsModifierConstructorDescriptionGeodesicLine
(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 TypeMethodDescriptionarcPosition
(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 capabilitiesdouble
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
getArc()
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
init()
private void
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.
-
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
-
Method Details
-
position
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
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 theGeodesicMask.LONG_UNROLL
flag, the longitude is "unrolled" so that the quantity lon2 − lon1 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 ofGeodesicMask
values specifying which results should be returned.- Returns:
- a
GeodesicData
object including the requested results.
-
arcPosition
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
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 theGeodesicMask.LONG_UNROLL
flags.- Parameters:
a12
- arc length from point 1 to point 2 (degrees); it can be negative.outmask
- a bitor'ed combination ofGeodesicMask
values specifying which results should be returned.- Returns:
- a
GeodesicData
object giving lat1, lon2, azi2, and a12.
-
position
The general position function.position(double, int)
andarcPosition(double, int)
are defined in terms of this function. TheGeodesicMask
values possible for outmask are-
outmask |=
GeodesicMask.LATITUDE
for the latitude lat2; -
outmask |=
GeodesicMask.LONGITUDE
for the latitude lon2; -
outmask |=
GeodesicMask.AZIMUTH
for the latitude azi2; -
outmask |=
GeodesicMask.DISTANCE
for the distance s12; -
outmask |=
GeodesicMask.REDUCED_LENGTH
for the reduced length m12; -
outmask |=
GeodesicMask.GEODESIC_SCALE
for the geodesic scales M12 and M21; -
outmask |=
GeodesicMask.ALL
for all of the above; -
outmask |=
GeodesicMask.LONG_UNROLL
to unroll lon2 (instead of reducing it to the range [−180°, 180°]).
- 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 ofGeodesicMask
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.
-
outmask |=
-
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
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
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'edGeodesicMask
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.
-