# Great-circle distance

A diagram illustrating great-circle distance (drawn in red) between two points on a sphere, P and Q. Two antipodal points, u and v, are also depicted.

The great-circle distance or orthodromic distance is the shortest distance between two points on the surface of a sphere, measured along the surface of the sphere (as opposed to a straight line through the sphere's interior). The distance between two points in Euclidean space is the length of a straight line between them, but on the sphere there are no straight lines. In non-Euclidean geometry, straight lines are replaced by geodesics. Geodesics on the sphere are the great circles (circles on the sphere whose centers coincide with the center of the sphere).

Through any two points on a sphere that are not directly opposite each other, there is a unique great circle. The two points separate the great circle into two arcs. The length of the shorter arc is the great-circle distance between the points. A great circle endowed with such a distance is the Riemannian circle.

Between two points that are directly opposite each other, called antipodal points, there are infinitely many great circles, but all great circle arcs between antipodal points have the same length, i.e. half the circumference of the circle, or ${\displaystyle \pi r}$, where r is the radius of the sphere.

The Earth is nearly spherical (see Earth radius) so great-circle distance formulas give the distance between points on the surface of the Earth (as the crow flies) correct to within 0.5% or so.[1] (See Arc length § Arcs of great circles on the Earth.)

## Formulas

An illustration of the central angle, Δσ, between two points, P and Q. λ and φ are the longitudinal and latitudinal angles of P respectively

Let ${\displaystyle \phi _{1},\lambda _{1}}$ and ${\displaystyle \phi _{2},\lambda _{2}}$ be the geographical latitude and longitude of two points 1 and 2, and ${\displaystyle \Delta \phi ,\Delta \lambda }$ their absolute differences; then ${\displaystyle \Delta \sigma }$, the central angle between them, is given by the spherical law of cosines:

${\displaystyle \Delta \sigma =\arccos {\bigl (}\sin \phi _{1}\cdot \sin \phi _{2}+\cos \phi _{1}\cdot \cos \phi _{2}\cdot \cos(\Delta \lambda ){\bigr )}.}$

The distance d, i.e. the arc length, for a sphere of radius r and ${\displaystyle \Delta \sigma }$ given in radians

${\displaystyle d=r\,\Delta \sigma .}$

### Computational formulas

On computer systems with low floating-point precision, the spherical law of cosines formula can have large rounding errors if the distance is small (if the two points are a kilometer apart on the surface of the Earth, the cosine of the central angle comes out 0.99999999). For modern 64-bit floating-point numbers, the spherical law of cosines formula, given above, does not have serious rounding errors for distances larger than a few meters on the surface of the Earth.[2] The haversine formula is numerically better-conditioned for small distances:[3]

${\displaystyle \Delta \sigma =2\arcsin {\sqrt {\sin ^{2}\left({\frac {\Delta \phi }{2}}\right)+\cos {\phi _{1}}\cdot \cos {\phi _{2}}\cdot \sin ^{2}\left({\frac {\Delta \lambda }{2}}\right)}}.\;\!}$

Historically, the use of this formula was simplified by the availability of tables for the haversine function: hav(θ) = sin2(θ/2).

Although this formula is accurate for most distances on a sphere, it too suffers from rounding errors for the special (and somewhat unusual) case of antipodal points (on opposite ends of the sphere). A more complicated formula that is accurate for all distances is the following special case of the Vincenty formula for an ellipsoid with equal major and minor axes:[4]

${\displaystyle \Delta \sigma =\arctan {\frac {\sqrt {\left(\cos \phi _{2}\cdot \sin(\Delta \lambda )\right)^{2}+\left(\cos \phi _{1}\cdot \sin \phi _{2}-\sin \phi _{1}\cdot \cos \phi _{2}\cdot \cos(\Delta \lambda )\right)^{2}}}{\sin \phi _{1}\cdot \sin \phi _{2}+\cos \phi _{1}\cdot \cos \phi _{2}\cdot \cos(\Delta \lambda )}}.}$

When programming a computer, one should use the atan2() function rather than the ordinary arctangent function (atan()), so that ${\displaystyle \Delta \sigma }$ is placed in the correct quadrant.

The determination of the great-circle distance is just part of the more general problem of great-circle navigation, which also computes the azimuths at the end points and intermediate way-points.

### Vector version

Another representation of similar formulas, but using normal vectors instead of latitude/longitude to describe the positions, is found by means of 3D vector algebra, i.e. utilizing the dot product, cross product, or a combination:[5]

{\displaystyle {\begin{aligned}\Delta \sigma &=\arccos(\mathbf {n} _{1}\cdot \mathbf {n} _{2})\\\Delta \sigma &=\arcsin \left|\mathbf {n} _{1}\times \mathbf {n} _{2}\right|\\\Delta \sigma &=\arctan {\frac {\left|\mathbf {n} _{1}\times \mathbf {n} _{2}\right|}{\mathbf {n} _{1}\cdot \mathbf {n} _{2}}}\\\end{aligned}}\,\!}

where ${\displaystyle \mathbf {n} _{1}}$ and ${\displaystyle \mathbf {n} _{2}}$ are the normals to the ellipsoid at the two positions 1 and 2. Similarly to the equations above based on latitude and longitude, the expression based on arctan is the only one that is well-conditioned for all angles.

### From chord length

A line through three-dimensional space between points of interest on a spherical Earth is the chord of the great circle between the points. The central angle between the two points can be determined from the chord length. The great circle distance is proportional to the central angle.

The great circle chord length, ${\displaystyle C_{h}\,\!}$, may be calculated as follows for the corresponding unit sphere, by means of Cartesian subtraction:

{\displaystyle {\begin{aligned}\Delta {X}&=\cos \phi _{2}\cdot \cos \lambda _{2}-\cos \phi _{1}\cdot \cos \lambda _{1};\\\Delta {Y}&=\cos \phi _{2}\cdot \sin \lambda _{2}-\cos \phi _{1}\cdot \sin \lambda _{1};\\\Delta {Z}&=\sin \phi _{2}-\sin \phi _{1};\\C&={\sqrt {(\Delta {X})^{2}+(\Delta {Y})^{2}+(\Delta {Z})^{2}}}\end{aligned}}}

The central angle is:

${\displaystyle \Delta \sigma =2\arcsin {\frac {C}{2}}.}$

The great circle distance is:

${\displaystyle d=r\Delta \sigma .}$

In this last formula, the central angle must be in radians. Alternatively, when working in nautical miles, the distance may be calculated directly by converting the central angle in degrees to minutes (i.e. multiply by 60).

The shape of the Earth closely resembles a flattened sphere (a spheroid) with equatorial radius ${\displaystyle a}$ of 6378.137 km; distance ${\displaystyle b}$ from the center of the spheroid to each pole is 6356.752 km. When calculating the length of a short north-south line at the equator, the circle that best approximates that line has a radius of ${\displaystyle b^{2}/a}$ (which equals the meridian's semi-latus rectum), or 6335.439 km, while the spheroid at the poles is best approximated by a sphere of radius ${\displaystyle a^{2}/b}$, or 6399.594 km, a 1% difference. So long as we are assuming a spherical Earth, any single formula for distance on the Earth is only guaranteed correct within 0.5% (though we can do better if our formula is only intended to apply to a limited area). A good choice[6] for the radius is the mean earth radius, ${\displaystyle R_{1}={\frac {1}{3}}(2a+b)\approx 6371\,\mathrm {km} }$ (for the WGS84 ellipsoid); in the limit of small flattening, this choice minimizes the mean square relative error in the estimates for distance.