将纬度和经度转换为3D空间中的点

Nik*_*s R 19 python math 3d data-conversion latitude-longitude

我需要将纬度和经度值转换为三维空间中的一个点.我现在已经尝试了大约2个小时,但是我没有得到正确的结果.

等距离长方圆柱坐标来自openflights.org.我已经尝试了几种cos罪的组合,但结果看起来永远不像我们心爱的小地球.


在下文中,您可以看到应用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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

红色: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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


这是没有转换值的结果.

def llarToWorld(latit, longit, altid, rad):
    return c4d.Vector(math.degrees(latit), math.degrees(longit), altid)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


问题:如何正确转换经度和纬度?


感谢TreyA,我在mathworks.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)
Run Code Online (Sandbox Code Playgroud)

实际上,我切换了y,z因为地球旋转然后,它工作!这就是结果:

在此输入图像描述

and*_*oke 13

你不是在做维基百科的建议.仔细阅读它.

他们说:

x = r cos(phi) sin(theta)
y = r sin(phi) sin(theta)
z = r cos(theta)
Run Code Online (Sandbox Code Playgroud)

然后:

theta == latitude
phi == longitude
Run Code Online (Sandbox Code Playgroud)

并且,在您的情况下,r =半径+高度

所以你应该使用:

r = radius + altitude
x = r cos(long) sin(lat)
y = r sin(long) sin(lat)
z = r cos(lat)
Run Code Online (Sandbox Code Playgroud)

请注意,最后一个条目是cos(lat)(您使用的是经度).

  • 它应该是```x = r cos(long) cos(lat) y = r sin(long) cos(lat) z = r sin(lat)```。请注意 lat 与 xy 平面的角度而不是 wikipedia 建议的 z 轴的角度。 (2认同)

小智 12

我重新格式化了之前提到过的代码,但更重要的是你忽略了Niklas R提供的链接中提到的一些方程式

def LLHtoECEF(lat, lon, alt):
    # see http://www.mathworks.de/help/toolbox/aeroblks/llatoecefposition.html

    rad = np.float64(6378137.0)        # Radius of the Earth (in meters)
    f = np.float64(1.0/298.257223563)  # Flattening factor WGS84 Model
    cosLat = np.cos(lat)
    sinLat = np.sin(lat)
    FF     = (1.0-f)**2
    C      = 1/np.sqrt(cosLat**2 + FF * sinLat**2)
    S      = C * FF

    x = (rad * C + alt)*cosLat * np.cos(lon)
    y = (rad * C + alt)*cosLat * np.sin(lon)
    z = (rad * S + alt)*sinLat

    return (x, y, z)
Run Code Online (Sandbox Code Playgroud)

比较输出:找到洛杉矶,加利福尼亚州的ECEF(34.0522,-118.40806,0海拔)
我的代码:
X = -2516715.36114米或-2516.715 km
Y = -4653003.08089米或-4653.003 km
Z = 3551245.35929米或3551.245公里

您的密码:
X = -2514072.72181米或-2514.072公里
Y = -4648117.26458米或-4648.117公里
Z = 3571424.90261米或3571.424公里

虽然在地球自转环境中,您的功能会产生正确的地理区域以供显示,但它不会给出正确的ECEF等效坐标.正如您所看到的,一些参数变化多达20公里,这是一个很大的错误.

展平系数f取决于您为转换假设的模型.典型的型号是WGS 84 ; 但是,还有其他型号.

就个人而言,我喜欢使用此链接进入海军研究生院,以便对我的转换进行健全性检查.


Nik*_*s R 4

正如TreyA所说,LLA to ECEF这就是解决方案。请参阅http://www.mathworks.de/help/toolbox/aeroblks/llatoecefposition.html