【发布时间】:2011-06-22 06:01:28
【问题描述】:
问题
我想知道如何获得 2 个 GPS 点之间的距离和方位。 我研究了haversine公式。 有人告诉我,我也可以使用相同的数据找到方位。
编辑
一切正常,但轴承还不能完全正常工作。轴承输出负值,但应在 0 - 360 度之间。
设置的数据应该使水平方位96.02166666666666
并且是:
Start point: 53.32055555555556 , -1.7297222222222221
Bearing: 96.02166666666666
Distance: 2 km
Destination point: 53.31861111111111, -1.6997222222222223
Final bearing: 96.04555555555555
这是我的新代码:
from math import *
Aaltitude = 2000
Oppsite = 20000
lat1 = 53.32055555555556
lat2 = 53.31861111111111
lon1 = -1.7297222222222221
lon2 = -1.6997222222222223
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
dlon = lon2 - lon1
dlat = lat2 - lat1
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
c = 2 * atan2(sqrt(a), sqrt(1-a))
Base = 6371 * c
Bearing =atan2(cos(lat1)*sin(lat2)-sin(lat1)*cos(lat2)*cos(lon2-lon1), sin(lon2-lon1)*cos(lat2))
Bearing = degrees(Bearing)
print ""
print ""
print "--------------------"
print "Horizontal Distance:"
print Base
print "--------------------"
print "Bearing:"
print Bearing
print "--------------------"
Base2 = Base * 1000
distance = Base * 2 + Oppsite * 2 / 2
Caltitude = Oppsite - Aaltitude
a = Oppsite/Base
b = atan(a)
c = degrees(b)
distance = distance / 1000
print "The degree of vertical angle is:"
print c
print "--------------------"
print "The distance between the Balloon GPS and the Antenna GPS is:"
print distance
print "--------------------"
【问题讨论】:
-
Python hasrsine 实现可以在codecodex.com/wiki/… 找到。然而,对于短距离计算,存在非常简单的方法。现在,您期望的最大距离是多少?你能在一些当地的笛卡尔坐标系中得到你的坐标吗?
-
@James Dyson:距离像 15 公里,创造圈不算什么。我的建议:首先找出欧几里得距离的解决方案!这将为您提供一个可行的解决方案,然后如果您的距离会更长,然后调整您的应用程序。谢谢
-
@James Dyson:如果您的上述评论是针对我的(以及针对我之前的建议),那么答案肯定是(而且非常“微不足道”)。我也许可以给出一些示例代码,但它不会使用三角函数,而是几何(所以我不确定它是否会对你有所帮助。你是否熟悉向量的概念?在你的情况下,位置和方向可以用向量最直接的方式处理)。
-
atan2(sqrt(a), sqrt(1-a))与asin(sqrt(a))相同
标签: python gps distance haversine bearing