# How do I convert a vector field in Cartesian coordinates to spherical coordinates?

I have a vector field in terms of $\mathbf{\hat i}$, $\mathbf{\hat j}$, and $\mathbf{\hat k}$,

$$\mathbf{F} = x\mathbf{\hat i} + y\mathbf{\hat j} + z\mathbf{\hat k}$$

How do I convert it to the spherical coordinate system so that the unit vectors become $\mathbf{\hat r}$, $\boldsymbol{\hat \theta}$ and $\boldsymbol{\hat \phi}$?

I know that we have the following relations:

\begin{align} F_r &= \sqrt{{F_x}^2 + {F_y}^2 + {F_z}^2}\\ F_\theta &= \tan^{-1} \frac{F_y}{F_x}\\ F_\phi &= \cos^{-1} \frac{F_z}{F_r} \end{align}

And the inverses:

\begin{align} x &= r\cos{\theta}\sin{\phi}\\ y &= r\sin{\theta}\sin{\phi}\\ z &= r\cos{\phi} \end{align}

I want to have the vector in the form

\begin{align} \mathbf{F} &= F_{r}\mathbf{\hat r} + F_{\theta}\boldsymbol{\hat \theta} + F_{\phi}\boldsymbol{\hat \phi} \end{align}

Therefore, I will eventually get

\begin{align} \mathbf{F} &= \sqrt{x^2 + y^2 + z^2}\mathbf{\hat r} + \tan^{-1} \frac{y}{x}\boldsymbol{\hat \theta} + \cos^{-1} \frac{z}{\sqrt{x^2 + y^2 + z^2}}\boldsymbol{\hat \phi} \end{align}

Then express $x$, $y$ and $z$ in terms of $r$, $\theta$ and $\phi$.

Did I get the relations right? Or are there other operations (chain rule, etc) that I missed? OR is this simply out of whack?

I am looking for the process as to how it got to this (from Wikipedia):

$$\begin{bmatrix}\boldsymbol{\hat\rho} \\ \boldsymbol{\hat\theta} \\ \boldsymbol{\hat\phi} \end{bmatrix} = \begin{bmatrix} \sin\theta\cos\phi & \sin\theta\sin\phi & \cos\theta \\ \cos\theta\cos\phi & \cos\theta\sin\phi & -\sin\theta \\ -\sin\phi & \cos\phi & 0 \end{bmatrix} \begin{bmatrix} \mathbf{\hat x} \\ \mathbf{\hat y} \\ \mathbf{\hat z} \end{bmatrix}$$

so that $\mathbf{F} = x\mathbf{\hat i} + y\mathbf{\hat j} + z\mathbf{\hat k} = F_{r}\mathbf{\hat r} + F_{\theta}\boldsymbol{\hat \theta} + F_{\phi}\boldsymbol{\hat \phi}$.

First, $$\mathbf{F} = x\mathbf{\hat i} + y\mathbf{\hat j} + z\mathbf{\hat k}$$ converted to spherical coordinates is just $$\mathbf{F} = \rho \boldsymbol{\hat\rho}$$. This is because $$\mathbf{F}$$ is a radially outward-pointing vector field, and so points in the direction of $$\boldsymbol{\hat\rho}$$, and the vector associated with $$(x,y,z)$$ has magnitude $$|\mathbf{F}(x,y,z)| = \sqrt{x^2+y^2+z^2} = \rho$$, the distance from the origin to $$(x,y,z)$$.

$$\begin{bmatrix}\boldsymbol{\hat\rho} \\ \boldsymbol{\hat\theta} \\ \boldsymbol{\hat\phi} \end{bmatrix} = \begin{bmatrix} \sin\theta\cos\phi & \sin\theta\sin\phi & \cos\theta \\ \cos\theta\cos\phi & \cos\theta\sin\phi & -\sin\theta \\ -\sin\phi & \cos\phi & 0 \end{bmatrix} \begin{bmatrix} \mathbf{\hat x} \\ \mathbf{\hat y} \\ \mathbf{\hat z} \end{bmatrix}$$

