Frequently
Asked Questions
If you use matrix from Shoemake
paper you have to be careful as it represents rotation by q-1 rather
than q and because of that some signs are reversed (the paper defines rotation
by quaternion as v’ = q-1*v*q).
Use the formulas on pages (253, 254) of Shoemake paper to compute sin and cos for all angles.
Then
use atan2 function to compute the angles:
m_real x = atan2( sinx, cosx );
m_real y = atan2( siny, cosy );
m_real z = atan2( sinz, cosz );
All the formulas for computing an and bn using quaternion representation are given in Shoemake paper (page 249).
The formulas are correct. We implemented the algorithm using the formulas in the paper and it works.
Couple
of things to make sure:
Yes. It is correct. I implemented it. Below is my implementation. It exactly follows formulas in the paper.
quater
EulerAngle2Quater( vector const& v )
{
quater q;
float cosX = cos(v.x()/2.0);
float cosY = cos(v.y()/2.0);
float cosZ = cos(v.z()/2.0);
float sinX = sin(v.x()/2.0);
float sinY = sin(v.y()/2.0);
float sinZ = sin(v.z()/2.0);
q.set_w(cosX*cosY*cosZ +
sinX*sinY*sinZ);
q.set_x(sinX*cosY*cosZ -
cosX*sinY*sinZ);
q.set_y(cosX*sinY*cosZ +
sinX*cosY*sinZ);
q.set_z(cosX*cosY*sinZ -
sinX*sinY*cosZ);
return q;
}