Spherical Trigonometry and Geodetic Distance
Calculating distances and bearings on Earth requires spherical trigonometry because the Earth is roughly spherical. The shortest distance between two points on a sphere is a great-circle distance.
To calculate this, we use the Haversine formula, which computes the great-circle distance between two points on a sphere given their longitudes and latitudes. Let the coordinates of point 1 be \((\phi_1, \lambda_1)\) and point 2 be \((\phi_2, \lambda_2)\), where \(\phi\) represents latitude and \(\lambda\) represents longitude in radians. Let the differences be \(\Delta \phi = \phi_2 - \phi_1\) and \(\Delta \lambda = \lambda_2 - \lambda_1\). The haversine function \(\text{hav}(\theta) = \sin^2(\theta/2)\) is applied to formulate the spherical distance:
\\[a = \\sin^2\\left(\\frac{\\Delta \\phi}{2}\\right) + \\cos(\phi_1)\\cos(\phi_2)\\sin^2\\left(\\frac{\\Delta \\lambda}{2}\\right)\\]
\\[c = 2\\operatorname{atan2}(\\sqrt{a}, \\sqrt{1-a})\\]
The geodetic distance \(d\) is then computed as the product of the Earth's mean radius \(R\) (approximately 6,371,000 meters or 3,959 miles) and the central angle \(c\):
\\[d = R \\times c\\]
This formula is highly accurate for geocaching purposes, with errors under 0.5% due to the Earth's slight ellipsoidal flattening.