【发布时间】:2020-08-12 14:34:54
【问题描述】:
我希望能够使用 python 确定两个地理位置之间的角度。为了实现它,我考虑了movable-type 网站。在这个网站上查找 point1(42.386391,-71.019037) 和 point2(42.387728, -71.016153) 时,我得到了 57 度,这在谷歌地图中也完全有意义。
所以我已将网站上共享的公式转换为 python。 这是网站上的公式:
这是我的python代码:
def bearing1(lat1, long1, lat2, long2):
cal = math.atan2(np.sin(long2-long1)*np.cos(lat2), np.cos(lat1)*np.sin(lat2)-np.sin(lat1)*np.cos(lat2)*np.cos(long2-long1))
bearing = np.degrees(cal)
return (360+bearing) % 360
但是当我运行这个函数时,我得到的角度是 357 度。
如果你认为红点是 point1,粉红色点是 point2,那么 57 度角比 357 度更有意义。 (绿色的X是我想学的角度)。
另外,我在this website 上尝试了相同的值,它又是 59 度,这还不错。显然,我的代码中遗漏了一些东西。所以你觉得我做错了什么?应该改变什么?
【问题讨论】:
-
lat1 等的 tp 以弧度表示。是吗?
-
是的,它是@dmuir
标签: python math geolocation bearing