I was writing a C++ class for working with 3D vectors. I have written operations in the Cartesian coordinates easily, but I'm stuck and very confused at spherical coordinates. I googled my question but couldn't find a direct formula for vector product in the search results.

Assume that I have $ \overrightarrow{V_1} $ and $ \overrightarrow{V_2} $ vectors in shperical coordinates:

$ \overrightarrow{V_1} = r_1\hat{u_r} + \theta_1\hat{u_\theta} + \phi_1\hat{u_\phi} \\ \overrightarrow{V_2} = r_2\hat{u_r} + \theta_2\hat{u_\theta} + \phi_2\hat{u_\phi} \\ \hat{u_r}: \mbox{the unit vector in the direction of radius} \\ \hat{u_\theta}: \mbox{the unit vector in the direction of azimuthal angle} \\ \hat{u_\phi}: \mbox{the unit vector in the direction of polar angle} $

$ \theta $ and $ \phi $ angles are as represented in the image below:
spherical coordinates

What is the general formula for taking dot and cross products of these vectors?

$ \overrightarrow{V_1} \bullet \overrightarrow{V_2} = ? \\ \overrightarrow{V_1} \times \overrightarrow{V_2} = ? $

If you need an example, please work on this one:

$ \overrightarrow{V_1} = 2\hat{u_r} + \frac{\pi}{3}\hat{u_\theta} + \frac{\pi}{4}\hat{u_\phi} \\ \overrightarrow{V_2} = 3\hat{u_r} + \frac{\pi}{6}\hat{u_\theta} + \frac{\pi}{2}\hat{u_\phi} $

  • 2
    $\begingroup$ Why don't you just convert to Cartesian coordinates, call the operation in Cartesian coordinates that you've already implemented, and convert the result back to spherical coordinates? $\endgroup$ – Dan Shved Nov 23 '12 at 12:41
  • $\begingroup$ @DanShved: I can prefer working in Cartesian coordinates if it is guarantied to be faster. Coordinate conversion is also a lot of work which involves calling some trigonometric functions. First, I need to see the formula in spherical coordinates and compare it to the one in Cartesian coordinates. $\endgroup$ – hkBattousai Nov 23 '12 at 12:44
  • $\begingroup$ Well, I'm not ready to write down that formula, but I guarantee that multiplication in spherical coordinates will also involve trigonometry. To derive the formula, you'd still have to do what I said in my first comment, except you'd have to do it by yourself with pen and paper instead of some C++ code. In any case, multiplication of vectors will be faster in Cartesian coordinates. $\endgroup$ – Dan Shved Nov 23 '12 at 12:47
  • 4
    $\begingroup$ Your premise seems to be that "spherical coordinates" permit vectors to be expressed as linear combinations of three unit vectors, the first of which you say is a unit vector in the direction of the radius. I'm afraid this makes no sense. Radius $r$ appears as a scalar multiple in spherical coordinates. $\endgroup$ – hardmath Nov 23 '12 at 12:49
  • $\begingroup$ A simple illustration: the dot product $(a,b)$ of vector $a$ with spherical coordinates $(r,\theta,\phi)=(1, 0, 0)$ and vector $b$ with spherical coordinates $(r,\theta,\phi)=(1, 0, \varphi_0)$ is $\cos(\varphi_0)$. Clearly, you'll need to calculate a cosine to get this result. $\endgroup$ – Dan Shved Nov 23 '12 at 12:54

Here are two ways to derive the formula for the dot product. I assume that $v_1$ and $v_2$ are vectors with spherical coordinates $(r_1, \varphi_1, \theta_1)$ and $(r_2, \varphi_2, \theta_2)$.

