我需要将纬度和经度值转换为3维空间中的一个点。我已经尝试了大约2个小时,但是没有得到正确的结果。
等角坐标来自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)
问题:如何正确转换经度和纬度?
解
多亏了TreyA,我才能在mathworks.com上找到this页面。起作用的代码如下:
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
,因为那时地球已经旋转了,但是它起作用了!结果就是: 最佳答案
我已经重新格式化了前面在此提到的代码,但是更重要的是,您省略了尼古拉斯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)
比较输出:查找加利福尼亚洛杉矶的ECEF(34.0522,-118.40806、0海拔)
我的代码:
X = -2516715.36114米或 -2516.715 km
Y = -4653003.08089米或 -4653.003 km
Z = 3551245.35929米或 3551.245 km
您的代码:
X = -2514072.72181米或 -2514.072 km
Y = -4648117.26458米或 -4648.117 km
Z = 3571424.90261米或 3571.424 km
尽管在地球自转环境中,您的函数将产生正确的地理区域进行显示,但它会而不是给出正确的ECEF等效坐标。如您所见,某些参数的差异最大为 20 KM ,这是一个很大的错误。
展平系数
f
取决于您为转换所采用的模型。典型的模型是WGS 84;但是,还有其他模型。就我个人而言,我喜欢使用this link到海军研究生院进行转换的健全性检查。
关于python - 将经度和纬度转换为3D空间中的点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10473852/