Method Deck / astronomy

Great-circle distance (haversine)

Computes the great-circle distance between two latitude/longitude points using the haversine formula.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Convert both points' latitudes and longitudes to radians.
  2. Haversine formula: a = sin^2(dLat/2) + cos(lat1)*cos(lat2)*sin^2(dLon/2), where dLat and dLon are the differences in latitude and longitude.
  3. c = 2 * atan2(sqrt(a), sqrt(1-a)).
  4. distance = R * c, where R is the mean Earth radius, 6371.0088 km (IUGG).
  5. Round to 2 decimals.
  6. This treats Earth as a sphere; true geodesic distance on the actual ellipsoid can differ by a small fraction of a percent.

Constants

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"lat1":51.5074,"lon1":-0.1278,"lat2":48.8566,"lon2":2.3522}343.56 km
test vector: quarter of the equator{"lat1":0,"lon1":0,"lat2":0,"lon2":90}10007.56 km

Published card