Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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;
share|improve this question
5  
$A=\sqrt{x^2+y^2+z^2}$... more or less, look up the conversion formulae from spherical to Cartesian coordinates. You will want to use the two-argument arctangent for this application instead of the usual arctangent. –  J. M. Aug 29 '11 at 1:51
1  
If this is for a real life app, you really need to take into account that the Earth's radius is not a constant 6378137 meters. –  Jyrki Lahtonen Aug 29 '11 at 9:25
add comment

1 Answer

up vote 0 down vote accepted

"A" should be the distance of of (x,y,z) from the origin, or $$\sqrt{x^2+y^2+z^2} $$ as J.M. commented.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.