Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Calculated solution in Clear category for Earth Distances by kopytok
import re
import math
R = 6371
coord_to_rad = lambda coord: (float(coord[0]) + float(coord[1]) / 60. + float(coord[2]) / 3600.) * math.pi / 180.
def coord_to_vec(coordinate):
loc = [re.split('[°′″]+', angle) for angle in coordinate.replace(',', ' ').split()]
alpha = coord_to_rad(loc[1])
if 'W' in loc[1][3]: alpha = 2 * math.pi - alpha
beta = coord_to_rad(loc[0])
if 'S' in loc[0][3]: beta = -beta
return [math.cos(alpha) * math.cos(beta), math.sin(alpha) * math.cos(beta), math.sin(beta)]
def distance(first, second):
dot = sum([i * j for i, j in zip(coord_to_vec(first), coord_to_vec(second))])
return round(math.acos(dot) * R, 1)
Nov. 10, 2017