# Vincenty's formulae

For the mathematical background to this problem, see Geodesics on an ellipsoid.

Vincenty's formulae are two related iterative methods used in geodesy to calculate the distance between two points on the surface of a spheroid, developed by Thaddeus Vincenty (1975a) 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 (0.020″) on the Earth ellipsoid.

## Background

Vincenty's goal was to express existing algorithms for geodesics on an ellipsoid in a form that minimized the program length (see the first sentence of his paper). His unpublished report (1975b) mentions the use of a Wang 720 desk calculator which had only a few kilobytes of memory. To obtain good accuracy for long lines, the solution uses the classical solution of Legendre (1806), Bessel (1825), and Helmert (1880) based on the auxiliary sphere. (Vincenty relied on formulation of this method given by Rainsford, 1955.) Legendre showed that an ellipsoidal geodesic can be exactly mapped to a great circle on the auxiliary sphere by mapping the geographic latitude to reduced latitude and setting the azimuth of the great circle equal to that of the geodesic. The longitude on the ellipsoid and the distance along the geodesic are then given in terms of the longitude on the sphere and the arc length along the great circle by simple integrals. Bessel and Helmert gave rapidly converging series for these integrals which allow the geodesic to be computed with arbitrary accuracy.

In order to minimize the program size, Vincenty took these series, re-expanded them using the first term of each series as the small parameter, and truncated them to order ƒ3. This resulted in compact expressions for the longitude and distance integrals. The expressions were put in Horner (or nested) form, since this allows polynomials to be evaluated using only a single temporary register. Finally, simple iterative techniques were used to solve the implicit equations in the direct and inverse methods; even though these are slow (and in the case of the inverse method it sometimes does not converge), they result in the least increase in code size.

## Notation

Define the following notation:

 a length of semi-major axis of the ellipsoid (radius at equator); (6378137.0 metres in WGS-84) ƒ flattening of the ellipsoid; (1/298.257223563 in WGS-84) b = (1 - ƒ) a length of semi-minor axis of the ellipsoid (radius at the poles); (6356752.314245 meters in WGS-84) φ1, φ2 latitude of the points; U1 = arctan[(1 − ƒ) tan φ1], U2 = arctan[(1 − ƒ) tan φ2] reduced latitude (latitude on the auxiliary sphere) L = L2 - L1 difference in longitude of two points; λ1, λ2 longitude of the points on the auxiliary sphere; α1, α2 forward azimuths at the points; α azimuth at the equator; s ellipsoidal distance between the two points; σ arc length between points on the auxiliary sphere

## Inverse problem

Given the coordinates of the two points (φ1L1) and (φ2L2), the inverse problem finds the azimuths α1, α2 and the ellipsoidal distance s.

Calculate U1, U2 and L, and set initial value of λ = L. Then iteratively evaluate the following equations until λ converges:

$\sin \sigma = \sqrt{ (\cos U_2 \sin \lambda)^2 + (\cos U_1 \sin U_2 - \sin U_1 \cos U_2 \cos \lambda)^2}$
$\cos \sigma = \sin U_1 \sin U_2 + \cos U_1 \cos U_2 \cos \lambda \,$
$\sigma = \arctan\frac{\sin\sigma}{\cos\sigma}\,$[1][2]
$\sin \alpha = \frac{\cos U_1 \cos U_2 \sin \lambda}{\sin \sigma} \,$[3]
$\cos^2 \alpha = 1 - \sin^2 \alpha \,$
$\cos (2 \sigma_m) = \cos \sigma - \frac{2 \sin U_1\sin U_2}{\cos^2 \alpha} \,$[4]
$C = \frac{f}{16} \cos^2 \alpha \big[4 + f(4-3 \cos^2 \alpha) \big] \,$
$\lambda = L + (1-C) f \sin \alpha \left\{ \sigma + C \sin \sigma \left[\cos (2 \sigma_m) + C \cos \sigma (-1 + 2 \cos^2 (2 \sigma_m)) \right]\right\} \,$

When λ has converged to the desired degree of accuracy (10−12 corresponds to approximately 0.06mm), evaluate the following:

$u^2 = \cos^2 \alpha \frac{a^2 - b^2}{b^2} \,$
$A = 1 + \frac{u^2}{16384} \left\{ 4096 + u^2 \left[ -768 +u^2 (320 - 175u^2) \right] \right\}$
$B = \frac{u^2}{1024} \left\{ 256 + u^2 \left[ -128 + u^2 (74-47 u^2) \right] \right\}$
$\Delta \sigma = B \sin \sigma \Big\{ \cos(2 \sigma_m) + \tfrac{1}{4} B \big[ \cos \sigma \big(-1+2 \cos^2(2 \sigma_m) \big) - \tfrac{1}{6} B \cos(2 \sigma_m) (-3+4 \sin^2 \sigma) \big(-3+4 \cos^2 (2 \sigma_m)\big) \big] \Big\}$
$s = b A(\sigma - \Delta \sigma) \,$
$\alpha_1 = \arctan \left( \frac{\cos U_2 \sin \lambda}{\cos U_1 \sin U_2 - \sin U_1 \cos U_2 \cos \lambda} \right)$[2]
$\alpha_2 = \arctan \left( \frac{\cos U_1 \sin \lambda}{-\sin U_1 \cos U_2 + \cos U_1 \sin U_2 \cos \lambda} \right)$[2]

