4 added 149 characters in body edited Jul 27 '12 at 16:20 Robert Fraser 67733 gold badges1414 silver badges3131 bronze badges I'm getting different signs when I convert a matrix to quaternion and invert that, versus when I invert a matrix and then get the quaternion from it: Quaternion q1a = Quaternion.Invert(getRotation(m)); Quaternion q2b = getRotation(Matrix.Invert(m)); Quaternion a = someOtherQuaternion * q1; Quaternion b = someOtherQuaternion * q2;  QuaternionsI would expect a and b are nearlyto be identical (within the tolerancesor inverses of floating point matheach other). However, which I would expectit looks like q1 = (x, except they, signs of X-z, Y-w) while q2 = (-x, Z-y, and W are differentw, z). This makes my rotations goIn other words, the wrong direction or flail wildly aroundZ and W components have been switched for some reason. Why is this? Am I losing data somewhere? Note: getRotation() decomposes the transform matrix and returns just the rotation part of it (I've tried normalizing the result; it does nothing). The matrix m is a complete transform matrix and contains a translation (and possibly a scale) as well as a rotation. I'm using D3DXMatrixDecompose to do the actual decomposition. EDIT: some more investigation... it looks like a = (-x, y, -z, w) while b = (-x, -y, z, w) .... So only the y and z components are inverted. Wut? I'm getting different signs when I convert a matrix to quaternion and invert that, versus when I invert a matrix and then get the quaternion from it: Quaternion q1 = Quaternion.Invert(getRotation(m)); Quaternion q2 = getRotation(Matrix.Invert(m)); Quaternion a = someOtherQuaternion * q1; Quaternion b = someOtherQuaternion * q2;  Quaternions a and b are nearly identical (within the tolerances of floating point math), which I would expect, except the signs of X, Y, Z, and W are different. This makes my rotations go the wrong direction or flail wildly around. Why is this? Am I losing data somewhere? Note: getRotation() decomposes the transform matrix and returns just the rotation part of it (I've tried normalizing the result; it does nothing). The matrix m is a complete transform matrix and contains a translation (and possibly a scale) as well as a rotation. I'm using D3DXMatrixDecompose to do the actual decomposition. EDIT: some more investigation... it looks like a = (-x, y, -z, w) while b = (-x, -y, z, w) .... So only the y and z components are inverted. Wut? I'm getting different signs when I convert a matrix to quaternion and invert that, versus when I invert a matrix and then get the quaternion from it: Quaternion a = Quaternion.Invert(getRotation(m)); Quaternion b = getRotation(Matrix.Invert(m));  I would expect a and b to be identical (or inverses of each other). However, it looks like q1 = (x, y, -z, -w) while q2 = (-x, -y, w, z). In other words, the Z and W components have been switched for some reason. Note: getRotation() decomposes the transform matrix and returns just the rotation part of it (I've tried normalizing the result; it does nothing). The matrix m is a complete transform matrix and contains a translation (and possibly a scale) as well as a rotation. I'm using D3DXMatrixDecompose to do the actual decomposition. 3 added 149 characters in body edited Jul 27 '12 at 16:15 Robert Fraser 67733 gold badges1414 silver badges3131 bronze badges I'm getting different signs when I convert a matrix to quaternion and invert that, versus when I invert a matrix and then get the quaternion from it: Quaternion q1 = Quaternion.Invert(getRotation(m)); Quaternion q2 = getRotation(Matrix.Invert(m)); Quaternion a = someOtherQuaternion * q1; Quaternion b = someOtherQuaternion * q2;  Quaternions a and b are nearly identical (within the tolerances of floating point math), which I would expect, except the signs of X, Y, Z, and W are different. This makes my rotations go the wrong direction or flail wildly around. Why is this? Am I losing data somewhere? Note: getRotation() decomposes the transform matrix and returns just the rotation part of it (I've tried normalizing the result; it does nothing). The matrix m is a complete transform matrix and contains a translation (and possibly a scale) as well as a rotation. I'm using D3DXMatrixDecompose to do the actual decomposition. EDIT: some more investigation... it looks like a = (-x, y, -z, w) while b = (-x, -y, z, w) .... So only the y and z components are inverted. Wut? I'm getting different signs when I convert a matrix to quaternion and invert that, versus when I invert a matrix and then get the quaternion from it: Quaternion q1 = Quaternion.Invert(getRotation(m)); Quaternion q2 = getRotation(Matrix.Invert(m)); Quaternion a = someOtherQuaternion * q1; Quaternion b = someOtherQuaternion * q2;  Quaternions a and b are nearly identical (within the tolerances of floating point math), which I would expect, except the signs of X, Y, Z, and W are different. This makes my rotations go the wrong direction or flail wildly around. Why is this? Am I losing data somewhere? Note: getRotation() decomposes the transform matrix and returns just the rotation part of it (I've tried normalizing the result; it does nothing). The matrix m is a complete transform matrix and contains a translation (and possibly a scale) as well as a rotation. I'm using D3DXMatrixDecompose to do the actual decomposition. I'm getting different signs when I convert a matrix to quaternion and invert that, versus when I invert a matrix and then get the quaternion from it: Quaternion q1 = Quaternion.Invert(getRotation(m)); Quaternion q2 = getRotation(Matrix.Invert(m)); Quaternion a = someOtherQuaternion * q1; Quaternion b = someOtherQuaternion * q2;  Quaternions a and b are nearly identical (within the tolerances of floating point math), which I would expect, except the signs of X, Y, Z, and W are different. This makes my rotations go the wrong direction or flail wildly around. Why is this? Am I losing data somewhere? Note: getRotation() decomposes the transform matrix and returns just the rotation part of it (I've tried normalizing the result; it does nothing). The matrix m is a complete transform matrix and contains a translation (and possibly a scale) as well as a rotation. I'm using D3DXMatrixDecompose to do the actual decomposition. EDIT: some more investigation... it looks like a = (-x, y, -z, w) while b = (-x, -y, z, w) .... So only the y and z components are inverted. Wut? 2 added 148 characters in body edited Jul 27 '12 at 12:42 Robert Fraser 67733 gold badges1414 silver badges3131 bronze badges I'm getting different signs when I convert a matrix to quaternion and invert that, versus when I invert a matrix and then get the quaternion from it: Quaternion q1 = Quaternion.Invert(getRotation(m)); Quaternion q2 = getRotation(Matrix.Invert(m)); Quaternion a = someOtherQuaternion * q1; Quaternion b = someOtherQuaternion * q2;  Quaternions a and b are nearly identical (within the tolerances of floating point math), which I would expect, except the signs of X, Y, Z, and W are different. This makes my rotations go the wrong direction or flail wildly around. Why is this? Am I losing data somewhere? Note: getRotation() decomposes the transform matrix and returns just the rotation part of it (I've tried normalizing the result; it does nothing). The matrix m is a complete transform matrix and contains a translation (and possibly a scale) as well as a rotation. I'm using D3DXMatrixDecompose to do the actual decomposition. I'm getting different signs when I convert a matrix to quaternion and invert that, versus when I invert a matrix and then get the quaternion from it: Quaternion q1 = Quaternion.Invert(getRotation(m)); Quaternion q2 = getRotation(Matrix.Invert(m)); Quaternion a = someOtherQuaternion * q1; Quaternion b = someOtherQuaternion * q2;  Quaternions a and b are nearly identical (within the tolerances of floating point math), which I would expect, except the signs of X, Y, Z, and W are different. This makes my rotations go the wrong direction or flail wildly around. Why is this? Am I losing data somewhere? Note: getRotation() decomposes the transform matrix and returns just the rotation part of it (I've tried normalizing the result; it does nothing). The matrix m is a complete transform matrix and contains a translation (and possibly a scale) as well as a rotation. I'm getting different signs when I convert a matrix to quaternion and invert that, versus when I invert a matrix and then get the quaternion from it: Quaternion q1 = Quaternion.Invert(getRotation(m)); Quaternion q2 = getRotation(Matrix.Invert(m)); Quaternion a = someOtherQuaternion * q1; Quaternion b = someOtherQuaternion * q2;  Quaternions a and b are nearly identical (within the tolerances of floating point math), which I would expect, except the signs of X, Y, Z, and W are different. This makes my rotations go the wrong direction or flail wildly around. Why is this? Am I losing data somewhere? Note: getRotation() decomposes the transform matrix and returns just the rotation part of it (I've tried normalizing the result; it does nothing). The matrix m is a complete transform matrix and contains a translation (and possibly a scale) as well as a rotation. I'm using D3DXMatrixDecompose to do the actual decomposition. 1 asked Jul 27 '12 at 12:04 Robert Fraser 67733 gold badges1414 silver badges3131 bronze badges