HOME

TheInfoList



OR:

The haversine formula determines the
great-circle distance The great-circle distance, orthodromic distance, or spherical distance is the distance along a great circle. It is the shortest distance between two points on the surface of a sphere, measured along the surface of the sphere (as opposed to a ...
between two points on a
sphere A sphere () is a Geometry, geometrical object that is a solid geometry, three-dimensional analogue to a two-dimensional circle. A sphere is the Locus (mathematics), set of points that are all at the same distance from a given point in three ...
given their
longitude Longitude (, ) is a geographic coordinate that specifies the east–west position of a point on the surface of the Earth, or another celestial body. It is an angular measurement, usually expressed in degrees and denoted by the Greek letter l ...
s and
latitude In geography, latitude is a coordinate that specifies the north– south position of a point on the surface of the Earth or another celestial body. Latitude is given as an angle that ranges from –90° at the south pole to 90° at the north pol ...
s. Important in
navigation Navigation is a field of study that focuses on the process of monitoring and controlling the movement of a craft or vehicle from one place to another.Bowditch, 2003:799. The field of navigation includes four general categories: land navigation, ...
, it is a special case of a more general formula in
spherical trigonometry Spherical trigonometry is the branch of spherical geometry that deals with the metrical relationships between the sides and angles of spherical triangles, traditionally expressed using trigonometric functions. On the sphere, geodesics are gr ...
, the law of haversines, that relates the sides and angles of spherical triangles. The first table of haversines in English was published by James Andrew in 1805, but
Florian Cajori Florian Cajori (February 28, 1859 – August 14 or 15, 1930) was a Swiss-American historian of mathematics. Biography Florian Cajori was born in Zillis, Switzerland, as the son of Georg Cajori and Catherine Camenisch. He attended schools first ...
credits an earlier use by
José de Mendoza y Ríos José is a predominantly Spanish and Portuguese form of the given name Joseph. While spelled alike, this name is pronounced differently in each language: Spanish ; Portuguese (or ). In French, the name ''José'', pronounced , is an old vernacul ...
in 1801. (NB. ISBN and link for reprint of second edition by Cosimo, Inc., New York, 2013.) The term ''
haversine The versine or versed sine is a trigonometric function found in some of the earliest (Sanskrit ''Aryabhatia'',James Inman James Inman (1776–1859), an English mathematician and astronomer, was professor of mathematics at the Royal Naval College, Portsmouth, and author of ''Inman's Nautical Tables''. Early years Inman was born at Tod Hole in Garsdale, then in the ...
. (Fourth edition

)
These names follow from the fact that they are customarily written in terms of the haversine function, given by . The formulas could equally be written in terms of any multiple of the haversine, such as the older
versine The versine or versed sine is a trigonometric function found in some of the earliest (Sanskrit Āryabhaṭa's sine table , ''Aryabhatia'',
function (twice the haversine). Prior to the advent of computers, the elimination of division and multiplication by factors of two proved convenient enough that tables of haversine values and
logarithm In mathematics, the logarithm is the inverse function to exponentiation. That means the logarithm of a number  to the base  is the exponent to which must be raised, to produce . For example, since , the ''logarithm base'' 10 o ...
s were included in 19th- and early 20th-century navigation and trigonometric texts.E. R. Hedrick
Logarithmic and Trigonometric Tables
(Macmillan, New York, 1913).
These days, the haversine form is also convenient in that it has no coefficient in front of the function.


Formulation

Let the
central angle A central angle is an angle whose apex (vertex) is the center O of a circle and whose legs (sides) are radii intersecting the circle in two distinct points A and B. Central angles are subtended by an arc between those two points, and the arc le ...
between any two points on a sphere be: :\theta = \frac where: * is the distance between the two points along a
great circle In mathematics, a great circle or orthodrome is the circular intersection of a sphere and a plane passing through the sphere's center point. Any arc of a great circle is a geodesic of the sphere, so that great circles in spherical geomet ...
of the sphere (see
spherical distance The great-circle distance, orthodromic distance, or spherical distance is the distance along a great circle. It is the shortest distance between two points on the surface of a sphere, measured along the surface of the sphere (as opposed to a s ...
), * is the radius of the sphere. The ''haversine formula'' allows the
haversine The versine or versed sine is a trigonometric function found in some of the earliest (Sanskrit ''Aryabhatia'',haversine function The versine or versed sine is a trigonometric function found in some of the earliest (Sanskrit Āryabhaṭa's sine table , ''Aryabhatia'',
, applied above to both the central angle and the differences in latitude and longitude, is : \operatorname(\theta) = \sin^2\left(\frac\right) = \frac The haversine function computes half a
versine The versine or versed sine is a trigonometric function found in some of the earliest (Sanskrit Āryabhaṭa's sine table , ''Aryabhatia'',
of the angle . To solve for the distance , apply the archaversine (
inverse haversine The versine or versed sine is a trigonometric function found in some of the earliest (Sanskrit Āryabhaṭa's sine table , ''Aryabhatia'',
) to or use the
arcsine In mathematics, the inverse trigonometric functions (occasionally also called arcus functions, antitrigonometric functions or cyclometric functions) are the inverse functions of the trigonometric functions (with suitably restricted domains). Spec ...
(inverse sine) function: : d = r\operatorname(h) = 2r\arcsin\left(\sqrt\right) or more explicitly: : \begin d &= 2r \arcsin\left(\sqrt\right) \\ &= 2r \arcsin\left(\sqrt\right) \\ &= 2r \arcsin\left(\sqrt\right). \end When using these formulae, one must ensure that does not exceed 1 due to a
floating point In computing, floating-point arithmetic (FP) is arithmetic that represents real numbers approximately, using an integer with a fixed precision, called the significand, scaled by an integer exponent of a fixed base. For example, 12.345 can be ...
error ( is only
real Real may refer to: Currencies * Brazilian real (R$) * Central American Republic real * Mexican real * Portuguese real * Spanish real * Spanish colonial real Music Albums * ''Real'' (L'Arc-en-Ciel album) (2000) * ''Real'' (Bright album) (2010) ...
for ). only approaches 1 for ''antipodal'' points (on opposite sides of the sphere)—in this region, relatively large numerical errors tend to arise in the formula when finite precision is used. Because is then large (approaching , half the circumference) a small error is often not a major concern in this unusual case (although there are other
great-circle distance The great-circle distance, orthodromic distance, or spherical distance is the distance along a great circle. It is the shortest distance between two points on the surface of a sphere, measured along the surface of the sphere (as opposed to a ...
formulas that avoid this problem). (The formula above is sometimes written in terms of the
arctangent In mathematics, the inverse trigonometric functions (occasionally also called arcus functions, antitrigonometric functions or cyclometric functions) are the inverse functions of the trigonometric functions (with suitably restricted domains). Spec ...
function, but this suffers from similar numerical problems near .) As described below, a similar formula can be written using cosines (sometimes called the
spherical law of cosines In spherical trigonometry, the law of cosines (also called the cosine rule for sides) is a theorem relating the sides and angles of spherical triangles, analogous to the ordinary law of cosines from plane trigonometry. Given a unit sphere, a "sphe ...
, not to be confused with the
law of cosines In trigonometry, the law of cosines (also known as the cosine formula, cosine rule, or al-Kashi's theorem) relates the lengths of the sides of a triangle to the cosine of one of its angles. Using notation as in Fig. 1, the law of cosines states ...
for plane geometry) instead of haversines, but if the two points are close together (e.g. a kilometer apart, on the Earth) one might end up with , leading to an inaccurate answer. Since the haversine formula uses sines, it avoids that problem. Either formula is only an approximation when applied to the
Earth Earth is the third planet from the Sun and the only astronomical object known to harbor life. While large volumes of water can be found throughout the Solar System, only Earth sustains liquid surface water. About 71% of Earth's surfa ...
, which is not a perfect sphere: the "
Earth radius Earth radius (denoted as ''R''🜨 or R_E) is the distance from the center of Earth to a point on or near its surface. Approximating the figure of Earth by an Earth spheroid, the radius ranges from a maximum of nearly (equatorial radius, deno ...
" varies from 6356.752 km at the poles to 6378.137 km at the equator. More importantly, the
radius of curvature In differential geometry, the radius of curvature, , is the reciprocal of the curvature. For a curve, it equals the radius of the circular arc which best approximates the curve at that point. For surfaces, the radius of curvature is the radius o ...
of a north-south line on the earth's surface is 1% greater at the poles (≈6399.594 km) than at the equator (≈6335.439 km)—so the haversine formula and law of cosines cannot be guaranteed correct to better than 0.5%. More accurate methods that consider the Earth's ellipticity are given by
Vincenty's formulae 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 ...
and the other formulas in the
geographical distance Geographical distance or geodetic distance is the distance measured along the surface of the earth. The formulae in this article calculate distances between points which are defined by geographical coordinates in terms of latitude and longitude. ...
article.


The law of haversines

Given a unit sphere, a "triangle" on the surface of the sphere is defined by the
great circle In mathematics, a great circle or orthodrome is the circular intersection of a sphere and a plane passing through the sphere's center point. Any arc of a great circle is a geodesic of the sphere, so that great circles in spherical geomet ...
s connecting three points , , and on the sphere. If the lengths of these three sides are (from to ), (from to ), and (from to ), and the angle of the corner opposite is , then the law of haversines states: : \operatorname(c) = \operatorname(a - b) + \sin(a)\sin(b)\operatorname(C). Since this is a unit sphere, the lengths , , and are simply equal to the angles (in
radian The radian, denoted by the symbol rad, is the unit of angle in the International System of Units (SI) and is the standard unit of angular measure used in many areas of mathematics. The unit was formerly an SI supplementary unit (before that c ...
s) subtended by those sides from the center of the sphere (for a non-unit sphere, each of these arc lengths is equal to its
central angle A central angle is an angle whose apex (vertex) is the center O of a circle and whose legs (sides) are radii intersecting the circle in two distinct points A and B. Central angles are subtended by an arc between those two points, and the arc le ...
multiplied by the radius of the sphere). In order to obtain the haversine formula of the previous section from this law, one simply considers the special case where is the
north pole The North Pole, also known as the Geographic North Pole or Terrestrial North Pole, is the point in the Northern Hemisphere where the Earth's axis of rotation meets its surface. It is called the True North Pole to distinguish from the Mag ...
, while and are the two points whose separation is to be determined. In that case, and are (that is, the, co-latitudes), is the longitude separation , and is the desired . Noting that , the haversine formula immediately follows. To derive the law of haversines, one starts with the
spherical law of cosines In spherical trigonometry, the law of cosines (also called the cosine rule for sides) is a theorem relating the sides and angles of spherical triangles, analogous to the ordinary law of cosines from plane trigonometry. Given a unit sphere, a "sphe ...
: :\cos(c) = \cos(a)\cos(b) + \sin(a)\sin(b)\cos(C). \, As mentioned above, this formula is an ill-conditioned way of solving for when is small. Instead, we substitute the identity that , and also employ the addition identity , to obtain the law of haversines, above.


Proof

One can prove the formula: : \operatorname\left(\theta\right) = \operatorname\left(\varphi_2 - \varphi_1\right) + \cos\left(\varphi_1\right)\cos\left(\varphi_2\right)\operatorname\left(\lambda_2 - \lambda_1\right) by transforming the points given by their latitude and longitude into
cartesian coordinates A Cartesian coordinate system (, ) in a plane is a coordinate system that specifies each point uniquely by a pair of numerical coordinates, which are the signed distances to the point from two fixed perpendicular oriented lines, measured in t ...
, then taking their
dot product In mathematics, the dot product or scalar productThe term ''scalar product'' means literally "product with a scalar as a result". It is also used sometimes for other symmetric bilinear forms, for example in a pseudo-Euclidean space. is an algebra ...
. Consider two points \bf p_1,p_2 on the
unit sphere In mathematics, a unit sphere is simply a sphere of radius one around a given center. More generally, it is the set of points of distance 1 from a fixed central point, where different norms can be used as general notions of "distance". A unit b ...
, given by their latitude \varphi and longitude \lambda: :\begin &= (\lambda_2, \varphi_2) \\ &= (\lambda_1, \varphi_1) \end These representations are very similar to
spherical coordinates In mathematics, a spherical coordinate system is a coordinate system for three-dimensional space where the position of a point is specified by three numbers: the ''radial distance'' of that point from a fixed origin, its ''polar angle'' measu ...
, however latitude is measured as angle from the equator and not the north pole. These points have the following representations in cartesian coordinates: :\begin &= (\cos(\lambda_2)\cos(\varphi_2), \;\sin(\lambda_2)\cos(\varphi_2), \;\sin(\varphi_2)) \\ &= (\cos(\lambda_1)\cos(\varphi_1), \;\sin(\lambda_1)\cos(\varphi_1), \;\sin(\varphi_1)) \end From here we could directly attempt to calculate the dot product and proceed, however the formulas become significantly simpler when we consider the following fact: the distance between the two points will not change if we rotate the sphere along the z-axis. This will in effect add a constant to \lambda_1, \lambda_2. Note that similar considerations do not apply to transforming the latitudes - adding a constant to the latitudes may change the distance between the points. By choosing our constant to be -\lambda_1, and setting \lambda' = \lambda_2 - \lambda_1, our new points become: :\begin &= (\cos(\lambda')\cos(\varphi_2), \;\sin(\lambda')\cos(\varphi_2), \;\sin(\varphi_2)) \\ &= (\cos(0)\cos(\varphi_1), \;\sin(0)\cos(\varphi_1), \;\sin(\varphi_1)) \\ &= (\cos(\varphi_1), \;0, \;\sin(\varphi_1)) \end With \theta denoting the angle between and , we now have that: :\begin \cos(\theta) &= \langle,\rangle = \langle,\rangle = \cos(\lambda')\cos(\varphi_1)\cos(\varphi_2) + \sin(\varphi_1)\sin(\varphi_2) \\ &= \sin(\varphi_2)\sin(\varphi_1) + \cos(\varphi_2)\cos(\varphi_1) - \cos(\varphi_2)\cos(\varphi_1) + \cos(\lambda')\cos(\varphi_2)\cos(\varphi_1) \\ &= \cos(\varphi_2 - \varphi_1) + \cos(\varphi_2)\cos(\varphi_1)(-1 + \cos(\lambda')) \Rightarrow \\ \operatorname\left(\theta\right) &= \operatorname\left(\varphi_2 - \varphi_1 \right) + \cos(\varphi_2)\cos(\varphi_1)\operatorname\left(\lambda_2 - \lambda_1 \right) \end


See also

*
Sight reduction In astronavigation, sight reduction is the process of deriving from a sight, (in celestial navigation usually obtained using a sextant), the information needed for establishing a line of position, generally by intercept method. Sight is defined as ...
*
Vincenty's formulae 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 ...


References


Further reading

*
U. S. Census Bureau The United States Census Bureau (USCB), officially the Bureau of the Census, is a principal agency of the Federal Statistical System of the United States, U.S. Federal Statistical System, responsible for producing data about the Americans, Ame ...
Geographic Information Systems FAQ, (content has been moved t
What is the best way to calculate the distance between 2 points?
* R. W. Sinnott, "Virtues of the Haversine", ''Sky and Telescope'' 68 (2), 159 (1984).

''Ask Dr. Math'' (Apr. 20–21, 1999). {{webarchive , url=https://web.archive.org/web/20200120134215/http://mathforum.org/library/drmath/view/51879.html , date=20 January 2020 * Romuald Ireneus 'Scibor-Marchocki

''Elementary-Geometry Trigonometry'' web page (1997). * W. Gellert, S. Gottwald, M. Hellwich, H. Kästner, and H. Küstner, ''The VNR Concise Encyclopedia of Mathematics'', 2nd ed., ch. 12 (Van Nostrand Reinhold: New York, 1989).


External links

* Implementations of the haversine formul
in 91 languages at rosettacode.org
an
in 17 languages on codecodex.com
* Other implementations i
C (MacOS)PythonRuby PHPMatlabMySQL
Spherical trigonometry Geodesy Distance