By: thejaybird (thejaybird) - 2008-01-09 11:33 |
| I've
been using this method for many years but have never seen it published
anywhere. It's not necessarily the fastest method, but is the most
elegant IMO. On modern platforms with SIMD and shuffling, it's very
fast. Matrix44 CreateRotation(const Quaternion& quat) { Matrix44 m1( quat.w, quat.z, -quat.y, quat.x, -quat.z, quat.w, quat.x, quat.y, quat.y, -quat.x, quat.w, quat.z, -quat.x, -quat.y, -quat.z, quat.w ); Matrix44 m2( quat.w, quat.z, -quat.y, -quat.x, -quat.z, quat.w, quat.x, -quat.y, quat.y, -quat.x, quat.w, -quat.z, quat.x, quat.y, quat.z, quat.w ); return m1 * m2; } It calculates the product of two simple matrices. The matrices have some very interesting features. Notice that they are identical and symmetric, except for the distribution of negations. The upper 3x3 is the same for both matrices, whereas the 4th row and column are transposed. I've put quite a bit of effort into finding ways to exploit that last bit of apparent symmetry/similarity, but haven't been able to simplify it any further. If anyone has any insight into this, I would be very keen to hear it. Note that it's assumed the quaternion is unit length. Otherwise, the resulting matrix will be scaled. |
| This is very interesting, I don't know why this works, My first guess is that it might be related to either: * constructing a rotation from two reflections? * Pauli matricies? but I can't make either work at the moment, perhaps someone else can help? I would like to put this on the web page, It this alright with you? If so how would you like to be named: thejaybird? Thanks, Martin 2 reflections ------------- A single reflection in a line Px,Py,Pz is given by the symmetrical(including signs) matrix: -Px² + Pz²+ Py² - 2 * Px * Py - 2 * Px * Pz - 2 * Py * Px -Py² + Px² + Pz² - 2 * Py * Pz - 2 * Pz * Px -2 * Pz * Py -Pz² + Py² + Px² So could each of the 4x4 matricies be related to a reflection? I can't make this work. Pauli matricies --------------- The Pauli matricies usually represent i,j,k as: 0 -i i 0 0 1 1 0 1 0 0 -1 but we can also expand this out to a 4x4 version (I'm not sure I've got the signs correct): 0 0 +1 0 | 0 0 0 1 | 0 +1 0 0 0 0 0 -1 | 0 0 1 0 | +1 0 0 0 -1 0 0 0 | 0 1 0 0 | 0 0 0 -1 0 +1 0 0 | 1 0 0 0 | 0 0 -1 0 We can take a linear combination of these (with the identity matrix) to give somthing like: +w x +y +z +x w +z -y -y z +w -x +z y -x +w So we can transform points by using the 'sandwich product' like: p' = [M][p][M]^t I was wondering if there is some rule we could use to reverse the order to give some variation of: [M][M]^t |
By: thejaybird (thejaybird) - 2008-01-10 16:09 |
| Yes, please go ahead and put it up on the website, by all means. You can use my real name, Jay Ryness. I don't have much to add, but I am reminded of some work I was doing years ago with geometric algebra. In GA, the product of two multivectors can be implemented as a 4x4 matrix multiplication, where the operands look basically like the multivector was scrambled into a 4x4 matrix not too unlike the operands in the quaternion product above, except that a multivector in GA has 8 scalar components rather than 4, and I think some of the expressions in the matrix may have been slightly more involved than a simple negation, but not much. Anyway, rotors (which are a specialized form of multivectors, where 4 of the 8 scalar components happen to be zero--I'm sure know all this stuff much better than I) are, IIRC, isomorphic to quaternions, or close enough. I haven't verified it, but I would venture to guess that if one were to write out the GA product of two rotors as a 4x4 matrix multiplication, it would simplify to something very similar if not identical to the quaternion product implementation above. It's also worth noting that rotors are logically constructed as the composition of two reflections, and all of this is tightly coupled with complex numbers, quaternions, Pauli matrices and the like. So, I think you're definitely on a good track with your approach. I should point out that I'm not a mathematician and it's been years since I delved into this stuff, and furthermore I'm shooting from the hip, so take my abstract mathematical observations for what they're worth. Anyway, thanks for taking an interest. I'll be keeping an eye out for developments. -Jay |
Follow up message
Following this thread Tim Meehan has kindly sent me a message telling me that this article on Wikipedia has a section on isoclinic decomposition about how a quaternion can be converted to a 4x4 matrix by performing matrix multiplication on two simpler 4x4 matricies.
I think this sheds light on the subject and my intuition tells me this is important, I'll have to give this some thought.








