# Converting from Cartesian coordinates to Spherical coordinates

I want to understand how to convert from Cartesian coordinates to spherical coordinates. I have the following definitions:

\begin{align} x & =r\sin\theta\cos\phi \\[6pt] y & =r\sin\theta\sin\phi \\[6pt] z & =r\cos\theta \\[6pt] \rho & =r\sin\theta \end{align}

In written terms: $r$ is the distance from the origin to the point, $\phi$ is the angle needed to rotate around $z$ to get to the point, $\theta$ is the angle from the positive $z$-axis, $\rho$ is the distance between the point and the $z$-axis.

On the basis that $(x,y,z)=(r,\theta,\phi)$ I have,

$$\rho=\sqrt{x^2+y^2}=r\sin\theta$$

using Pythagoras' Theorem gives

$$r=\sqrt{\rho^2+z^2}=\sqrt{x^2+y^2+z^2}.$$

Next take $z=r\cos\theta$ which gives

$$\theta=\arccos\left(\frac{z}{r}\right).$$ Both of these agree with what I have found on wikipedia, however I can't understand how the last coordinate $\phi$ is reached. This is what I get:

$$y=r\sin\theta\sin\phi$$ $$\frac{y}{r\sin\theta}=\sin\phi$$

from here I use the relationship that $\rho=\sqrt{x^2+y^2}=r\sin\theta$ and write

$$\frac{y}{\rho}=\sin\phi$$ $$\arcsin\left(\frac{y}{\rho}\right)=\phi.$$

Have I gone wrong somewhere? Can it be explained to me how my last result differs from that provided by wikipedia?

Thanks

-

In most texts, $\theta$ is the angle in the $xy$ plane and $\phi$ is the angle down from the $z$ axis. That is, I think you (and wiki) have things not as usual. Nevertheless, using their definitions, both answers are correct.

The wiki terms for $y$ and $x$, when one computes $y/x$ the $r \sin(\theta)$ cancels and the result is $\sin(\phi)/\cos(\phi) = \tan(\phi)$. so you can say $\phi = \tan^{-1}(y/x)$ as wiki does.

For your version, you use the extra symbol $\rho$, which is really $r \sin(\theta)$. So using the same formulas from wiki gives $y/\rho = y/(r \sin(\theta) )$. This time the $y$ in wiki is $r\sin(\theta)\sin(\phi)$, so things cancel and you get $y/\rho = \sin(\phi)$. Thus you can also say that $\phi = \arcsin(y/\rho)$. But note that $\rho$ is not one of the spherical coordinates, but is just $r\sin(\theta)$ in terms of the spherical coordinates. It's not usual to give the inverse in terms of other symbols than the direct variables.

-
In both the wiki version and yours, care must be taken as to which quadrant one is in, because of the arctan and arcsin functions not automatically returning the original angles. – coffeemath Oct 12 '12 at 16:51
Thanks for help explaining this in the terms I am using and I understand now that I really don't want to be using $\rho$ in my final conversions. Could you help explain why I would divide y/x in order to obtain tan? – Aesir Oct 12 '12 at 17:20
In the wiki formulas, y is r sin theta sin phi and x is r sin theta cos phi. By dividing y by x we will have a cancel of the common factor r sin theta, arriving at simply sin phi / cos phi, which is tan phi. – coffeemath Oct 12 '12 at 17:31
Ah yes, I see so it's just common sense to do that, or not in my case! Thanks, I understand now. – Aesir Oct 12 '12 at 17:40

Your formula for $\phi$ is correct for $x>0$, but gives the wrong angle when $x<0$: in this case $\phi\in(\pi/2,3\pi/2)$, but $\arcsin$ gives a result in $[-\pi/2,\pi/2]$.

The formula shown by Wikipedia is obtained from

$$\sin\phi=y/\rho\\ \cos\phi=x/\rho$$

and dividing the two's (when possible)

$$\tan\phi=y/x.$$

From here it comes out $\arctan$, with all the warning of the case, leading to the atan2 function.

-
Thanks for taking the time to answer, could you provide some more clarification on why I would divide $y$ by $x$? I can see now that, that would give me $\tan$ which is what I need but I don't understand why I would do this. – Aesir Oct 12 '12 at 17:18