First way: Let us convert these spherical coordinates to Cartesian ones. For the first point we get Cartesian coordinates $(x_1, y_1, z_1)$ like this: $$ \begin{array}{rcl} x_1 & = & r_1 \sin \varphi_1 \cos \theta_1, \\ y_1 & = & r_1 \sin \varphi_1 \sin \theta_1, \\ z_1 & = & r_1 \cos \varphi_1. \end{array} $$ Similar formulas hold for $(x_2, y_2, z_2)$. Now, the dot product is simply equal to $$ (v_1, v_2) = x_1 x_2 + y_1 y_2 + z_1 z_2 = \\ = r_1 r_2 ( \sin \varphi_1 \sin \varphi_2 ( \cos \theta_1 \cos \theta_2 + \sin \theta_1 \sin \theta_2) + \cos \varphi_1 \cos \varphi_2) = \\ = r_1 r_2 ( \sin \varphi_1 \sin \varphi_2 \cos (\theta_1 - \theta_2) + \cos \varphi_1 \cos \varphi_2) $$

Second way: Actually, we could have done it without coordinate conversions at all. Indeed, we know that $(v_1, v_2) = r_1 r_2 \cos \alpha$, where $\alpha$ is the angle between $v_1$ and $v_2$. But $\cos \alpha$ can be immediately found by the Spherical law of cosines, which yields exactly the same formula that we just proved. Basically, our first way is itself a proof for the spherical law of cosines.

PS: I'm not saying anything about cross products, but my guess is that the correct formula will look terrible. Not only will it contain sines and cosines, it is likely that it will also contain arc functions (they will appear when we try to convert the result back to spherical coordinates). Unless those arc functions magically cancel out with all the sines and cosines. But it is highly unlikely, and I don't feel like going through the trouble of checking.

PPS: One more thing. Cross products are not the only scary thing about spherical coordinates. If you think about it, even addition of two vectors is extremely unpleasant in spherical coordinates. Multiplication by a number is alright though, because it only changes $r$ and doesn't affect $\varphi$ and $\theta$ (at least when we multiply by a positive number).

  • 3
    $\begingroup$ Alright, just to clarify how this is different from James S. Cook's answer. In my answer by spherical coordinates of a vector I mean the spherical coordinates of its endpoint if its starting point is placed at the origin. James's answer, on the other hand, deals with usual coordinates of tangent vectors at a certain point $p$ with respect to a specific basis of the tangent space at this point. Somehow using letters $r_i,\varphi_i,\theta_i$ makes me think that OP actually means coordinates in the former sense, not the latter. But I can be wrong. $\endgroup$ – Dan Shved Nov 23 '12 at 18:28
  • $\begingroup$ right, I don't know which context he actually needs for his application. As a general principle it is better to calculate in coordinates which resemble the natural symmetry of a given system. I think your advice to do more pen paper thinking before coding is probably the best advice in this thread ;) $\endgroup$ – James S. Cook Nov 24 '12 at 1:17
  • $\begingroup$ The illustration certainly suggests vectors based at the origin. $\endgroup$ – hardmath Nov 24 '12 at 19:18

Since $u_r,u_{\phi},u_{\theta}$ forms a right handed orthonormal frame of unit vectors the rules for computing vectors at a point $p$ expressed in the frame at $p$ is precisely the same as that for the globally constant Cartesian frame. For example,

$$ \vec{V}_1 \cdot \vec{V}_2 = 2(3)+\frac{\pi}{3}\frac{\pi}{6}+\frac{\pi}{4}\frac{\pi}{2} $$

More generally, if we count $u_1,u_2,u_3$ as $u_r,u_{\phi},u_{\theta}$ then I can define dot and cross products by the usual formulas:

$$ u_i \cdot u_j = \delta_{ij} \qquad u_i \times u_j = \sum_k \epsilon_{ijk} u_k $$

The vectors $u_i$ are not fixed vectors like $e_1,e_2,e_3$ or perhaps you prefer $\hat{i},\hat{j},\hat{k}$, the $u_r,u_{\phi},u_{\theta}$ are vector fields. You can construct them by normalizing the gradient vector fields of the spherical coordinate functions if you wish to know what their formulas are explicitly in terms of the Cartesian frame.

$$ r = \sqrt{x^2+y^2+z^2} \ \ \implies \ \ \nabla r = \frac{1}{r}\langle x,y,z\rangle \ \ \implies \ \ u_r = \frac{1}{r}\langle x,y,z\rangle $$

