Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将纬度和经度转换为三维空间中的点_Python_Math_3d_Latitude Longitude_Data Conversion - Fatal编程技术网

Python 将纬度和经度转换为三维空间中的点

Python 将纬度和经度转换为三维空间中的点,python,math,3d,latitude-longitude,data-conversion,Python,Math,3d,Latitude Longitude,Data Conversion,我需要将纬度和经度值转换为三维空间中的一个点。我已经试了大约两个小时了,但是没有得到正确的结果 等矩形坐标来自。我尝试过好几种因与罪的组合,但结果从来不像我们可爱的小地球 在下面,您可以看到应用转换的结果。我想人们可以从上下文中猜出什么是c4d.Vector def llarToWorld(latit, longit, altid, rad): x = math.sin(longit) * math.cos(latit) z = math.sin(longit) * math.

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

等矩形坐标来自。我尝试过好几种因与罪的组合,但结果从来不像我们可爱的小地球


在下面,您可以看到应用转换的结果。我想人们可以从上下文中猜出什么是
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)


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


解决方案 多亏了特雷亚,我在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)
实际上,我切换了
y
z
,因为那时地球是旋转的,但是,它是工作的!这就是结果:


你没有按照维基百科的建议去做。仔细再读一遍

他们说:

x = r cos(phi) sin(theta)
y = r sin(phi) sin(theta)
z = r cos(theta)
然后:

theta == latitude
phi == longitude
在你的例子中,r=半径+高度

因此,您应该使用:

r = radius + altitude
x = r cos(long) sin(lat)
y = r sin(long) sin(lat)
z = r cos(lat)

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

作为TreyA statet,
LLA到ECEF
是解决方案。请参见

我已重新格式化了前面提到的代码,但更重要的是,您遗漏了Niklas R提供的链接中提到的一些等式

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

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

虽然在您的地球自转环境中,您的函数将生成正确的地理区域以供显示,但它将而不是给出正确的ECEF等效坐标。正如您所见,一些参数的变化幅度高达20公里,这是一个相当大的误差

平坦因子,
f
取决于您为转换假设的模型。典型的,模型是;然而,还有其他模式


就我个人而言,我喜欢在海军研究生院对我的转换进行健康检查。

altid
是海拔高度,但什么是
rad
?那是地球的半径吗?
altid
rad
的单位是否相同(英尺)?如果您只使用半径(即仅
v=v*rad
),会怎么样?也可以通过谷歌搜索“lla到ecef”-纬度/经度/高度到以地球为中心的固定地球。@TreyA很好,谢谢!发现:这是正确的公式。:)如果你想让代表回答,你可以将你的评论作为答案,这样我也可以将我的问题标记为已回答。不幸的是,这与pixture 2显示的结果相同:(不,它不是。lat/long只被z交换。你把它们全部交换了。好吧,这不完全一样,但非常等于第二张图片。当交换lat和long时,它非常等于第一张图片。我通过搜索
lla到ecef
(感谢TreyA)找到的链接非常完美。请参阅:它应该是
x=r cos(long)cos(横向)y=r正弦(长)cos(横向)z=r正弦(横向)
。请注意,lat是从xy平面到z轴的角度,而不是维基百科建议的从z轴到xy平面的角度。这是可行的,但您首先需要将角度转换为弧度。lat/long值通常以度的形式提供。正如@TomislavMuic所指出的,在使用上述代码片段之前,您必须将纬度度转换为弧度。要做到这一点,请使用math.radians()功能。
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)