ArticleslgStudy

mathematics

Haversine formula

Haversine formula is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Haversine formula rather than just read about it. In short: The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes. Important in navigation, it is a special case of a more general formula in spherical trigonometry, the law of haversines, that relates the sides and angles of spherical triangles.

Haversine formula — main illustration
Haversine formula — illustration

Key takeaways

  • Haversine formula belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Haversine formula to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Haversine formula from memory before moving on to harder problems.

Reference excerpt

The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes. Important in navigation, it is a special case of a more general formula in spherical trigonometry, 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 credits an earlier use by José de Mendoza y Ríos in 1801. The term haversine was coined in 1835 by James Inman, a contraction of "half-versed sine". These names follow from the fact that they are customarily written in terms of the haversine function, given by hav θ = sin2 ⁠1/2⁠θ. The formulas could equally be written in terms of any multiple of the haversine, such as the older versine 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 logarithms were included in 19th- and early 20th-century navigation and trigonometric texts. These days, the haversine form is also convenient in that it has no coefficient in front of the sin2 function.

The formula is contrasted with spherical law of cosines, which is theoretically equivalent, however.

Formulation The basic relation is shown by d=rθ, where

θ is the central angle between any two points on a sphere, d is the distance between the two points along a great circle of the sphere (see spherical distance), r is the radius of the sphere. The haversine formula allows the haversine of θ to be computed directly from the latitude (represented by φ) and longitude (represented by λ) of the two points: hav⁡θ=hav⁡(Δφ)+cos⁡(φ1)cos⁡(φ2)hav⁡(Δλ) where

φ1, φ2 are the latitude of point 1 and latitude of point 2, λ1, λ2 are the longitude of point 1 and longitude of point 2, Δφ=φ2−φ1, Δλ=λ2−λ1. The haversine function computes half a versine of the angle θ, or the squares of half chord of the angle on a unit circle (sphere). It is related to other sinusoidal functions: hav⁡θ=sin2(θ2)=1−cos⁡(θ)2. To solve for θ from the differences in latitude and longitude explicitly: θ=2arcsin⁡(hav⁡θ), where hav⁡θ can be calculated by: hav⁡θ=hav⁡(Δφ)+cos⁡(φ1)cos⁡(φ2)hav⁡(Δλ)=hav⁡(Δφ)+(1−hav⁡(Δφ)−hav⁡(2φm))⋅hav⁡(Δλ)=sin2(Δφ2)+(1−sin2(Δφ2)−sin2(φm))⋅sin2(Δλ2)=sin2(Δφ2)+cos⁡φ1⋅cos⁡φ2⋅sin2(Δλ2)=sin2(Δφ2)⋅cos2(Δλ2)+cos2(φm)⋅sin2(Δλ2)=1−cos⁡(Δφ)+cos⁡φ1⋅cos⁡φ2⋅(1−cos⁡(Δλ))2 and φm=φ2+φ12. When using these formulae, one must ensure that h = hav(θ) does not exceed 1 due to a floating point error (d is real only for 0 ≤ h ≤ 1). h 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 d is then large (approaching πR, half the circumference) a small error is often not a major concern in this unusual case (although there are other great-circle distance formulas that avoid this problem). (The formula above is sometimes written in terms of the arctangent function, but this suffers from similar numerical problems near h = 1.) As described below, a similar formula can be written using cosines (sometimes called the spherical law of cosines, not to be confused with the law of cosines 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 cos(⁠d/R⁠) = 0.99999999, 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, which is not a perfect sphere: the "Earth radius" R varies from 6356.752 km at the poles to 6378.137 km at the equator. More importantly, the radius of curvature 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 and the other formulas in the geographical distance article.

The law of haversines

Given a unit sphere, a "triangle" on the surface of the sphere is defined by the great circles connecting three points u, v, and w on the sphere. If the lengths of these three sides are a (from u to v), b (from u to w), and c (from v to w), and the angle of the corner opposite c is C, then the law of haversines states: hav⁡(c)=hav⁡(a−b)+sin⁡(a)sin⁡(b)hav⁡(C). Since this is a unit sphere, the lengths a, b, and c are simply equal to the angles (in radians) 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 multiplied by the radius R of the sphere). In order to obtain the haversine formula of the previous section from this law, one simply considers the special case where u is the north pole, while v and w are the two points whose separation d is to be determined. In that case, a and b are ⁠π/2⁠ − φ1,2 (that is, the, co-latitudes), C is the longitude separation λ2 − λ1, and c is the desired ⁠d/R⁠. Noting that sin(⁠π/2⁠ − φ) = cos(φ), the haversine formula immediately follows. To derive the law of haversines, one starts with the spherical law of cosines: 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 c when c is small. Instead, we substitute the identity that cos(θ) = 1 − 2 hav(θ), and also employ the addition identity cos(a − b) = cos(a) cos(b) + sin(a) sin(b), to obtain the law of haversines, above.

… excerpt ends here. Continue reading the full article.

Illustrations

Haversine formula: 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 shown.
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 shown.
Haversine formula: Spherical triangle solved by the law of haversines
Spherical triangle solved by the law of haversines
Haversine formula: A geodesic (red) connecting Washington, D.C. to Paris, plotted on the two-point equidistant projection, with geodesic circles (blue) at multiples of 1,000 km distance from Washington.
A geodesic (red) connecting Washington, D.C. to Paris, plotted on the two-point equidistant projection, with geodesic circles (blue) at multiples of 1,000 km distance from Washington.

Worked examples

Example 1 — a first encounter with Haversine formula

Start with the simplest possible case. Write down what Haversine formula claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Haversine formula before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Haversine formula ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Haversine formula

In research
Haversine formula appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Haversine formula in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Haversine formula is common in secondary-school and first-year university syllabi. It links to neighbouring topics Distance, Geodesy, Spherical trigonometry, so understanding it makes those chapters shorter.
In everyday life
Look for Haversine formula outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Haversine formula” →

How to study Haversine formula in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Haversine formula means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Haversine formula out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Haversine formula in simple terms?

The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes. Important in navigation, it is a special case of a more general formula in spherical trigonometry, the law of haversines, that relates the sides and angles of spherical tr…

Why does Haversine formula matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Haversine formula?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Haversine formula.

Tags

  • Distance
  • Geodesy
  • Spherical trigonometry

Keep exploring