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