Between two nearly antipodal points, the iterative formula may fail to converge; this will occur when the first guess at λ as computed by the equation above is greater than π in absolute value.

## Direct Problem

Given an initial point (φ1, L1) and initial azimuth, α1, and a distance, s, along the geodesic the problem is to find the end point (φ2, L2) and azimuth, α2.

Start by calculating the following:

$\tan U_1 = (1 - f)\tan \phi_1 \,$
$\sigma_1 = \arctan \left ( \frac{ \tan U_1}{ \cos \alpha_1} \right ) \,$[2]
$\sin \alpha = \cos U_1 \sin \alpha_1; \,\,\,\, \cos^2 \alpha = (1 - \sin \alpha)(1 + \sin \alpha)$
$u^2 = \cos^2 \alpha \frac{a^2 - b^2}{b^2} \,$
$A = 1 + \frac{u^2}{16384} \left\{ 4096 + u^2 \left[ -768 +u^2 (320 - 175u^2) \right] \right\}$
$B = \frac{u^2}{1024} \left\{ 256 + u^2 \left[ -128 + u^2 (74-47 u^2) \right] \right\}$

Then, using an initial value $\sigma = \tfrac{s}{bA}$, iterate the following equations until there is no significant change in σ:

$2 \sigma_m = 2 \sigma_1 + \sigma \,$
$\Delta \sigma = B \sin \sigma \Big\{ \cos(2 \sigma_m) + \tfrac{1}{4} B \big[ \cos \sigma \big(-1+2 \cos^2(2 \sigma_m) \big) - \tfrac{1}{6} B \cos(2 \sigma_m) (-3+4 \sin^2 \sigma) \big(-3+4 \cos^2 (2 \sigma_m)\big) \big] \Big\}$
$\sigma = \frac{s}{bA} + \Delta \sigma \,$

Once σ is obtained to sufficient accuracy evaluate:

$\phi_2 = \arctan \left( \frac{\sin U_1 \cos \sigma + \cos U_1 \sin \sigma \cos \alpha_1}{(1 - f) \sqrt{\sin^2 \alpha + (\sin U_1 \sin \sigma - \cos U_1 \cos \sigma \cos \alpha_1 )^2 } } \right) \,$[2]
$\lambda = \arctan \left( \frac{\sin \sigma \sin \alpha_1}{\cos U_1 \cos \sigma - \sin U_1 \sin \sigma \cos \alpha_1} \right) \,$[2]
$C = \frac{f}{16} \cos^2 \alpha \big[4 + f(4-3 \cos^2 \alpha) \big] \,$
$L = \lambda - (1-C) f \sin \alpha \left\{ \sigma + C \sin \sigma \left[\cos (2 \sigma_m) + C \cos \sigma (-1 + 2 \cos^2 (2 \sigma_m)) \right]\right\} \,$
$\alpha_2 = \arctan \left( \frac{\sin \alpha}{-\sin U_1 \sin \sigma + \cos U_1 \cos \sigma \cos \alpha_1} \right) \,$[2]

If the initial point is at the North or South pole then the first equation is indeterminate. If the initial azimuth is due East or West then the second equation is indeterminate. If a double valued atan2 type function is used then these values are usually handled correctly.

## Vincenty's modification

In his letter to Survey Review in 1976, Vincenty suggested replacing his series expressions for A and B with simpler formulas using Helmert's expansion parameter k1:

$A = \frac {1 + \frac {1}{4} (k_1)^2}{1 - k_1}$

$B = k_1(1 - \tfrac {3}{8}(k_1)^2)$

where $k_1 = \frac { \sqrt {(1 + u^2)} - 1}{ \sqrt {(1 + u^2)} + 1}$

## Nearly antipodal points

As noted above, the iterative solution to the inverse problem fails to converge or converges slowly for nearly antipodal points. An example of slow convergence is (φ1L1) = (0°, 0°) and (φ2L2) = (0.5°, 179.5°) for the WGS84 ellipsoid. This requires about 130 iterations to give a result accurate to 1 mm. Depending on how the inverse method is implemented, the algorithm might return the correct result (19936288.579 m), an incorrect result, or an error indicator. An example of an incorrect result is provided by the NGS online utility which returns a distance which is about 5 km too long. Vincenty suggested a method of accelerating the convergence in such cases (Rapp, 1973).

An example of a failure of the inverse method to converge is (φ1L1) = (0°, 0°) and (φ2L2) = (0.5°, 179.7°) for the WGS84 ellipsoid. In an unpublished report, Vincenty (1975b) gave an alternative iterative scheme to handle such cases. This converges to the correct result 19944127.421 m after about 60 iterations; however, in other cases many thousands of iterations are required.

Newton's method has been successfully used to give rapid convergence for all pairs of input points (Karney, 2013).

4. ^ Start and end point are on the equator. In this case C = 0 so the value of $\cos (2 \sigma_m)$ is not used. The limiting value is $\cos (2 \sigma_m) = -1$.