Files
FlightGrid/simulator/utils.py
2025-09-29 22:46:23 -05:00

18 lines
436 B
Python

import math
def haversine_nm(lat1, lon1, lat2, lon2):
# Earth radius in nautical miles
R = 3440.065
phi1, phi2 = math.radians(lat1), math.radians(lat2)
dphi = math.radians(lat2 - lat1)
dlambda = math.radians(lon2 - lon1)
a = (
math.sin(dphi / 2) ** 2
+ math.cos(phi1) * math.cos(phi2) * math.sin(dlambda / 2) ** 2
)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
return R * c