The Haversine Formula
Compute the great-circle distance between two points on a spherical Earth using the haversine function and the Haversine formula. Includes sign conventions for latitude/longitude and unit handling for kilometers and nautical miles.
Step 1 of 157%
Tutorial
The Haversine Function
To compute great-circle distances on a sphere cleanly, we use the haversine function, defined for any angle as
The two forms are equivalent via the half-angle identity. The haversine is non-negative, equals at and grows to at It is also an even function:
For example,
The haversine is the building block of the Haversine formula for great-circle distance. It is preferred over the law-of-cosines formula because it remains numerically stable for points that are close together on the sphere.