13
$\begingroup$

Given two vectors $u, v \in \mathbb{R}^d$ represented the spherical coordinates is there a simple formula to compute the angle between the two vectors? Without loss of generality, we can assume that the vectors $u$ and $v$ have unit norm.

I am not sure that the following notation is standard, but I assume that the vector $u$ is defined with $\rho = 1$ and the angular components $\theta_1, \ldots, \theta_{d-1}$. We can obtain the Euclidean components as follows: $u_{x_1} = \cos \theta_1$ $u_{x_2} = \sin \theta_1 \cos \theta_2$ $\ldots$ $u_{x_{d-1}} = \sin \theta_1 \ldots \sin \theta_{d-2} \cos \theta_{d-1}$ $u_{x_d} = \sin \theta_1 \ldots \sin \theta_{d-2} \sin \theta_{d-1}.$

One way to find the angle is to represent the two vectors in the Euclidean coordinates and compute arccos of the dot product. Is there a simpler way?

As pointed out in comments, is there a generalization of the Haversine formula?

  • 0
    @J.M. I'm slightly curious what you mean by that. To me 'spherical coordinates' + 'n > 3' immediately brings to mind expanding the angular components much like spherical extends polar coordinates. Since it's evidently not the only interpretation - what other ways are there?2016-10-17

4 Answers 4

4

Here is a recursive idea that might work. Let $s_1$, $s_2$,..., $s_{n-1}$ the sines of the angles of the first vector on $S^{n-1}$, $c_1$, ..., the cosines, and s'_{\nu} and c'_{\nu} those for the second one. With $p$ being the scalar product, we have $p=1$ for $n=1$, p=c c'+s s' for $n=2$ and generically p(n)=c_1 c'_1 + s_1 s'_1 p(n-1) where $p(n-1)$ is the scalar product of the vectors given by the angles $[\theta_2,...]$ and [\theta'_2,...] on $S^{n-1}$(i.e. by removing the first angle of each sequence).

This, of course, still requires all sines and cosines, but my idea is to simplify $p(n-2)$ using the haversine formula and hope that this reduces the number of calls to trigoniometric functions.

2

Simple, alternative derivation of Ralf's formula, without the guesswork:

Angle between the vectors: $\alpha = \arccos\left({{u \cdot v}\over{|u| |v|}}\right)$ $u \cdot v = \sum_i u_i v_i $ in hyper-spherical coordinates (n+1 dimensions, hence n angles): $u_i(n) = |u| \cos(\theta_i) \prod_{j=1}^{i-1}{\sin(\theta_j)} $ except when i=n: $u_n(n) = |u| \prod_{j=1}^{n}{\sin(\theta_j)} $ and similar for v (I will use $\phi$ for the angles of v).

With unit vectors we combine the three formulae to: $\cos(\alpha) = \sum_{i=1}^{n-1}{\cos(\theta_i)\cos(\phi_i) \prod_{j=1}^{i-1}{\sin(\theta_j)\sin(\phi_j)}} + \prod_{i=1}^{n}{\sin(\theta_j)\sin(\phi_j)} $ which can be written as a recursive rule: $\cos(\alpha)_n = \cos(\theta_{n-1})\cos(\phi_{n-1}) \cos(\alpha)_{n-1} + \prod_{j=1}^{n}{\sin(\theta_j)\sin(\phi_j)} $

Which is similar to what Ralf's answer contains (cos/sin switched).

0

Perhaps a change to a different basis in spherical coordinates could make the problem simpler, or even lead to a direct solution. For example, if you want to know the angle subtended by the arc from NYC to Cleveland, you could slide the lat/long lines until the prime meridian passed through both cities, and one was on the equator.

Of course, when you start out with what seems like a different approach, you often find yourself doing the same arithmetic.

0

Let's not overthink. We can assume that the length of each vector is 1. Figure the (x,y,z) locations of the vectors, and then the Euclidean distance, d, between them. Then the angle is one angle of an isosceles triangle with two sides = 1 and one side = d.

  • 0
    ... and this is nothing more than a re-statement of what Americo Tavares wrote in his comments dated Nov 22, 2010. `:-)`2011-04-15