Great-circle distance


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. 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 spaces with curvature, straight lines are replaced by geodesics. Geodesics on the sphere are circles on the sphere whose centers coincide with the center of the sphere, and are called great circles.
The determination of the great-circle distance is part of the more general problem of great-circle navigation, which also computes the azimuths at the end points and intermediate way-points.
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 called a Riemannian circle in Riemannian geometry.
Between two points that are directly opposite each other, called antipodal points, there are infinitely many great circles, and all great circle arcs between antipodal points have a length of half the circumference of the circle, or, where r is the radius of the sphere.
The Earth is nearly spherical, so great-circle distance formulas give the distance between points on the surface of the Earth correct to within about 0.5%.

Formulae

Let and be the geographical longitude and latitude in radians of two points 1 and 2, and be their absolute differences; then, the central angle between them, is given by the spherical law of cosines if one of the poles is used as an auxiliary third point on the sphere:
The problem is normally expressed in terms of finding the central angle. Given this angle in radians, the actual arc length d on a sphere of radius r can be trivially computed as

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. 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. The haversine formula is numerically better-conditioned for small distances:
Historically, the use of this formula was simplified by the availability of tables for the haversine function: hav = sin2.
Although this formula is accurate for most distances on a sphere, it too suffers from rounding errors for the special case of antipodal points. A 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:

Vector version

Another representation of similar formulas, but using normal vectors instead of latitude and longitude to describe the positions, is found by means of 3D vector algebra, using the dot product, cross product, or a combination:
where and 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. The expression based on arctan requires the magnitude of the cross product over the dot product.

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,, may be calculated as follows for the corresponding unit sphere, by means of Cartesian subtraction:
The central angle is:

Radius for spherical Earth

The shape of the Earth closely resembles a flattened sphere with equatorial radius of 6378.137 km; distance 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 , or 6335.439 km, while the spheroid at the poles is best approximated by a sphere of radius, or 6399.594 km, a 1% difference. So long as a spherical Earth is assumed, any single formula for distance on the Earth is only guaranteed correct within 0.5%. Using the mean earth radius, means that in the limit of small flattening, the mean square relative error in the estimates for distance is minimized.