Angular distance

From vegard.wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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:

// 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);
}