comes from. Let's look at the simpler 2D case first. For a point $$(x,y)$$ it helps to imagine that you're on a circle centered at the origin. In this case, the two fundamental directions you can move are perpendicular to the circle or along the circle. For the perpendicular direction we use the outward-pointing radial unit vector $$\mathbf{\hat{r}}$$. For the other direction, moving along the circle means (instantaneously) that you're moving tangent to it, and we take the unit vector in this case to be $$\boldsymbol{\hat\theta}$$, pointing counterclockwise. For example, suppose you're at the point $$(1/\sqrt{2},1/\sqrt{2})$$. Then, in the graph below, $$\mathbf{\hat{r}}$$ is in red and $$\boldsymbol{\hat\theta}$$ is in yellow.

Note that this means that, unlike the unit vectors in Cartesian coordinates, $$\mathbf{\hat{r}}$$ and $$\boldsymbol{\hat{\theta}}$$ aren't constant; they change depending on the value of $$(x,y)$$.

Now, what about a formula for $$\mathbf{\hat{r}}$$? If we move perpendicular to the circle we're keeping $$\theta$$ fixed in the polar coordinate representation $$(r \cos \theta, r \sin \theta)$$. The vector $$\mathbf{\hat{r}}$$ is the unit vector in the direction of this motion. If we interpret $$r$$ as time, taking the derivative with respect to $$r$$ will give us the velocity vector, which we know points in the direction of motion. Thus we want the unit vector in the direction of $$\frac{d}{dr} (r \cos \theta, r \sin \theta) = (\cos \theta, \sin \theta)$$. This is already a unit vector, so $$\mathbf{\hat{r}} = \cos \theta \mathbf{\hat{x}} + \sin \theta \mathbf{\hat{y}}$$. Similarly, moving counterclockwise along the circle entails keeping $$r$$ fixed in the polar coordinate representation $$(r \cos \theta, r \sin \theta)$$. Thus to find $$\boldsymbol{\hat\theta}$$ we take $$\frac{d}{d\theta} (r \cos \theta, r \sin \theta) = (-r \sin \theta, r \cos \theta)$$. This is not necessarily a unit vector, and so we need to normalize it. Doing so yields $$\boldsymbol{\hat\theta}= -\sin \theta \mathbf{\hat{x}} + \cos \theta \mathbf{\hat{y}}$$. In matrix form, this is $$\begin{bmatrix} \mathbf{\hat{r}} \\ \boldsymbol{\hat\theta}\end{bmatrix} = \begin{bmatrix} \cos \theta & \sin \theta \\ -\sin \theta & \cos \theta \end{bmatrix} \begin{bmatrix} \mathbf{\hat{x}} \\ \mathbf{\hat{y}} \end{bmatrix}$$.

Moving up to spherical coordinates, for a given point $$(x,y,z)$$, imagine that you're on the surface of a sphere. The three fundamental directions are perpendicular to the sphere, along a line of longitude, or along a line of latitude. The first corresponds to $$\boldsymbol{\hat\rho}$$, the second to $$\boldsymbol{\hat\theta}$$, and the third to $$\boldsymbol{\hat{\phi}}$$. (This is using the convention in the Wikipedia page, which has $$\theta$$ and $$\phi$$ reversed from what you have.) Thus to find $$\boldsymbol{\hat\rho}$$, $$\boldsymbol{\hat\theta}$$, and $$\boldsymbol{\hat{\phi}}$$, we take the derivative of the spherical coordinate representation $$(\rho \sin \theta \cos \phi, \rho \sin \theta \sin \phi, \rho \cos \theta)$$ with respect to $$\rho$$, $$\theta$$, and $$\phi$$, respectively, and then normalize each one. That's where the matrix

