Great-circle distance and the haversine formula
Why does a flight from New York to London head north-east over Newfoundland instead of straight east, as the map seems to suggest? Because the Earth is round, and the shortest way between two places on a sphere is an arc of a great circle. This page explains what great circles are, how latitude and longitude turn two places into a triangle with the pole, and how the haversine formula turns that triangle into a distance, with New York to London worked out by hand.
Great circles: the straight lines of a sphere
On a flat surface the shortest way between two points is a straight line. On a sphere there are no straight lines on the surface; their place is taken by great circles, the circles whose centre is the centre of the sphere. Every plane through the centre cuts the surface in one: the equator and all meridians are great circles, the other circles of latitude are not. Two places that are not exactly opposite each other lie on just one great circle, and the shorter arc between them is the shortest way over the surface. A string stretched tight between two points on a globe lies along it.
Latitude and longitude are angles
The latitude φ of a place is the angle between the equator's plane and the line from the centre of the Earth to the place: 0° on the equator, 90° at the poles, positive in the north. The longitude λ is the angle around the axis from the meridian of Greenwich, positive to the east. New York lies at about 40.71° N, 74.01° W (φ = 40.71°, λ = −74.01°) and London at 51.51° N, 0.13° W. Because both are angles at the centre, the distance between two places comes down to one more angle at the centre: the central angle Δσ between their radii. The distance is then the arc length d = R · Δσ, with Δσ in radians.
The triangle with the pole
To find Δσ, draw the meridians from both places to the North Pole. Together with the great-circle arc between the places they make a spherical triangle, with sides that are arcs of great circles. The side from the pole to a place is its colatitude, 90° − φ, and the angle at the pole between the two meridians is the difference in longitude Δλ = λ₂ − λ₁. Two sides and the angle between them fix a triangle, on a sphere as on a plane. For places in the southern hemisphere the South Pole works the same way, with sides 90° + φ.
The spherical law of cosines
The plane law of cosines, c² = a² + b² − 2ab cos C, has a spherical version for a triangle with sides a, b, c (as angles) and angle C opposite c: cos c = cos a cos b + sin a sin b cos C. With a = 90° − φ₁, b = 90° − φ₂ and C = Δλ it becomes cos Δσ = sin φ₁ sin φ₂ + cos φ₁ cos φ₂ cos Δλ. It is exact, and it can be proved with vectors: the dot product of the two unit vectors from the centre to the places is cos Δσ, and writing them out in latitude and longitude gives the same right-hand side.
Why haversines?
For places close together cos Δσ is very nearly 1, and the arccosine of a number like 0.99999999 loses most of its digits in a computer or a book of tables: two places 100 m apart can come out as 0 m or 300 m. Navigators therefore used the haversine, hav θ = sin²(θ/2) = (1 − cos θ)/2, which is small for small angles and keeps its precision. Replacing each cosine by 1 − 2 hav turns the law of cosines into hav Δσ = hav Δφ + cos φ₁ cos φ₂ hav Δλ, the haversine formula. Solved for the distance: d = 2R · arcsin √(sin²(Δφ/2) + cos φ₁ · cos φ₂ · sin²(Δλ/2)).
New York to London by hand
Δφ = 51.51° − 40.71° = 10.79° and Δλ = −0.13° − (−74.01°) = 73.88°. Then sin²(5.40°) = 0.00885, cos 40.71° · cos 51.51° = 0.758 · 0.622 = 0.472 and sin²(36.94°) = 0.361, so a = 0.00885 + 0.472 · 0.361 = 0.179. Its square root is 0.423, the arcsine 25.05°, so Δσ = 50.09° = 0.874 rad. With R = 6,371 km the distance is 6,371 × 0.874 ≈ 5,570 km, or 3,461 miles. The square root of a also has a meaning: the straight chord through the Earth between the cities is 2R √a ≈ 5,395 km, about 175 km shorter than the arc.
Heading, great circles and rhumb lines
Along a great circle the compass heading changes all the time. The initial heading from place 1 to place 2 is θ = atan2(sin Δλ cos φ₂, cos φ₁ sin φ₂ − sin φ₁ cos φ₂ cos Δλ): about 51° (north-east) from New York, while the plane arrives in London heading about 108°. The route that keeps one heading is the rhumb line, or loxodrome, which crosses every meridian at the same angle; on a Mercator map it is straight. It is easier to steer but always longer, about 5,790 km from New York to London, and much longer for long routes at high latitudes. Ships and planes follow the great circle and change heading as they go.
How round is the Earth?
The Earth is an ellipsoid, flattened by its rotation: the radius is 6,378 km at the equator and 6,357 km at the poles. The haversine formula with the mean radius of 6,371 km is therefore off by up to about 0.5 %, a few kilometres on a long flight, which is plenty for planning and teaching. Geodesy uses the formulas of Vincenty (1975) or Karney (2013) on the WGS 84 ellipsoid, which agree with the real shortest paths to within millimetres. The same haversine formula works for the Moon (R = 1,737 km), Mars (R = 3,390 km) or any other sphere.
How the app works it out
The app keeps both places as unit vectors from the centre of the sphere and the great circle as the plane through them, so it can draw the arc, the whole circle, the radii and the chord exactly. It computes Δφ, Δλ, a, Δσ and d with the haversine formula and checks them against the law of cosines, plays the steps as a timeline of seconds (the places, the triangle with the pole, the central angle and the flight), and draws the Earth pixel by pixel from a map of land and sea in an orthographic view seen from just beside the great circle's plane, so the arc, the chord and the radii do not fall on one line.
Frequently asked questions
What is the difference between the haversine formula and the law of cosines?
None in exact arithmetic: they are the same relation, written with haversines instead of cosines. In practice the haversine form is better for short distances, where the law of cosines takes the arccosine of a number very close to 1 and loses precision. For places almost opposite each other the haversine form takes the arcsine of a number close to 1, but that matters only within a few kilometres of the antipode.
Why is the haversine called that?
It is the half versed sine. The versed sine, versin θ = 1 − cos θ, was used in tables since the Middle Ages; half of it, sin²(θ/2), was tabulated in the 19th century for navigators, who could then work out great-circle distances from logarithm tables without subtracting numbers close to each other. The name haversine was coined by James Inman in 1835.
Which radius should I use for the Earth?
The mean radius, 6,371.0 km (3,958.8 miles), defined by the International Union of Geodesy and Geophysics as the average of the three axes of the ellipsoid. It gives the smallest errors on average. Some calculators use 6,378 km, the equatorial radius, which makes all distances about 0.1 % longer.
What is the longest possible distance on the Earth?
Half a great circle, π × 6,371 ≈ 20,015 km, between two antipodes, places exactly opposite each other. There every great circle through the two points has the same length, so there is no single shortest route. Madrid and Wellington in New Zealand are nearly antipodal.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Open the distance on a sphere app