Get Euler angles from rotation matrix.
Angles = eulang(Rp) [alpha,beta,gamma] = eulang(Rp)
Given a rotation matrix
Rp
, the function eulang
computes the
Euler angles
defining the same rotation and returns them
separately or as a 3-element vector Angles = [alpha, beta, gamma]
.
The angles are in radians.
For details about Euler angles and rotation matrices, see the page on relative orientations.
The rotation matrix must be a 3x3 real matrix with determinant +1 to within 0.1, otherwise the function errors. For smaller deviations, a warning is issued.
Since (α,β,γ) and (α+/-π,-β,γ+/-π)
describe the same rotation, there is more than one set of Euler angles
that give the same rotation matrix. eulang
returns the one with positive
β.
In the special cases β=0 and β=π, the
rotation axes for α and γ coincide, and the
two angles cannot be distinguished. In this case eulang
sets
γ to zero and describes the entire z rotation by
α.
eulang
detemines the Euler angles by least-squares fitting,
starting from angles analytically extracted from a few
elements of the given rotation matrix.
Taking three arbitrary angles, we compute the rotation matrix
ang = [34 72 -143]*pi/180; R = erot(ang)
R = 0.1319 -0.6369 0.7595 0.6008 -0.5581 -0.5724 0.7885 0.5318 0.3090
Now, feeding this rotation matrix into eulang
,
we get back the three original angles.
eulang(R)*180/pi
ans = 34.0000 72.0000 -143.0000