# Angle difference between 2 directions in 3d

I have a view direction in 3d space described with 2 values: Horizontal and Vertical (x and y) ranging the full 360 degrees (from -180 to +180), thus describing every possible view direction.

It seems fairly straight forward to me, that the angle between (0,0) and (5,0) would be 5 degrees.

But what is the angle between (0,0) and (5,5). If it was 2 points in 2d I would use Pythagoras theorem; having the difference be sqrt(5^2 + 5^2). But I don't think that would apply in 3d? How do I go about calculating the angle between these 2 directions?

This has likely been asked before, but I probably don't know the correct wording. I assume the "view directions" should be calculated as vectors, but I'm not sure how.

Thanks

• It's not clear how $x$ and $y$ define a direction in the first place. Can you give more details about your intended representation? It is more common to describe directions in 3D using a 3D unit vector, i.e. three coordinates $x$, $y$, and $z$ such that $x^2+y^2+z^2=1$. – Rahul Oct 3 '18 at 8:19
• Also, how would Pythagoras (in 2d) give you an angle? – Jaap Scherphuis Oct 3 '18 at 8:44
• Maybe look at the wiki page for great-circle distance. – Jaap Scherphuis Oct 3 '18 at 8:48
• @Rahul Imagine a fixed point of reference being (0,0) - 0 degrees horizontal, 0 degrees vertical. Now, if the point of view turns 5 degrees "right" along the horizontal axis, this could now be described as (5,0). When we then turn the point of view further "up" along the vertical axis, this would now be (5,5). My question is: What is the angle between (0,0) and (5,5)? – Scherling Oct 3 '18 at 10:54
• First, one thing you have to be careful about is that the way you describe it, the order of rotation matters: turning "right" 5 degrees and then "up" 5 degrees is different from turning "up" 5 degrees and then "right" 5 degrees. This is hard to visualize, but easier if you think about what happens when rotating 90 degrees each time. If you are clear that this situation is what you want, and which rotation should be done first, then you can apply Hugo's formula. – Rahul Oct 3 '18 at 11:14

If I understood well, by a "direction" ($$\phi, \theta)$$ (I assume the angles between $$0$$ and $$2 \pi$$) you mean the unit vector $$u(\phi, \theta) = (\cos \theta \cos \phi, \cos \theta \sin \phi, \sin \theta)$$. The angle $$\alpha$$ between $$u(\theta, \phi)$$ and $$u(\theta', \phi')$$ may be calculated by taking the scalar product $$u(\theta, \phi) \cdot u(\theta', \phi')$$ as follows: $$\cos \alpha = \cos \theta \cos \theta' (\cos \phi \cos \phi' + \sin \phi \sin \phi') + \sin \theta \sin \theta' = \cos \theta \cos \theta' \cos (\phi-\phi') + \sin \theta \sin \theta',$$ hence $$\alpha = \cos^{-1} (\cos \theta \cos \theta' \cos (\phi-\phi') + \sin \theta \sin \theta')$$
• The best way is to see all this on a globe. In my computations, $\phi$ is the longitude, between 0 (Greenwich) and $2\pi$ (Greenwich again), and $\theta$ is the latitude, between $-\pi$ (South pole) and $+\pi$ (North pole). Hope it's clearer now. – Hugo Oct 3 '18 at 12:20
• The angle is the une given by my formula, where $\theta$ is the latitude and $\phi$ the longitude. – Hugo Oct 4 '18 at 12:08