Great-Circle Distance

The simplest way to compute the great-circle distance is to use the spherical law of cosines. Unfortunately, this is ill-conditioned for small distances due to rounding errors. For example, if two points are 1km apart, the cosine of the central angle is 0.99999999.

A better formula is known as the haversine formula, which is better-conditioned for all distances except for those close to 180°.

Even better, a special case of Vincenty’s formula is accurate for all distances.

To compare these formulæ, I computed distances along the equator, for which the expected distance is simple to derive.

As you can see, the error is still pretty small, thanks to double-precision floating point!

Distances close to 0°

Distances close to 180°

Distances in the second set of charts are relative to 180°.

Distances are shown in metres on Earth, assuming a radius of 6,371km.