ang_diff(ANGLE* a, ANGLE* a1, ANGLE* a2)
Calculates the difference of two Euler angles. When the angle a2 is rotated by the result angle a, it ends up at a1.
Parameters:
a1 - destination angle.
a2 - initial angle.
a - angle difference between a1 and a2.
Speed:
Medium
Remarks:
- ang_diff is not the same as vec_diff. The difference of three-dimensional angles can not be calculated by a mere subtraction, but requires matrix operations (see ang_to_matrix for an example).
As infinitely many different rotations can go from the same start angles to the same end angles, the result angle a is normally not fully determined by this operation, but has still one degree of freedom.
-
A7.82 The resulting pan, tilt, roll angles are in the -180..+180 range, so their signs can be used to determine whether the rotation is clockwise or counterclockwise.
Example (lite-C):
// Calculate an angle that aligns an axis to a vector
// (see also the ang_for_axis example for a different method)
function ang_align(ANGLE* ang,VECTOR* to,VECTOR* axis)
{
ANGLE axis_angle,target_angle;
vec_to_angle(axis_angle,axis); // f.i. (0,0,1) for the vertical axis
vec_to_angle(target_angle,to); // target angle to align to
ang_diff(ang,target_angle,axis_angle); // rotate angle by the difference of the axis and vector
}
See also:
pan, tilt, roll,
vec_to_angle,
ang, ang_for_axis,
ang_rotate, vec_diff
► latest version online