You need the formulas for converting from Cartesian to Spherical
coordinate systems.  There is a good discussion of this at at
http://en.wikipedia.org/wiki/Spherical_coordinates.

In their notation:
r = radius of the earth
theta = latitude
phi = longitude

Then
var r = Math.sqrt(x*x + y*y + z*z); // radius from center of the earth
to your point
var theta = Math.acos( z / r); // LAT in radians
var phi = Math.atan2(y, x); // LON in radians

You will have to do the radians-to-degrees conversion, and also check
that the +/- sign conventions of your x/y/z match the +/- and E/W for
longitude and latitude.

Good luck!
Ralph

On Mar 12, 1:15 am, dyc <[email protected]> wrote:
> Hey guys,
>
> I am currently trying to go from an XYZ coordinate to a lon/lat
> coordinate.
>
> The formula to go from lon/lat to XYZ is as follows:
>
> LAT = latitude * pi/180
> LON = longitude * pi/180
> x = -R * cos(LAT) * cos(LON)
> y =  R * sin(LAT)
> z =  R * cos(LAT) * sin(LON)
>
> Can anyone help me figure out how to reverse that formula so I can get
> lon/lat from xyz?
>
> Thanks so much!
>
> `Scott

Reply via email to