Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Michael Kuhn <michakuhn@gm...>  20030723 23:42:17

Hi, I'm trying to set up a vnl_quaternion (representing a rotation) in two different ways. On one hand, I'm trying to set it up directly, i.e. by using the constructor that takes an axis and an angle. On the other hand, I'm trying to create it by vnl_rotation_matrix, which I created using the same axis and angle as before. I noticed, that the quaternions produced by these two construction methods are not equal. The difference is in the orientation of the rotation axis. Can somebody explain me why? To make sure that my explanation is clear enough, I appended the code and output below. Thanks, Michael CODE: ===== (...) double x = 1; double y = 1; double z = 1; double mag = x * x + y * y + z * z; mag = sqrt(mag); x /= mag; y /= mag; z /= mag; double alpha = 40.0 * vnl_math::pi / 180.0; double* vec = new double[3]; vnl_vector<double> axis(3); axis[0] = x; axis[1] = y; axis[2] = z; vnl_quaternion<double> q(axis, alpha); double tmp3 = 2 * acos(q.r()); cout << "q: " << endl; cout << "alpha: " << 180 / vnl_math::pi * tmp3 << endl; cout << "x: " << q.x() / sin(tmp3 / 2) * mag << endl; cout << "y: " << q.y() / sin(tmp3 / 2) * mag << endl; cout << "z: " << q.z() / sin(tmp3 / 2) * mag << endl; cout << endl << endl; axis[0] *= alpha; axis[1] *= alpha; axis[2] *= alpha; vnl_matrix<double> rMat3x3 = vnl_rotation_matrix(axis); vnl_quaternion<double> q2(rMat3x3); double tmp4 = 2 * acos(q2.r()); cout << "q2: " << endl; cout << "alpha: " << 180 / vnl_math::pi * tmp4 << endl; cout << "x: " << q2.x() / sin(tmp4 / 2) * mag << endl; cout << "y: " << q2.y() / sin(tmp4 / 2) * mag << endl; cout << "z: " << q2.z() / sin(tmp4 / 2) * mag << endl; OUTPUT: ======= (...) q: alpha: 40 x: 1 y: 1 z: 1 q2: alpha: 40 x: 1 y: 1 z: 1 Press any key to continue 