Haversine Formula - The Haversine Formula

The Haversine Formula

For any two points on a sphere, the haversine of the central angle between them is given by

where

  • haversin is the haversine function:
  • d is the distance between the two points (along a great circle of the sphere; see spherical distance),
  • r is the radius of the sphere,
  • : latitude of point 1 and latitude of point 2
  • : longitude of point 1 and longitude of point 2

On the left side of the equals sign d/r is the central angle, assuming angles are measured in in radians (note that φ and λ can be converted from degrees to radians by multiplying by π/180 as usual).

Solve for d by applying the inverse haversine (if available) or by using the arcsine (inverse sine) function:

where h is haversin(d/r), or more explicitly:

In the era before the digital calculator, printed tables for the haversine/inverse-haversine and its logarithm (to aid multiplications) saved navigators from squaring sines, computing square roots, etc., an arduous process and likely to exacerbate small errors (see also versine).

When using these formulae, ensure that h does not exceed 1 due to a floating point error (d is only real for h from 0 to 1). h only approaches 1 for antipodal points (on opposite sides of the sphere) — in this region, relatively large numerical errors tend to arise in the formula when finite precision is used. Because d is then large (approaching πR, half the circumference) a small error is often not a major concern in this unusual case (although there are other great-circle distance formulas that avoid this problem). (The formula above is sometimes written in terms of the arctangent function, but this suffers from similar numerical problems near h = 1.)

As described below, a similar formula can be written using cosines (sometimes called the spherical law of cosines, not to be confused with the law of cosines for plane geometry) instead of haversines, but if the two points are close together (e.g. a kilometer apart, on the Earth) you might end up with cos (d/R) = 0.99999999, leading to an inaccurate answer. Since the haversine formula uses sines it avoids that problem.

Either formula is only an approximation when applied to the Earth, which is not a perfect sphere: the "Earth radius" R varies from 6356.78 km at the poles to 6378.14 km at the equator. More importantly, the radius of curvature of a north-south line on the earth's surface is 1% greater at the poles than at the equator— so the haversine formula and law of cosines can't be guaranteed correct to better than 0.5%. More accurate methods that consider the Earth's ellipticity are given by Vincenty's formulae and the other formulas in the geographical distance article.

Read more about this topic:  Haversine Formula

Famous quotes containing the word formula:

    “It’s hard enough to adjust [to the lack of control] in the beginning,” says a corporate vice president and single mother. “But then you realize that everything keeps changing, so you never regain control. I was just learning to take care of the belly-button stump, when it fell off. I had just learned to make formula really efficiently, when Sarah stopped using it.”
    Anne C. Weisberg (20th century)