# Is there an easy way to transform unit vectors from spherical to Cartesian coordinates? [duplicate]

This question already has an answer here:

How to change coordinates of a differential operator?

2 answers

Is there a built-in function on Mathematica that will transform unit vectors from one coordinate system to another? I have a vector expressed in spherical coordinates, and I would like to find the Cartesian components of the vector, but still express those Cartesian components using (r,θ,ϕ)(r,\theta,\phi). The transformation I am trying to generate is listed below:

ˆx=sinθcosϕˆr+cosθcosϕˆθ−sinϕˆϕ\hat{x}=\sin\theta\cos\phi\,\hat{r}+\cos\theta\cos\phi\,\hat{\theta}-\sin\phi\,\hat{\phi}
ˆy=sinθsinϕˆr+cosθsinϕˆθ+cosϕˆϕ\hat{y}=\sin\theta\sin\phi\,\hat{r}+\cos\theta\sin\phi\,\hat{\theta}+\cos\phi\,\hat{\phi}
ˆz=cosθˆr−sinθˆθ\hat{z}=\cos\theta\,\hat{r}-\sin\theta\,\hat{\theta}

The above uses the physics convention where θ\theta is the polar angle. So basically I would like Mathematica to automatically generate a matrix which looks like this:

(sinθcosϕcosθcosϕ−sinϕsinθsinϕcosθsinϕcosϕcosθ−sinθ0)\left(\begin{array}{ccc}
\sin\theta\cos\phi&\cos\theta\cos\phi&-\sin\phi\\
\sin\theta\sin\phi&\cos\theta\sin\phi&\cos\phi\\
\cos\theta&-\sin\theta&0\\
\end{array}\right)

If I act this matrix on my vector (expressed in spherical coordinates) I will get what I want. Of course I could just type this matrix in myself, but that is not very elegant… The JacobianMatrix command is close, but not quite what I am looking for.

=================

=================

1 Answer
1

=================

CoordinateTransformData[
“Spherical” -> “Cartesian”,
“OrthonormalBasisRotation”,
{1, Î¸, Ï†}
] // MatrixForm

Thanks for the fast reply! Your solution is close, but not quite right — the third column is not quite right.
– Charlie
Feb 25 ’15 at 16:21

I set r = 1 just to conform to your example. You can just use r.
– Taiki
Feb 25 ’15 at 16:22

Sorry. Now the third column is right.
– Taiki
Feb 25 ’15 at 19:05

Taiki,Thank you very much. This works great. I can even put {r,[Theta],[CurlyPhi]} in there and it works. -Charlie
– Charlie
Feb 25 ’15 at 19:49