Haversine Formula — Definition, Formula & Example
The haversine formula is a trigonometric formula that gives the shortest distance between two points on a sphere, such as two cities on Earth, using only their latitudes and longitudes. That shortest path follows a great circle, not a straight line on a flat map.
The haversine of an angle is . For points with latitudes and longitudes on a sphere of radius , the central angle between them satisfies , and the great-circle distance is the arc length with in radians.
Key Formula
Where:
- = Great-circle distance between the two points, in the same units as the radius
- = Radius of the sphere; for Earth, about 3,960 miles
- = Latitudes of the first and second points
- = Difference in latitude: second latitude minus first latitude
- = Difference in longitude: second longitude minus first longitude
Worked Example
Problem: Point A is at latitude 0°, longitude 0°. Point B is at latitude 60° N, longitude 90° E. Treat Earth as a sphere with radius r = 3,960 miles. Find the great-circle distance from A to B.
Step 1: Find the differences: the latitude difference is 60° and the longitude difference is 90°. Evaluate the two terms under the square root.
Step 2: Add the terms, take the square root, and find the central angle. The arcsine of the square root of one-half is 45°.
Step 3: Multiply the radius by the central angle in radians to get the arc length.
Answer: The great-circle distance is exactly 1980π miles, or about 6,220 miles. The two points are a quarter of the way around Earth from each other.
Why It Matters
GPS apps, flight-planning software, and shipping logistics use the haversine formula to compute distances between coordinates. Programmers prefer it to the spherical law of cosines because it stays accurate for very short distances. With the cosine version, a computer can lose precision when the cosine of a tiny angle rounds to almost exactly 1.
Common Mistakes
Mistake: Multiplying the radius by the central angle in degrees. In the example above, this gives 3,960 × 90 = 356,400 miles, which is more than Earth's circumference.
Correction: The arc length formula d = rθ requires θ in radians. Convert first: 90° = π/2, so d = 3,960 × π/2 ≈ 6,220 miles.
