我正在尝试计算两个纬度/经度之间的方位。
我对函数/公式本身没有疑问,
假如:
def get_bearing(lat1, long1, lat2, long2):
dLon = (long2 - long1)
y = math.sin(dLon) * math.cos(lat2)
x = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(dLon)
brng = math.atan2(y, x)
brng = np.rad2deg(brng)
return brng
问题是结果不是预期的。
该函数的预期用途返回(非常长的)列表中两个纬度/经度对之间的方位,即
lat1 = path[int(len(path) * location / 1000)][0]
lat2 = path[int(len(path) * location / 1000) + 1][0]
lng1 = path[int(len(path) * location / 1000)][1]
lng2 = path[int(len(path) * location / 1000) + 1][1]
然后,方位角结果会改变绘图的视图方向,其中方位角可以采用 [-180, 180] 范围内的值。理想情况下,结果将显示为 lat1、lng1 和 lat2、lng2 之间形成的线在图中完全“垂直”(lat/lon 注释在图中切换), 见下文
我希望有人能够从函数返回的轴承中推断出问题以及预期的轴承应该是什么。下面举几个例子:
Current Location: 30.07134 -97.23076
Next in path: 30.0709 -97.22907
Calculated Bearing: 88.39967863143139
Expected Bearing: ~-70.67
Current Location: 29.91581 -96.85068
Next in path: 29.91556 -96.85021
Calculated Bearing: 118.9170342272798
Expected Bearing: ~122.67
Current Location: 29.69419 -96.53487
Next in path: 29.69432 -96.53466
Calculated Bearing 141.0271357781952
Expected Bearing: ~56
Current Location: 29.77357 -96.07924
Next in path: 29.77349 -96.07876
Calculated Bearing 165.24612555483893
Expected Bearing: ~104
很高兴提供更多信息,在此先感谢您提供的任何/所有帮助。
原文由 Sterling Butters 发布,翻译遵循 CC BY-SA 4.0 许可协议
最终改变了功能: