If you’re okay with a great-circle distance, as mentioned in the comments, then this should work. It’s the haversine distance:
def haversine(origin, destination, units='mi'):
# Radian deltas
origin_lat = radians(float(origin[0]))
origin_lon = radians(float(origin[1]))
destination_lat = radians(float(destination[0]))
destination_lon = radians(float(destination[1]))
lat_delta = destination_lat - origin_lat
lon_delta = destination_lon - origin_lon
# Radius of earth in meters
r = 6378127
# Haversine formula
a = sin(lat_delta / 2) ** 2 + cos(origin_lat) * \
cos(destination_lat) * sin(lon_delta / 2) ** 2
c = 2 * asin(sqrt(a))
meters_traveled = c * r
scaling_factors = {
"m:": 1,
"km": 1 / 1000,
"ft": 3.2808, # meters to feet
"mi:": 0.000621371 # meters to miles
}
return meters_traveled * scaling_factors[units]
If you already have the geodesic (great circle) distance in meters and you want the chord length, then you can do the following
def chord(geodesic_distance):
"""
Chord length
C = 2 * r * sin(theta/2)
Arc length; which is geodesic distance in this case
AL = R * theta
therefore
C = 2 * R * sin(AL/(2*R))
"""
r = 6378127 # Radius of earth in meters
return 2 * r * sin(geodesic_distance / (2 * r))
CLICK HERE to find out more related problems solutions.