In view of $x = r\cos \theta \sin \phi, y = r\sin \theta \sin \phi, z = r\cos \phi$ the spherical unit vector field is given by:

$$ u_r = \langle \cos \theta \sin \phi, \sin \theta \sin \phi, \cos \phi \rangle $$

a formula which is totally unsurprising if you think about the unit-sphere and the geometric relation between a normal to the sphere and the radial direction to any point further away (or closer) the origin.

I have much more posted here (see my section 1.6).

  • $\begingroup$ But isn't $u_r,u_{\phi},u_{\theta}$ are associated with a particular point $p$? So if you take the dot product of two different vectors $V_1$ and $V_2$ which are expressed in spherical coordinates, I was wondering why could we simply compute it exactly in the same way as we do in the cartesian coordinates? $\endgroup$ – IgNite May 22 '16 at 12:19
  • $\begingroup$ @Ignite Because the coordinate system set up by the spherical frame at a given point is geometrically identical to that of the $xyz$-coordinate system. However, if you concern yourself with questions of differentiation which involve varying over a nbhd of points then there are big differences. For example, look up the formulas for grad, curl, div or Laplacian in non-Cartesian coordinates. $\endgroup$ – James S. Cook May 22 '16 at 12:39
  • $\begingroup$ Oh, I got it already. Just confused a little bit. By two different vectors $V_1$ and $V_2$ I mean two vectors which point to different points $p_1$ and $p_2$. But thanks for your answer, this will be helpful for my study. $\endgroup$ – IgNite May 22 '16 at 13:55

I refer you (and new readers) to Introduction to Electrodynamics by D.J. Griffiths, third edition, page 39.

  • 1
    $\begingroup$ I think the relevant quote from Griffiths here would be the following: "In general, if you're uncertain about the validity of an operation, reexpress the problem in Cartesian coordinates, where this difficulty does not arise". $\endgroup$ – David Schwartz Apr 8 '15 at 3:23

EDIT: this answer is only defined if the two vectors are defined at the same point in space, because spherical polar unit vectors change with poisition.

So if you have one point ($r$,$\theta$,$\phi$) which has defined $\mathbf{\hat r}$, $\mathbf{\hat \theta}$ and $\mathbf{\hat \phi}$, and two vectors coming out of that point, then the dot product is: $$ \mathbf V \cdot \mathbf U = V_rU_r + V_\phi U_\phi + V_\theta U_\theta $$

For the cross product take the determinant of the matrix with unit vectors and components, the same way you would for cartesian coordinates: $$ \mathbf V \times \mathbf U = \begin{vmatrix} \mathbf{\hat r}&\mathbf{\hat \phi}& \mathbf{\hat \theta}\\ V_r &V_\phi &V_\theta\\ U_r & U_\phi & U_\theta \end{vmatrix} $$

For example $$\mathbf{\hat r} \times \mathbf{\hat \phi} = \begin{vmatrix} \hat r &\hat \phi& \hat \theta\\ 1 &0 &0\\ 0 & 1 & 0 \end{vmatrix} = \hat \theta $$


In spherical coordinates:

$$ X_1 \cdot X_2 = r_1r_2\left(\cos(\theta_1)\cos(\theta_2) + \cos(\phi_1-\phi_2)\sin(\theta_1)\sin(\theta_2)\right)$$

$$X_1 \times X_2=r_1r_2\begin{pmatrix} \sin(\theta_1)\sin(\phi_1)\cos(\phi_2)-\cos(\phi_1)\sin(\phi_2)\sin(\theta_2)\\ \left(\sin(\theta_2)-\sin(\theta_1)\right)\cos(\phi_1)\cos(\phi_2)\\ \sin(\theta_1)\sin(\theta_2)\sin(\phi_2-\phi_1)\end{pmatrix}$$

  • $\begingroup$ Welcome to MSE! It really helps readability to format using Mathjax (see FAQ). it might also help to describe where these came from or how they were derived. Regards $\endgroup$ – Amzoti Sep 1 '13 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.