Skip to content

Haversine Formula

A half-angle spherical-trigonometry relation that converts two latitude–longitude positions into their central angle and great-circle arc distance, with explicit radius, angle-unit, and numerical-boundary controls.

Version
v4 · 2026-09-19 · History
Domain-specific #
1988
Domain group
Formal Sciences
Origin domain
Mathematics
Subdomains
Spherical Trigonometry, Great Circle Distance Computation → Mathematics
Aliases
Great-circle haversine formula

Core Idea

The haversine formula converts the latitude and longitude of two points on a sphere into their central angle and hence the length of the shorter great-circle arc between them. It does so through the half-angle function

\[ \operatorname{hav}(x)=\sin^2\!\left(\frac{x}{2}\right)=\frac{1-\cos x}{2}. \]

For latitudes \(\varphi_1,\varphi_2\), longitude difference \(\Delta\lambda\), and sphere radius \(R\), form

\[ a=\sin^2\!\left(\frac{\varphi_2-\varphi_1}{2}\right) +\cos\varphi_1\cos\varphi_2 \sin^2\!\left(\frac{\Delta\lambda}{2}\right), \]

How would you explain it like I'm…

String-on-a-Ball Distance

Imagine two ants on a big round ball, and you want to know how far one ant must walk to reach the other along the ball's skin. The Haversine Formula is a recipe that uses where each ant is to tell you that shortest walking distance. People use it for places on Earth by pretending Earth is a perfect ball.

Globe Distance Recipe

Places on Earth are given by latitude (how far north or south) and longitude (how far east or west). If you treat Earth as a perfect ball, the shortest path between two places along the surface is part of a "great circle," a circle as big as the ball itself. The Haversine Formula takes the two places' coordinates and gives the angle between them as seen from the ball's center. Multiply that angle by the ball's radius and you get the distance. Earth isn't a perfect ball, so the answer is an approximation for the real Earth.

Half-Angle Great-Circle Distance

The Haversine Formula computes the great-circle distance between two points on a sphere from their latitudes and longitudes. It uses the haversine function, hav(x) = sin²(x/2) = (1 − cos x)/2. You compute a = sin²(Δφ/2) + cos φ₁ · cos φ₂ · sin²(Δλ/2), where Δφ is the latitude difference and Δλ is the longitude difference. The central angle is δ = 2·atan2(√a, √(1−a)), and the distance is d = Rδ. Another approach applies arccos to a cosine, but for two very close points that cosine is nearly 1 and rounding errors wreck the answer. The half-angle form avoids that problem. The result is exact for a perfect sphere, so any error from Earth not being a sphere is separate from the arithmetic.

 

The Haversine Formula computes the central angle between two points on a sphere from their coordinates, and hence the length of the shorter great-circle arc. With hav(x) = sin²(x/2) = (1 − cos x)/2, it forms a = sin²((φ₂ − φ₁)/2) + cos φ₁ cos φ₂ sin²(Δλ/2). It then recovers δ = 2 atan2(√a, √(1−a)) and returns d = Rδ. Equivalently δ = 2 arcsin √a for 0 ≤ a ≤ 1, but atan2 makes the numerator, denominator and range explicit. A correct implementation binds the coordinates to one reference sphere, converts units consistently, and normalizes Δλ. It also clamps floating-point drift so a stays in [0,1], ensuring the principal angle lies in [0, π]. On the assumed sphere, the result is exactly the metric distance along a shortest arc. When the sphere models Earth, that model error is separate from arithmetic error. Its main numerical advantage is that accumulating half-angle terms avoids the precision loss of taking arccos of a cosine near one for tiny separations.

Scope of Application

Literal uses arise whenever positions are represented on a sphere and a scalar shortest surface separation is required: celestial angular separation, idealized planetary or stellar surfaces, introductory great-circle navigation, rapid geographic proximity screening, database measurements under a declared spherical Earth option, simulation on spherical meshes, and validation fixtures for more elaborate geospatial systems.

The formula is often an appropriate approximation when application tolerances dominate Earth-figure error, when inputs are coarse, or when a fast preliminary filter will later hand close cases to an ellipsoidal solver. PostGIS exposes this decision explicitly: its spherical-distance operation is faster but less accurate than its spheroidal counterpart.

Clarity

A reader should be able to audit a Haversine calculation by answering eight questions:

  1. Are the two positions latitude–longitude pairs on the same reference surface and datum?
  2. Are all trigonometric inputs in radians, or is conversion performed before evaluation?
  3. How is longitude difference wrapped across the antimeridian?
  4. Which radius is used, in what units, and why is that radius appropriate?

Manages Complexity

The formula compresses a three-dimensional shortest-path problem on a sphere into a fixed scalar pipeline: coordinate differences, two squared half-angle terms, inverse-haversine recovery, and radius scaling. The practitioner need not construct planes through the sphere's center, calculate Cartesian radius vectors, identify their great circle, or integrate an arc for every pair.

Abstract Reasoning

The point-pair relation is a specialization of spherical trigonometry. If the north pole and the two positions form a spherical triangle, the included angle at the pole is \(\Delta\lambda\), the relevant side lengths are related to the co-latitudes, and rearranging the spherical law of cosines with \(1-\cos x=2\sin^2(x/2)\) yields the haversine form.

Knowledge Transfer

The formula transfers literally across practices that share spherical angular coordinates and great-circle separation. A navigator comparing waypoints, an astronomer measuring angular separation after converting coordinates to a common spherical frame, and a simulation measuring nodes on a spherical shell instantiate the same roles. Only the radius, coordinate frame, and acceptable approximation change.

It also transfers as a software contract. A geospatial database, scientific library, embedded navigation routine, or spreadsheet can expose the same inputs, central-angle intermediate, radius policy, and error boundaries.

Relationships to Other Abstractions

Local relationship map for Haversine FormulaParents appear above the current abstraction, mutual partners to the right, and children below. Node labels state whether each abstraction is prime or domain-specific; colors identify relation types.Haversine FormulaDOMAINPrime abstraction: Metric — is a kind ofMetricPRIME

Current abstraction Haversine Formula Domain-specific

Parents (1) — outgoing typed relations

  • Haversine Formula is a kind of Metric Prime

    The formula specializes Metric: its output is the geodesic distance on a sphere expressed through one coordinate relation.

Hierarchy path (1) — routes to 1 parentless root

Neighborhood in Abstraction Space

Haversine Formula sits in a sparse region of the domain-specific corpus (75th percentile for distinctiveness): few abstractions share its structure, so a faithful description tends to retrieve it precisely.

Family — Unclustered & Miscellaneous (2769 abstractions)

Nearest neighbors

Computed from structural-signature embeddings · 2026-10-25