$$\begin{bmatrix}\boldsymbol{\hat\rho} \\ \boldsymbol{\hat\theta} \\ \boldsymbol{\hat\phi} \end{bmatrix} = \begin{bmatrix} \sin\theta\cos\phi & \sin\theta\sin\phi & \cos\theta \\ \cos\theta\cos\phi & \cos\theta\sin\phi & -\sin\theta \\ -\sin\phi & \cos\phi & 0 \end{bmatrix} \begin{bmatrix} \mathbf{\hat x} \\ \mathbf{\hat y} \\ \mathbf{\hat z} \end{bmatrix}$$

comes from.

As Henning Makholm points out, one way to view what we're doing here is that we're rotating the $$\mathbf{\hat{x}}, \mathbf{\hat{y}}, \mathbf{\hat{z}}$$ vectors. The transformation matrix can thus be considered a change-of-basis matrix. This means you could also (and more generally) convert $$\mathbf{F} = x\mathbf{\hat i} + y\mathbf{\hat j} + z\mathbf{\hat k}$$ to spherical coordinates via \begin{align} \mathbf{F} &= \begin{bmatrix} F_{\rho}\\ F_{\theta}\\ F_{\phi}\end{bmatrix} \\ &= \begin{bmatrix} \sin \theta \cos \phi & \sin \theta \sin \phi & \cos \theta \\ \cos \theta \cos \phi & \cos \theta \sin \phi & - \sin \theta \\ - \sin \phi & \cos \phi & 0 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} \\ &= \begin{bmatrix} \sin \theta \cos \phi & \sin \theta \sin \phi & \cos \theta \\ \cos \theta \cos \phi & \cos \theta \sin \phi & - \sin \theta \\ - \sin \phi & \cos \phi & 0 \end{bmatrix} \begin{bmatrix} \rho \sin \theta \cos \phi \\ \rho \sin \theta \sin \phi \\ \rho \cos \theta \end{bmatrix} \\ &= \begin{bmatrix} \rho \sin^2 \theta \cos^2 \phi + \rho \sin^2 \theta \sin^2 \phi + \rho \cos^2 \theta \\ \rho \sin \theta \cos \theta \cos^2 \phi + \rho \sin \theta \cos \theta \sin^2 \phi - \rho \sin \theta \cos \theta \\ - \rho \sin \theta \sin \phi \cos \phi + \rho \sin \theta \sin \phi \cos \phi + 0 \end{bmatrix} \\ &= \begin{bmatrix} \rho \\ 0 \\ 0\end{bmatrix}. \end{align} So we get $$\mathbf{F} = \rho \boldsymbol{\hat\rho} + 0 \boldsymbol{\hat\theta} + 0 \boldsymbol{\hat{\phi}} = \rho \boldsymbol{\hat{\rho}}$$, just as we argued at the beginning.

• Thank you! This has cleared up my confusion. I think I can take it from here :)
– Kit
Oct 7, 2011 at 7:15
• This is not the correct Jacobian matrix. You have missed the factors of $r$ en.wikipedia.org/wiki/Jacobian_matrix_and_determinant The matrix you are using won’t give the correct tensor transformation law. Isn’t it. Apr 6, 2021 at 9:41
• This is simply not the correct Jacobian matrix which will give the correct tensor transformation law Apr 9, 2021 at 12:16
• @Shashaank, so what is the correct Jacobian matrix? citation please. Dec 2, 2021 at 8:03
• @MichaelLevy it's the one I have linked on the wikipedia page.... Under " Example 3" Dec 3, 2021 at 9:48

Spherical coordinates do not work like this: $$\mathbf{F} = F_{r}\mathbf{\hat r} + F_{\theta}\mathbf{\hat \theta} + F_{\phi}\mathbf{\hat \phi}$$ That would be true if the coordinate system is linear but spherical coordinates aren't. Your formulas are right (except that you need to add $\pi$ to the arctangent if $x$ is negative, and add some specific mechanism to make $\theta=\pm \pi/2$ when $x=0$), but it makes no sense to express the result as a linear combination of basis vectors. There is no such thing as "spherical-coordinate unit vectors".

