There are always tow different set of three Euler angles that yield the same rotation matrix
It does no matter what convection is used there will always be a difference.
If you do this :
- Code: Select all
dVector euler (30.0f * 3.1416f/ 180.0f, 145.0f * 3.1416f/ 180.0f, 145.0f * 3.1416f/ 180.0f, 0.0f);
dMatrix m (dPitchMatrix(euler.m_x) * dYawMatrix(euler.m_y) * dRollMatrix(euler.m_z));
dVector euler1 (m.GetEulerAngles());
dMatrix m1 (dPitchMatrix(euler1.m_x) * dYawMatrix(euler1.m_y) * dRollMatrix(euler1.m_z));
the result is this
- Code: Select all
euler {m_x=0.52359998 m_y=2.5307333 m_z=2.5307333}
euler1 {m_x=-2.6179926 m_y=0.61085927 m_z=-0.61085927}
but if yo umak eteh substitution
- Code: Select all
pitchangle = pitchangle - pi
yawangle = pi - yawangle
rollchangle = rollchangle – pi
you will see that
euler = euler1
but not knowing that yaw was in some other quadrant it is impossible to determine the desired solution.
A trick that you can do is using a memory the save the last value of the angles, decompose the delta matrix not the absolute matrix, then by using trig you can actually have the derided values all the time.
Basically what you do is that you save the previous matrix.
Then you the new matrix is compose uf this
M1 = M * M0
M0 is the previus matrix,
Ml is some local matrix
M is the new matrix,
The you do this
M = M1 * inv(M0)
Now you calculate the euler angle of M
Tehi will be the small angle thet will be in the firs quadrant every time so you know that they is not ambiguity.
Now to recostun the eler angles
You do this
Yaw = Ya0 + deltYaw
And by using equivalence n
Cos (Ya0 + deltYaw) and Sin (Ya0 + deltYaw) and
Yaw = atan2 (Cos (Ya0 + deltYaw), Sin (Ya0 + deltYaw))
And similar for Roll and pitch
You can have the angles all in an unlimited space, not just form [-180 < angle < 180]
If it is confusing to you, I can write you a function to do that if you and add it to the dMatrix class. Are you using the dMatrix class?
It will be a function like this,
dVector GetEulerAngles(dVector& initalEulerAngles)