Angular distance

Revision as of 12:21, 21 April 2020 by Vegard (talk | contribs) (add general formula for vectors)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

(if and are unit/normalized, then this can be simplified further).

Given two angles and , you could substitute and above, or you could use the following code:

// a0 and a1 are in radians (always positive)
float delta_angle(float a0, float a1)
    return M_PI - fabs(fabs(a1 - a0) - M_PI);