我需要将纬度和经度值转换为 3 维空间中的点。我已经尝试了大约 2 个小时,但没有得到正确的结果。
The 等长方形坐标来自openflights.org http://openflights.org/data.html。我尝试了几种组合cos and sin,但结果却一点也不像我们心爱的小地球。
在下面,您可以看到应用转换的结果维基百科 http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates建议。我想人们可以从上下文中猜出什么c4d.Vector
is.
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)
Question: 如何正确转换经度和纬度?
Solution
感谢 TreyA,我发现this http://www.mathworks.de/help/toolbox/aeroblks/llatoecefposition.htmlmathworks.com 上的页面。完成其工作的代码如下:
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
and z
因为当时地球是旋转的,但是,它是有效的!这就是结果: