鉴于我的代码:
from math import radians, cos, sin, asin, sqrt, atan2, degrees, log, tan, pi, fabs
def _c(old):
direction = {'N':1, 'S':-1, 'E': 1, 'W':-1}
new = old
new = new.split()
new_dir = new.pop(0)
new.extend([0,0,0])
x = (float(new[0])+float(new[1])/60.0+float(new[2])/3600.0) * direction[new_dir]
return x
def distance_rhumb_lines(lon1, lat1, lon2, lat2):
tenEtwelfe = 1000000000000
r = 3443.89849 # Radius of earth in NM.
lon1, lat1, lon2, lat2 = map(radians, [_c(lon1), _c(lat1), _c(lon2), _c(lat2)])
dlat = fabs(lat2 - lat1)
dlon = fabs(lon2 - lon1)
if fabs(dlon) > pi:
dlon = -(2*pi-dlon) if dlon>0 else (2*pi+dlon)
x = log( tan(pi/4+lat2/2) / tan(pi/4+lat1/2) )
q = dlat/dlon if fabs(x) > tenEtwelfe else cos(lat1)
dist = sqrt(dlat*dlat + q*q*dlon*dlon) * r
return dist
def distance_great_circle(lon1, lat1, lon2, lat2):
lon1, lat1, lon2, lat2 = map(radians, [_c(lon1), _c(lat1), _c(lon2), _c(lat2)])
dlon = lon2 - lon1
dlat = lat2 - lat1
a = (sin(dlat / 2) * sin(dlat / 2) +
cos(lat1) * cos(lat2) *
sin(dlon / 2) * sin(dlon / 2))
c = 2 * atan2(sqrt(a), sqrt(1 - a))
r = 3443.89849 # Radius of earth in NM.
return c * r
def eet(gs, dist):
return 60.0 / gs * dist
dist = distance_great_circle(lon1=u'N 47 27 59.60',lat1=u'E 7 39 55.6',lon2=u'N 47 30 32',lat2=u'E 7 57 0')
dist2 = distance_rhumb_lines(lon1=u'N 47 27 59.60',lat1=u'E 7 39 55.6',lon2=u'N 47 30 32',lat2=u'E 7 57 0')
eet_min = eet(100, dist)
print "Dist Great Circle = %.1f / Dist Rhumb Line = %.1f / EET = %.1f min" % (dist, dist2, eet_min)
我不确定这是否是一个数学特定问题然后python。这是我的剪贴簿代码,用于根据纬度/经度坐标计算两个给定点之间的距离。
我的代码似乎有效,但结果是大约5海里(海里1海里= 1.8公里)太高,因为我根据我的物理地图测量得到的结果是大约12纳米(我的代码显示17.3纳米) )。
可能是什么问题?我使用错误的地球半径吗?我是否需要关注半径中物理地图的投影类型?
我现在,有些图书馆正在做这些事情,并且他们做得更好;)但我想知道我的代码问题是什么,然后我扔掉它并使用库。