将GPS转换为笛卡尔坐标

2024-10-05 14:29:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将gps位置转换为笛卡尔x,y,z位置相对于python中的第二个gps位置。我使用的是基于我在其他论坛上发现的其他信息的标准三角学,并期望x,y,z以米为单位。在

#Get cartesian coordinates relative to a center
import math

centerLat = 0.7127
centerLon = -1.2906
centerAlt = -32.406


pointLat = float(input("Enter latitude in degrees for the new point")) * 3.141592653589 / 180
pointLon = float(input("Enter longitude in degrees for the new point")) * 3.141592653589 / 180
pointAlt = float(input("Enter altitude in meters for the new point"))

r = centerAlt + 6378137
xCenter = r * math.cos(centerLat) * math.cos(centerLon)
yCenter = r * math.cos(centerLat) * math.sin(centerLon)
zCenter = r * math.sin(centerLat) 


r = pointAlt + 6378137
xPoint = r * math.cos(pointLat) * math.cos(pointLon)
yPoint = r * math.cos(pointLat) * math.sin(pointLon)
zPoint = r * math.sin(pointLat) 

x = xPoint - xCenter
y = yPoint - yCenter
z = zPoint - zCenter`enter code here`

由于某些原因,转换后的这两个点现在相距甚远。如果有人能告诉我我做错了什么,那就太好了。在

编辑: 这是我要转变的观点。 纬度:40.767870 长度:-73.885160 海拔:48.463201

我使用了一个在虚幻引擎中的风景作为参考,我使用this tutorial从GIS数据中导入,并且在发布这篇文章后意识到,这些景观并没有集中在我认为的地方。我已经调整了他们,结果已经很接近了,但仍然没有排成一行。我想知道这可能是规模或旋转的问题。在

所有的公式和常数都在下面的链接中找到 https://stackoverflow.com/questions/8981943/lat-long-to-x-y-z-position-in-js-not-working在


Tags: theinnewforinputmathsincos