Signed spherical angle between two great circle arcs

spherical coordinatesspherical trigonometrytrigonometry

I am trying to calculate the signed spherical angle between two intersecting great circle arcs. In my specific case, I am considering a unit sphere ($r=1$). The first great circle arc goes from $A(\lambda_A, \phi_A)$ to $B(\lambda_B, \phi_B)$, while the second great circle arc goes from $B$ (the intersection point) to $C(\lambda_C, \phi_C)$. Here, $\lambda$ is longitude, or the angle with the reference meridian, while $\phi$ is latitude, or the angle with respect to the equatorial plane, like is the case in the geographic coordinate system.

My spherical coordinates are related to cartesian coordinates as follows:
$$ x = \cos(\lambda) \cos(\phi) $$
$$ y = \sin(\lambda) \cos(\phi) $$
$$ z = \sin(\phi) $$

The reference meridian is thus described by $y=0, x>0$ and the equatorial plane is defined as $z=0$.

I can calculate the angle between $AB$ and $BC$. First, I describe $A$, $B$, $C$ as cartesian vectors, e.g. $$\vec{A}= \big(\cos(\lambda_A) \cos(\phi_A),\ \sin(\lambda_A) \cos(\phi_A),\ \sin(\phi_A) \big).$$ Then I take the cross products $\vec{V_{ab}} = \vec{A}\times\vec{B}$ and $\vec{V_{bc}} = \vec{B}\times\vec{C}$. Then I take the angle between these two vectors (which describe the planes that the great circle arcs $AB$ and $BC$ respectively lie on):

$$\text{spherical angle}(AB, BC) = \frac{\vec{V_{ab}}\cdot \vec{V_{bc}}}{ ||\vec{V_{ab}}||\cdot ||\vec{V_{bc}}||}. $$

However, I want the signed spherical angle, so that the angle that $AB$ forms with $BC$ is defined clockwise between $[0, 2\pi]$.

Note: Perhaps it helps to say that $A$ in my specific case is the North Pole, i.e. $A = (0, 0, 1)$ or equivalently $\lambda_A = \frac{1}{2}\pi$. A solution that works for this particular case is fine as well.

The correct approach should thus for $A(0,\frac{1}{2}\pi)$, $B(0,0)$ and $C(\frac{1}{2}\pi, 0)$ output $\frac{1}{2}\pi$, while for $C(-\frac{1}{2}\pi, 0)$ it should output $\frac{3}{2}\pi$ (or equivalently $-\frac{1}{2}\pi$)

Best Answer

I figured out that I can check on which side $\vec{C}$ lies with respect to the plane formed by $\vec{V_{ab}}$ using the dot product $\vec{V_{ab}} \cdot \vec{C}$ and that I can make the output negative or positive depending on that.