我需要将纬度和经度的值转换为三维空间中的点。我已经尝试了大约2小时,但是我没有得到正确的结果。
Equirectangular坐标来自openflights.org。我尝试了几种cos和sin的组合,但结果从未像我们心爱的地球那样。
在下面,您可以看到应用Wikipedia建议的转换的结果。我认为可以从上下文中猜出c4d.Vector
是什么。
def llarToWorld(latit, longit, altid, rad):
x = math.sin(longit) * math.cos(latit)
z = math.sin(longit) * math.sin(latit)
y = math.cos(longit)
v = c4d.Vector(x, y, z)
v = v * altid + v * rad
return v
红色:X,绿色:Y,蓝色:Z
确实可以识别出北美洲和南美洲,特别是墨西哥湾周围的陆地。然而,它看起来有点扁平,并且位置有些不对。
由于结果看起来有些旋转,我尝试交换了纬度和经度。但这个结果有点奇怪。
def llarToWorld(latit, longit, altid, rad):
temp = latit
latit = longit
longit = temp
x = math.sin(longit) * math.cos(latit)
z = math.sin(longit) * math.sin(latit)
y = math.cos(longit)
v = c4d.Vector(x, y, z)
v = v * altid + v * rad
return v
如果不进行值转换,结果将会是这样。
def llarToWorld(latit, longit, altid, rad):
return c4d.Vector(math.degrees(latit), math.degrees(longit), altid)
Solution
Thanks to TreyA, I found this page on mathworks.com, which provides a code snippet for converting longitude and latitude. Here's the code:
def llarToWorld(lat, lon, alt, rad):
# see: http://www.mathworks.de/help/toolbox/aeroblks/llatoecefposition.html
f = 0 # flattening
ls = atan((1 - f)**2 * tan(lat)) # lambda
x = rad * cos(ls) * cos(lon) + alt * cos(lat) * cos(lon)
y = rad * cos(ls) * sin(lon) + alt * cos(lat) * sin(lon)
z = rad * sin(ls) + alt * sin(lat)
return c4d.Vector(x, y, z)
实际上,我交换了y
和z
因为那时地球被旋转了,不过它可以工作!这就是结果:
altid
是海拔高度,但rad
是什么?是地球半径吗?altid
和rad
是否使用相同的单位(英尺)?如果只使用半径会怎样(即只有v = v * rad
)? - Omri Barel