Baggywrinkle
Well-Known Member
Neither .... Karney’s algorithm ... until recently, I thought Pythons were snakes, but I got an AI to write the Python code from Greenwich to JFK ... obviously, substituting current position for lat1, lon1 and a waypoint for lat2, lon2 would enable it to work for current position to a waypoint. Karney's is very accurate, even over short distances, and uses the WGS-84 ellipsoid model of the earth.Nerdy question incoming...
Haversine formula or Vincenty algorithm?
from geographiclib.geodesic import Geodesic
# Coordinates (degrees)
lat1, lon1 = 51.4778, -0.0014 # Greenwich
lat2, lon2 = 40.6413, -73.7781 # JFK
result = Geodesic.WGS84.Inverse(lat1, lon1, lat2, lon2)
distance_m = result["s12"] # meters
initial_bearing = result["azi1"] # degrees
final_bearing = result["azi2"] # degrees
print("Distance (m):", distance_m)
print("Initial Bearing (°):", initial_bearing)
print("Final Bearing (°):", final_bearing)
Last edited: