【发布时间】:2014-12-31 02:49:07
【问题描述】:
我正在尝试实现 Vincenty 的逆问题,如 wiki HERE 中所述
问题在于 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)
如前所述,问题是“lamb”(lambda)的值不会变小。我什至尝试将我的代码与其他实现进行比较,但它们看起来几乎相同。
我在这里做错了什么? :-)
谢谢大家!
【问题讨论】:
-
在你的例子中,
lamb应该收敛到哪个值? -
试试
from __future__ import division -
那么,我认为您在链接到的页面上阅读的数学写作存在误解。当他们说
sin α = blabla时,并不是指sinAlpha = blabla,而是指α = arcsin blablabla -
@Bitious 在
L = (lo2 - lo1) * 0.0174532925,为什么是* 0.017...?维基文章没有提到这一点。 -
是的,但我在前几行中谈论的是 la1 和 la2。