Instead, write the result simply as a triple $$(r,\theta,\phi)=\left(\sqrt{x^2 + y^2 + z^2},\;\; \tan^{-1} \frac{y}{x},\;\; \cos^{-1} \frac{z}{\sqrt{x^2 + y^2 + z^2}}\right)$$

• "...except that you need to add $\pi$ to the arctangent if $x$ is negative, and add some specific mechanism to make $\theta=\pm \pi/2$ when $x=0$..." - or, use the two-argument arctangent. :) Oct 7, 2011 at 1:36
• I was looking for the process as to how it got to this goo.gl/7fOsb (from Wikipedia), so that $\mathbf{F} = F_x\mathbf{\hat i} + F_y\mathbf{\hat j} + F_z\mathbf{\hat k} = F_{r}\mathbf{\hat r} + F_{\theta}\mathbf{\hat \theta} + F_{\phi}\mathbf{\hat \phi}$.
– Kit
Oct 7, 2011 at 1:37
• @J.M., I'm told that the two-argument arctangent is a totally sick concept and that mathematicians should refuse to adopt it. Oct 7, 2011 at 1:45
• @Kit, the $\hat\rho, \hat\theta, \hat\phi$ in your link are not spherical unit vectors -- they are the base vectors of a (rotated, but nevertheless) rectangular coordinate system. Oct 7, 2011 at 1:47
• As I said in the comments there, Henning, his discomfort might be due to his different notation. I will keep on using two-argument arctangent when situations like polar coordinates keep turning up, but then again I ain't a mathematician... :D Oct 7, 2011 at 1:58

Of all the above questions, I have tried none, of them follow the principle of the book "Engineering Electromagnetics" by Hayt and Buck. You see every time a transformation in vectors is to be done, there is a need for the vector dot product to get the projection from that axis to the required axis and later all of them are summed up while appending the hats or the unit vector directions. Let me use your formula: $$\begin{bmatrix} \hat{\rho} \\ \hat{\theta} \\ \hat{\phi} \\ \end{bmatrix}=\begin{bmatrix} \sin\theta\cos\phi & \sin\theta\sin\phi & \cos\theta \\ \cos\theta\cos\phi & \cos\theta\sin\phi & -\sin\theta \\ -\sin\phi & \cos\phi & 0 \\ \end{bmatrix}\begin{bmatrix} \hat{x} \\ \hat{y} \\ \hat{z} \\ \end{bmatrix}$$. Now for $$\vec{F}=\mathbf{x}\hat{x}+\mathbf{y}\hat{y}+\mathbf{z}\hat{z}$$ , we have a tendency to determine the projections of the $$\hat{\rho}, \hat{\theta}, \hat{\phi}$$ with $$\hat{x}, \hat{y}, \hat{z}$$. $$\vec{F}\cdot\hat{\rho}=\displaystyle \left[\mathbf{x}\hat{x}+\mathbf{y}\hat{y}+\mathbf{z}\hat{z}\displaystyle\right] \cdot \displaystyle \left[ \sin\theta\cos\phi \hat{x} + \sin\theta\sin\phi \hat{y}+ \cos\theta \hat{z} \displaystyle\right]$$ $$=\sin\theta\cos\phi \mathbf{x} + \sin\theta\sin\phi \mathbf{y}+ \cos\theta \mathbf{z}$$.

$$\vec{F}\cdot\hat{\theta}=\displaystyle \left[\mathbf{x}\hat{x}+\mathbf{y}\hat{y}+\mathbf{z}\hat{z}\displaystyle\right] \cdot \displaystyle \left[ \cos\theta\cos\phi \hat{x} + \cos\theta\sin\phi \hat{y}- \sin\theta \hat{z} \displaystyle\right]$$ $$=\cos\theta\cos\phi \mathbf{x} + \cos\theta\sin\phi \mathbf{y}- \sin\theta \mathbf{z}$$.

