Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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} $

share|improve this question
2  
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? –  Dan Shved Nov 23 '12 at 12:41
    
@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. –  hkBattousai Nov 23 '12 at 12:44
    
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. –  Dan Shved Nov 23 '12 at 12:47
2  
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. –  hardmath Nov 23 '12 at 12:49
    
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. –  Dan Shved Nov 23 '12 at 12:54

4 Answers 4

up vote 4 down vote accepted

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).

share|improve this answer
1  
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. –  Dan Shved Nov 23 '12 at 18:28
    
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 ;) –  James S. Cook Nov 24 '12 at 1:17
    
The illustration certainly suggests vectors based at the origin. –  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} \ \ \Rightarrow \ \ \nabla r = \frac{1}{r}< x,y,z> \ \ \Rightarrow \ \ u_r = \frac{1}{r}<x,y,z> $$

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 = < \cos \theta \sin \phi, \sin \theta \sin \phi, \cos \phi > $$

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 at http://www.supermath.info/MultivariateCalculus2011TOCandChapter1.pdf (see my section 1.6).

share|improve this answer

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}$$

share|improve this answer
    
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 –  Amzoti Sep 1 '13 at 1:11

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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