Ellipsoidal.Distance(olat, olon, tlat, tlon, a =6378137, b =6356752.314, tol=10^(-12))
Arguments
olat: Origin Latitude, degrees
olon: Origin Longitude, degrees
tlat: Target Latitude, degrees
tlon: Target Longitude, degrees
a: major axis, meters. If missing uses the
b: minor axis, meters
tol: Tolerance for convergence, default=10^(-12)
Details
Uses Vincenty's formulation to calculate the distance along a great circle on an ellipsoidal body.
If a and be are not provided, they are set by default to a=6378137.0 , b=6356752.314, the WGS-84 standard.
Only one pair of (olat, olon) and (tlat, tlon) can be given at a time. The program is not vectorized.
Quoting from the wiki page this algorithm was extracted from:
"Vincenty's formulae are two related iterative methods used in geodesy to calculate the distance between two points on the surface of an spheroid, developed by Thaddeus Vincenty in 1975. They are based on the assumption that the figure of the Earth is an oblate spheroid, and hence are more accurate than methods such as great-circle distance which assume a spherical Earth.
The first (direct) method computes the location of a point which is a given distance and azimuth (direction) from another point. The second (inverse) method computes the geographical distance and azimuth between two given points. They have been widely used in geodesy because they are accurate to within 0.5 mm (.020 sec) on the Earth ellipsoid"
Returns
list - dist: distance, km
az: azimuth, degrees
revaz: reverse azimuth, degrees
err: =0, if convergence failed, else=1
Note
Latitudes >90 and < -90 are not allowed. NA's are returned.
If points are identical, a distance of zero is returned and NA for the azimuths. If there is some problems with convergence or division by zero, NA's are returned and error message is printed.
A couple of known cases that do not work are, e.g.: (olat=0; olon=0; tlat=0; tlon=-180) and (olat=0; olon=0; tlat=0; tlon=180). They will return NA's to avoid division by zero.
I am not sure how to deal with these cases yet.
The reverse azimuth is the angle from the meridian on the target point to the great circle from the origin to the target (as far as I can tell). If distaz and Ellipsoidal.Distance are compared, they give the same azimuth, and the absolute angles of baz (from distaz) and revaz (from Ellipsoidal.Distance) will add to 180 degrees.
Vincenty, T. (April 1975). Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations. Survey Review XXIII (misprinted as XXII) (176): 88.201393. http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf. Retrieved 2009-07-11.