$$\vec{F}\cdot\hat{\phi}=\displaystyle \left[\mathbf{x}\hat{x}+\mathbf{y}\hat{y}+\mathbf{z}\hat{z}\displaystyle\right] \cdot \displaystyle \left[ \cos\theta\cos\phi \hat{x} + \cos\theta\sin\phi \hat{y}- \sin\theta \hat{z} \displaystyle\right]$$ $$=\cos\theta\cos\phi \mathbf{x} + \cos\theta\sin\phi \mathbf{y}- \sin\theta \mathbf{z}$$. Summing these and putting the unit vectors, we have: $$\vec{F}=\left(\sin\theta\cos\phi \mathbf{x} + \sin\theta\sin\phi \mathbf{y}+ \cos\theta \mathbf{z}\right)\vec{\rho}+\left(\cos\theta\cos\phi \mathbf{x} + \cos\theta\sin\phi \mathbf{y}- \sin\theta \mathbf{z}\right) \vec{\theta}+\left(\cos\theta\cos\phi \mathbf{x} + \cos\theta\sin\phi \mathbf{y}- \sin\theta \mathbf{z}\right) \vec{\phi}.$$ Please DO NOT SUBSTITUTE $$\mathbf{x}$$ or $$\mathbf{y}$$ or $$\mathbf{z}$$. They are given as a general case values. Actually, they are only used with particular problems with specified values. In fact, $$x=r\cos\theta\sin\phi$$, $$y=r\sin\theta\sin\phi$$ and $$z=r\cos\phi$$ were actually used in deriving the expressions for transformation from spherical to cartesian by considering the case of r=1 or in our notations $$\rho=1$$ within the three dimensions of a part of a sphere (1/8)th it's total volume.

Using differential geometry you want to change the basis $$\frac{\partial}{\partial x},\frac{\partial}{\partial y},\frac{\partial}{\partial z}$$ by the normalization of $$\frac{\partial}{\partial r},\frac{\partial}{\partial \theta },\frac{\partial}{\partial \phi }$$ based on the relation

$$(x,y,z)=r(\cos \phi \sin \theta ,\sin \phi \sin \theta ,\cos \theta )$$

for $$(r,\theta ,\phi )\in[0,\infty )\times [0,\pi)\times [0,2\pi)$$. Now, in general, for a change of basis from a coordinate system $$a=(a_1,\ldots ,a_n)$$ to a coordinate system $$b=(b_1,\ldots ,b_n)$$ you have that

$$\frac{\partial}{\partial a_k}=\sum_{j=1}^n\frac{\partial b_j}{\partial a_k}\frac{\partial}{\partial b_j}$$

From there you can compute the matrix of change of coordinates from cartesian to spherical for a vector field, remembering that the spherical coordinates we are using are not normalized. Doing all the calculus yields the given matrix of change of coordinates.

Indeed you have that

$$\begin{bmatrix} F_{\hat r}\\ F_{\hat \theta } \\ F_{\hat \phi } \end{bmatrix} = \begin{bmatrix} \cos \phi \sin \theta & \sin \phi \sin \theta &\cos \theta \\ \cos \phi \cos \theta &\sin \phi \cos \theta &-\sin \theta \\ -\sin \phi &\cos \phi &0 \end{bmatrix} \begin{bmatrix} F_x\\F_y\\F_z \end{bmatrix}$$

for

$$F=F_x\frac{\partial}{\partial x}+F_y\frac{\partial}{\partial y}+F_z\frac{\partial}{\partial z}=F_{\hat r}\frac{\partial}{\partial \hat r}+F_{\hat \phi }\frac{\partial}{\partial \hat \phi} +F_{\hat \theta}\frac{\partial}{\partial \hat \theta }$$

where $$\frac{\partial}{\partial \hat r}=\frac{\partial}{\partial r}$$, $$\frac{\partial}{\partial \hat \theta } =\frac1{r}\frac{\partial}{\partial \theta }$$ and $$\frac{\partial}{\partial \hat \phi } =\frac1{r\sin \theta }\frac{\partial}{\partial \phi }$$ are the normalized spherical coordinates.