# Spherical unit vectors in terms of Cartesian unit vectors

Here’s a way to obtain the spherical unit vectors $\hat r$, $\hat \theta$ and $\hat \phi$ in terms of the Cartesian unit vectors $\hat x$, $\hat y$ and $\hat z$. Note that $\theta$ correspond to the zenithal angle while $\phi$ is the azimuthal angle.

Starting from $\begin{cases}x=r\cos\phi\sin\theta \\y=r\sin\phi\sin\theta\\z=r\cos\theta\end{cases}$    and $\vec r = x \hat x + y \hat y + z\hat z$, the spherical unit vectors are given by :

$\hat \phi = \frac{1}{h_\phi} \frac{\partial \vec r}{\partial \phi}$ where $h_\phi=|\frac{\partial \vec r}{\partial \phi}|=r\sin \theta$ is the scale factor. So we have that $\hat \phi = \frac{1}{r \sin \theta}(-r\sin \phi \sin \theta \hat x + r \sin \theta \cos \phi \hat y) = - \sin \phi \hat x + \cos \phi \hat y$.

While $\hat \theta = \frac{1}{r}(r \cos\phi\cos\theta \hat x + r \sin\phi \cos\theta \hat y -r\sin\theta \hat z)=\cos\phi\cos\theta \hat x + \sin\phi \cos\theta \hat y -\sin\theta \hat z$;

Finally, $\hat r=\frac{\partial \vec r}{\partial r}=\cos\phi\sin\theta \hat x + \sin\phi\sin\theta\hat y +\cos\theta \hat z$.