Formula to convert Cartesian coordinates to spherical coordinates?

281 Views Asked by At

I have this formula:

x, y, z = cos(vertical)*sin(horizontal), sin(vertical), cos(vertical)*cos(horizontal)

Which maps a spherical coordinates (horizontal and vertical) to Cartesian coordinates (x, y, and z). What formula could I use to get the spherical coordinates back?

EDIT: fixed formula error as noted by Paul Sinclair

1

There are 1 best solutions below

2
On BEST ANSWER

So $x = \cos v\sin h, y = \sin v, z = \cos v\cos h$ (if you want the full words used, ask the programming exchanges instead of the math exchange - we hate typing)! Then consider what is $\sqrt{x^2 + z^2}$ and what is $\frac{x}{z}$. This should give you the answer.

(Edited to bring my equations in line with the correction to the OP.)