0

I am attempting to convert a gps location for a Cartesian x,y,z location relative to a second gps location in python. I am using the standard trigonometry based on other info I found on other forums and was expect x,y,z to come out in meters.

#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`

For some reason these two points after conversion are now farther apart than they should be. If someone could give me advice on what I'm doing wrong that would be great.

Edit: Here is the point I am trying to convert. Lat: 40.767870 Lon: -73.885160 Alt: 48.463201

I am using a landscape in unreal engine for reference which I have imported from GIS Data using this tutorial and realized since posting this that the landscapes where not centered where I thought they were. I have adjusted them and the result is much closer now but still not lining up. I wonder if it might be an issue of scale or rotation.

all formulas and constants were found in the below links https://stackoverflow.com/questions/8981943/lat-long-to-x-y-z-position-in-js-not-working

PaulB
  • 111
  • 2
  • 13
  • Can you add the test-case which gives the wrong output? The math seems to be right. – MinosIllyrien Feb 18 '19 at 12:17
  • Here are the coordinates for the two points in radians. Origin lat: 0.7127 Origin lon: 1.2906, Point Lat:0.84584242351, Point lon: -1.2895393104. I realized that my landscape which I was using for reference was not center where I had thought and fixing that made the error a lot smaller. I think it may actually be an issue of rotation or scaling between the points and the landscape which I created from GIS data. Thanks – PaulB Feb 20 '19 at 14:33

0 Answers0