If I create a rotation matrix from an identity quaternion then it is the same as a creating it from a negative identity quaternion
Matrix m0 = Matrix.CreateFromQuaternion(Quaternion.Identity);
Matrix m1 = Matrix.CreateFromQuaternion(-Quaternion.Identity);
Console.WriteLine(m0);
Console.WriteLine(m1);
Console.WriteLine(m0.Forward); // {X:0 Y:0 Z:-1}
Console.WriteLine(m1.Forward); // {X:0 Y:0 Z:-1}
Why is this the case?
If I use a negative identity matrix
Quaternion q0 = Quaternion.CreateFromRotationMatrix(Matrix.Identity);
Quaternion q1 = Quaternion.CreateFromRotationMatrix(-Matrix.Identity);
the orientation will be rotated 180 degrees as expected.
Answer
Although rotation-matrices and unit-quaternions both can represent an orientation/rotation in 3D space, that does not mean that negating each of its individual terms will result in the same geometrical operation.
1. Negating each number of a unit-quaternion
There are always 2 unit-quaternions that represent a single unique orientation. One on each hemisphere of the hypersphere, pointing directly away from each other. In other words, each component of such quaternion is simply negated, however, both represent the same orientation.
Here are 2 examples:
Identity-Quaternion:
axis : 0.000 0.000 0.000
w : 1.000
magnitude: 1.000 rad: 0.000 deg: 0.000
Negated Identity-Quaternion:
axis : -0.000 -0.000 -0.000
w : -1.000
magnitude: 1.000 rad: 6.283 deg: 360.000
Above you see both, the identity quaternion and its negated quaternion. The first 3 numbers (axis, x, y, z -> the imaginary part) can be interpreted as the rotation axis. The acos of the 4th number (w) multiplied by 2 is the angle of rotation. Since the rotation axis is basically zero, there is no rotation at all, no matter how big the actual angle is. So both are the same, no rotation change at all.
Another example of a unit-quaternion and its negated quaternion:
Q:
axis : 0.397 0.555 0.159
w : 0.714
magnitude: 1.000 rad: 1.552 deg: 88.919
Q negated:
axis : -0.397 -0.555 -0.159
w : -0.714
magnitude: 1.000 rad: 4.731 deg: 271.081
Here you see the rotation axis is basically the same, only negated. The angle changed from 89 to 271, which is the same orientation in a circle, just counter-clockwise (360-89 == 271) So again, if you check the numbers properly, "Q" and "Q negated" will result in the same orientation. So the bottom line is:
Negating each term of a unit-quaternion will result in the same rotation, not in a rotation of 180 degrees
2. Negating each term of an identity-matrix
-Matrix.Identity
is not a rotation matrix anymore, it is a reflection matrix. Hence, this is no valid input for CreateFromRotationMatrix
, it will return a result however, but that is not correct, as that function only works with valid input. So negating each term in a rotation matrix will not result in a rotation of 180 degrees.
No comments:
Post a Comment