Compute great-circle distance and initial/final bearing between two latitude/longitude coordinates. Uses the Haversine formula on a spherical Earth (mean radius 6371 km). Accurate to ~0.3% versus a full ellipsoid model — plenty good for most flight, navigation, and location-matching work.
Given two points with latitudes φ₁, φ₂ and longitude difference Δλ:
a = sin²(Δφ/2) + cos(φ₁)·cos(φ₂)·sin²(Δλ/2)
c = 2·atan2(√a, √(1−a))
d = R · c where R is Earth's mean radius (6371 km).
The initial bearing θ is computed with:
θ = atan2(sin(Δλ)·cos(φ₂), cos(φ₁)·sin(φ₂) − sin(φ₁)·cos(φ₂)·cos(Δλ))
The final bearing is the initial bearing from B back to A, plus 180°.