为什么我执行大圆距离公式会给出错误的结果?
Why does my implementation of the Great Circle distance formula give wrong results?
我正在尝试实现根据 guide
使用大圆距离公式计算两点之间距离的算法
我的函数:
from math import sin, cos, radians
def get_great_circle_distance(first_coords, second_coords, radius):
"""
:param first_coords: (first_client_latitude, first_client_longitude) <- degrees
:param second_coords: (second_client_latitude, second_client_longitude) <- degrees
:param radius: planet radius
:return: distance
"""
la_1, lo_1 = map(radians, first_coords)
la_2, lo_2 = map(radians, second_coords)
denominator = cos(
cos(la_1) * cos(la_2) * cos(lo_1 - lo_2) +
sin(la_1) * sin(la_2)
)
distance = radius / denominator
return distance
例如我调用:
distance = get_great_circle_distance((55, 28), (86, 70), 7)
并期待 ~3.93km
,但我得到 10.56897。
我正在尝试实现根据 guide
使用大圆距离公式计算两点之间距离的算法我的函数:
from math import sin, cos, radians
def get_great_circle_distance(first_coords, second_coords, radius):
"""
:param first_coords: (first_client_latitude, first_client_longitude) <- degrees
:param second_coords: (second_client_latitude, second_client_longitude) <- degrees
:param radius: planet radius
:return: distance
"""
la_1, lo_1 = map(radians, first_coords)
la_2, lo_2 = map(radians, second_coords)
denominator = cos(
cos(la_1) * cos(la_2) * cos(lo_1 - lo_2) +
sin(la_1) * sin(la_2)
)
distance = radius / denominator
return distance
例如我调用:
distance = get_great_circle_distance((55, 28), (86, 70), 7)
并期待 ~3.93km
,但我得到 10.56897。