Lossy conversion Matrix -> Quaternion -> Matrix
I have a box defined by 8 points. From those points, I calculate开发者_JAVA百科 axes and create rotation matrix as follows:
axis[0], axis[1], axis[2]
mat =
{
axis[0].x axis[1].x axis[2].x 0
axis[0].y axis[1].y axis[2].y 0
axis[0].z axis[1].z axis[2].z 0
0 0 0 1
}
I have particular rotation matrix:
{
-1 0 0 0
0 0 1 0
0 -1 0 0
0 0 0 1
}
As best of my knowledge, this is a valid rotation matrix. Its inversion is equal to its transposition.
Now I would like to store this matrix as a quaternion. But later, I need rotation matrix to be recreated from this quaternion. I believe that convertsion from matrix to quaternion and back to matrix should be an identity transform and I should get the same matrix that I had in the beginning (maybe with very small numerical errors).
But this seems not to be the case. Both SlimDX (C#) and my propertiary math library (C++) return invalid matrix.
First, quaternion that I receive:
C#: 0, 0, 0.70710676908493, 0
C++: 0, -0.707107, 0, 0
And matrix created from this quaternion:
C#:
0 0 0 0
0 0 0 0
0 0 1 0
0 0 0 1
C++:
0 0 0 0
0 1 0 0
0 0 0 0
0 0 0 1
Why is this wrong?
I've also tried this: http://cache-www.intel.com/cd/00/00/29/37/293748_293748.pdf but it gave me bad results as well.
The matrix you gave isn't a rotation matrix, it's a reflection matrix because its determinant is -1. See the definition on Wikipedia. You can tell something isn't right because you should get a unit quaternion, and yet the one you're getting back only has length 1/sqrt(2).
Try using a 4x4 matrix. I'm not matrix math expert, but I've never used 3x3 matrices when dealing with 3D graphics. I believe the extra dimension is for normalization, or something like that.
精彩评论