Angular distance

In general, the smallest angle (angular distance) between two vectors is given by:

${\displaystyle a=\cos ^{-1}{\frac {A\cdot B}{\left|A\right|\cdot \left|B\right|}}}$

(if ${\displaystyle A}$ and ${\displaystyle B}$ are unit/normalized, then this can be simplified further).

Given two angles ${\displaystyle a_{0}}$ and ${\displaystyle a_{1}}$, you could substitute ${\displaystyle A=\left[\cos a_{0},\sin a_{0}\right]}$ and ${\displaystyle B=\left[\cos a_{1},\sin a_{1}\right]}$ above, or you could use the following code:

// https://gamedev.stackexchange.com/a/4472
// a0 and a1 are in radians (always positive)
float delta_angle(float a0, float a1)
{
return M_PI - fabs(fabs(a1 - a0) - M_PI);
}