Converting a Vector Field from cylindrical to spherical coordinates: what is the correct transformation matrix?

721 Views Asked by At

I'm having a bit of trouble with what I thought was a simple task.
I have a vector field expressed in cylindrical coordinates, $\vec{B}=(B_R,\ B_\phi,\ B_z)$, and I want to describe it in spherical coordinates, $\vec{B}=(B_\rho,\ B_\theta,\ B_\varphi)$. Here $R$ is the cylindrical radius, $\phi$ the polar angle, $\rho$ is the spherical radius, $\theta$ is the latitude and $\varphi$ is the longitude. x, y and z are the usual cartesian coordinates.

In order to do this, I decided to transform first the vector to cartesian coordinates and then transforming the cartesian expression in spherical coordinates. I used the transformation matrices found in this wikipedia page: \begin{equation} \left[\begin{array}{c} B_x\\ B_y\\ B_z \end{array}\right] = \left[ \begin{array}{ccc} \cos\varphi & -\sin\varphi & 0 \\ \sin\varphi & \cos\varphi & 0 \\ 0 & 0 & 1 \end{array}\right] \left[\begin{array}{c} B_R\\ B_\phi\\ B_z \end{array}\right],\ (1) \end{equation}

\begin{equation} \left[\begin{array}{c} B_\rho\\ B_\theta\\ B_\varphi \end{array}\right] = \left[ \begin{array}{ccc} \sin\theta\cos\varphi & \sin\theta\sin\varphi & \cos\theta \\ \cos\theta\cos\varphi & \cos\theta\sin\varphi & -\sin\theta \\ -\sin\varphi & \cos\varphi & 0 \end{array}\right] \left[\begin{array}{c} B_x\\ B_y\\ B_z \end{array}\right],\ (2) \end{equation}

\begin{equation} \rho=\sqrt{R^2+z^2}=\sqrt{x^2+y^2+z^2},\\ \theta=\text{atan2}\left(\dfrac{z}{R}\right)=\text{atan2}\left(\dfrac{z}{\sqrt{x^2+y^2}}\right),\\ \varphi\equiv\phi=\text{atan2}\left(\dfrac{y}{x}\right). \end{equation} I have obtained this relationship between the spherical and the cylindrical components of my vector: \begin{equation} \left[\begin{array}{c} B_\rho\\B_\theta\\B_\varphi \end{array}\right]= \left[\begin{array}{c} B_R\sin\theta+B_z\cos\theta\\B_R\cos\theta-B_z\sin\theta\\B_\varphi \end{array}\right]= \left[\begin{array}{c} B_R\sin\left(\text{atan2}\left(\dfrac{z}{R}\right)\right) + B_z\cos\left(\text{atan2}\left(\dfrac{z}{R}\right)\right)\\ B_R\cos\left(\text{atan2}\left(\dfrac{z}{R}\right)\right) - B_z\sin\left(\text{atan2}\left(\dfrac{z}{R}\right)\right) \\B_\varphi \end{array}\right].\ (3) \end{equation}

Am I done? I'm wondering this because, when trying to plot components and field lines of the "converted" vector, I struggle to recognize the original one. I suspect the unit vectors could be playing a role here, however on this matter wikipedia doesn't help me.
Searching on this site, I found this question from 10 years ago. The accepted answer uses the same transformation matrix I used, but comments from last year (2021) tell a different story. According to those comments, I should use the (inverse of the) Jacobian matrix written in examples 2 and 3 of this other wikipedia page (caution, here $\theta$ and $\varphi$ are switched), so that equations (1) and (2) should be instead (with the same $\theta,\varphi$ connotation used in (1) and (2)):

\begin{equation} \left[\begin{array}{c} B_x\\ B_y\\ B_z \end{array}\right] = \left[ \begin{array}{ccc} \cos\varphi & -R\sin\varphi & 0 \\ \sin\varphi & R\cos\varphi & 0 \\ 0 & 0 & 1 \end{array}\right] \left[\begin{array}{c} B_R\\ B_\varphi\\ B_z \end{array}\right],\ (4) \end{equation}

\begin{equation} \left[\begin{array}{c} B_\rho\\ B_\theta\\ B_\varphi \end{array}\right] = \left[ \begin{array}{ccc} \sin\theta\cos\varphi & \sin\theta\sin\varphi & \cos\theta\\ \rho\cos\theta\cos\varphi & \rho\cos\theta\sin\varphi & -\rho\sin\theta\\ -\rho\sin\theta\sin\varphi & \rho\sin\theta\cos\varphi & 0 \end{array}\right] \left[\begin{array}{c} B_x\\ B_y\\ B_z \end{array}\right].\ (5) \end{equation}

Which of these are the correct transformation matrices? If neither of these, where can I find the answer? Is expression (3) correct and I just need to find a way to properly visualize the field in the new frame or am I missing the correct transformations for the unit vectors?