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?

  • 1
    Well, you've essentially given the sketch of how to derive the formula you need; set $\rho=1$ in the conversion formula for spherical coordinates; take the dot product, and get the arccosine to get the angle.2010-11-22
  • 0
    ...and "spherical coordinates" implies you're dealing with $\mathbb R^3$ ...2010-11-22
  • 0
    @J.M. What is the proper name for the "spherical coordinates" when $d > 3$?2010-11-22
  • 0
    ...well, what do your vectors look like in four or more dimensions, first of all?2010-11-22
  • 4
    Some authors refer to "generalized spherical coordinates". See the entry in Glossary of the mapping sciences, p. 117 (e.g. Google Books). The idea is a radius r, an azimuth $\theta$, and n-2 "latitude-like" angles $\phi_1, ... , \phi_{n-2}$, with formulas for Cartesian coordinates in terms of these that generalize the familar relations in 3D (radius times various products of sines and possibly one cosine).2010-11-22
  • 0
    This question could be construed as asking for a d-dimensional generalization of the Haversine formula http://en.wikipedia.org/wiki/Haversine_formula .2010-11-22
  • 0
    I obtained $\alpha =\arccos \frac{N}{D}$ where $\begin{eqnarray*} N &=&u_{x}v_{x}+u_{y}v_{y}+u_{z}v_{z} \\ &=&|\overrightarrow{u}|\sin \theta _{u}\cos \varphi _{u}|\overrightarrow{v}% |\sin \theta _{v}\cos \varphi _{v} \\ &&+|\overrightarrow{u}|\sin \theta _{u}\sin \varphi _{u}|\overrightarrow{v}% |\sin \theta _{v}\sin \varphi _{v} \\ &&+|\overrightarrow{u}|\cos \theta _{u}|\overrightarrow{v}|\cos \theta _{v} \end{eqnarray*}$2010-11-22
  • 0
    and $\begin{eqnarray*} D^{2} &=&(u_{x}^{2}+u_{y}^{2}+u_{z}^{2})(v_{x}^{2}+v_{y}^{2}+v_{z}^{2}) \\&=&[\left( |\overrightarrow{u}|\sin \theta _{u}\cos \varphi _{u}\right)^{2}+\left( |\overrightarrow{u}|\sin \theta _{u}\sin \varphi _{u}\right) ^{2}+\left( |\overrightarrow{u}|\cos \theta _{u}\right) ^{2}] \\ &&\times \lbrack \left( |\overrightarrow{v}|\sin \theta _{v}\cos \varphi _{v}\right) ^{2}+\left( |\overrightarrow{v}|\sin \theta _{v}\sin \varphi _{v}\right) ^{2}+\left( |\overrightarrow{v}|\cos \theta _{v}\right) ^{2}]. \end{eqnarray*}$2010-11-22
  • 0
    I don't know a simpler way, even in $\mathbb{R}^3$.2010-11-22
  • 0
    I (and many of you I suppose) know what three-dimensional spherical coordinates look like; mkolar however has yet to elaborate on what his n-dimensional spherical coordinate data look like so all we can do is speculate until s/he clarifies.2010-11-23
  • 0
    @J.M. I have tried to clarify the notation.2010-11-23
  • 0
    Above I used the wrong notation. What I mean is $u_{\theta},u_{\varphi},v_{\theta},v_{\varphi}$ instead of $\theta_u,\varphi_u,\theta_v,\varphi_v$.2010-11-23
  • 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