I am using equations that look like the following to get x, y, and z given latitude, longitude, and altitude.
x = (6378137 + alt) * cos(lat) * cos(lon); y = (6378137 + alt) * cos(lat) * sin(lon); z = (6378137 + alt) * sin(lat);
If I already know x,y,z, I want to solve for lat, lon, and alt.
For the purposes of the solution it's just a problem of the form:
x=A*cos(B)*cos(C) y=A*cos(B)*sin(C) z=A*sin(B)
I know x, y, and z. I want to solve for A, B, and C.
Normally this should be easy. I've got 3 unknowns and 3 equations. I'd just solve for one variable and substitute it in the second equation, etc. But I'm having trouble doing this with the trig functions.
For example, if I try to solve them I end up with
C = atan(y/x) B = acos( x / (A*cos( atan(y/x) )) ) A = z / sin( acos( x / (A*cos( atan(y/x) )) ) )
I don't know how to solve that last one for A.
EDIT: The following works. Thanks!
double alt = Math.sqrt(x*x + y*y + z*z) - a; double lon = Math.atan2(y,x) * MathUtils.num180DivPI; double lat = Math.asin(z / (alt+a)) * MathUtils.num180DivPI;