What is the general formula for calculating dot and cross products in spherical coordinates? 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:

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} $
 A: 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
$$
A: I refer you (and new readers) to Introduction to Electrodynamics by D.J. Griffiths, third edition, page 39. 
A: 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).
A: 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).
A: 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}$$
