Python - Vincenty 反演公式不收敛(查找地球上点之间的距离)

2024-04-01

我正在尝试实现维基百科上描述的文森蒂逆问题HERE http://en.wikipedia.org/wiki/Vincenty%27s_formulae#Inverse_problem

问题在于 lambda 根本不收敛。如果我尝试迭代公式序列,该值将保持不变,而且我真的不确定为什么。也许我只是对一个明显的问题视而不见。

应该指出的是,我是 Python 新手,仍在学习该语言,因此我不确定是否滥用该语言可能导致问题,或者我执行的某些计算中是否确实存在一些错误。我似乎找不到公式中的任何错误。

基本上,我已经以尽可能接近 wiki 文章的格式编写了代码,结果是这样的:

import math

# Length of radius at equator of the ellipsoid
a = 6378137.0

# Flattening of the ellipsoid
f = 1/298.257223563

# Length of radius at the poles of the ellipsoid
b = (1 - f) * a

# Latitude points
la1, la2 = 10, 60

# Longitude points
lo1, lo2 = 5, 150

# For the inverse problem, we calculate U1, U2 and L.
# We set the initial value of lamb = L
u1 = math.atan( (1 - f) * math.tan(la1) )
u2 = math.atan( (1 - f) * math.tan(la2) )
L = (lo2 - lo1) * 0.0174532925

lamb = L

while True:
    sinArc = math.sqrt( math.pow(math.cos(u2) * math.sin(lamb),2) + math.pow(math.cos(u1) * math.sin(u2) - math.sin(u1) * math.cos(u2) * math.cos(lamb),2) )
    cosArc = math.sin(u1) * math.sin(u2) + math.cos(u1) * math.cos(u2) * math.cos(lamb)
    arc = math.atan2(sinArc, cosArc)
    sinAzimuth = ( math.cos(u1) * math.cos(u2) * math.sin(lamb) ) // ( sinArc )
    cosAzimuthSqr = 1 - math.pow(sinAzimuth, 2)
    cosProduct = cosArc - ((2 * math.sin(u1) * math.sin(u2) ) // (cosAzimuthSqr))
    C = (f//16) * cosAzimuthSqr  * (4 + f * (4 - 3 * cosAzimuthSqr))
    lamb = L + (1 - C) * f * sinAzimuth * ( arc + C * sinArc * ( cosProduct + C * cosArc * (-1 + 2 * math.pow(cosProduct, 2))))
    print(lamb)

如前所述,问题是“羔羊”(lambda) 值不会变小。我什至尝试将我的代码与其他实现进行比较,但它们看起来几乎相同。

我在这里做错了什么? :-)

谢谢你们!


首先,您也应该将纬度转换为弧度(您已经对经度执行了此操作):

u1 = math.atan( (1 - f) * math.tan(math.radians(la1)) )
u2 = math.atan( (1 - f) * math.tan(math.radians(la2)) )
L = math.radians((lo2 - lo1)) # better than * 0.0174532925

一旦你这样做并摆脱// (int部门)并将其替换为/ (float部门),lambda停止通过迭代重复相同的值并开始遵循此路径(基于您的示例坐标):

2.5325205864224847
2.5325167509030906
2.532516759118641
2.532516759101044
2.5325167591010813
2.5325167591010813
2.5325167591010813

正如您似乎期望的收敛精度10^(−12),似乎说到点子上了。

您现在可以退出循环(lambda已收敛)并继续前进,直到计算出所需的测地距离s.

Note: 你可以测试你的最终值s here http://planetcalc.com/73/.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python - Vincenty 反演公式不收敛(查找地球上点之间的距离) 的相关文章

随机推荐