# How to calculate angle between two directions on sphere

There are four points on sphere with latitude/longitude coordinates: ${a}_1, {a}_2, {b}_1, {b}_2$. How to calculate an angle between two vectors on sphere: $a = \overline{{a}_1{a}_2}, b =\overline{{b}_1{b}_2}$ (each directions are great circle)?

The following formula comes to mind: $$a \cdot b = ||a||\,||b|| \cos \theta$$ However, I am not sure how to express it via lat/long coordinates.

1. Convert each lat/lon pair $(\phi,\lambda)$ into 3D coordinates $(\cos\phi\sin\lambda,\cos\phi\cos\lambda,\sin\phi)$
2. After this conversion, compute the cross products $u=a_1\times a_2$ and $v=b_1\times b_2$
3. The angle between $u$ and $v$, as obtained from $\cos\angle (u,v)=\frac{u\cdot v}{|u||v|}$, is also the angle between the planes perpendicular to $u$ and $v$, respectively, and also the angle between the great circles in these planes (i.e., through $a_1,a_2$ and through $b_1,b_2$, respectively) at the points where these great circles intersect.