Use of Quaternions to replace transformation matrices

Started by
5 comments, last by Zakwayda 17 years, 5 months ago
I'm experimenting with shaders, and thought I could use quaternions instead of transformation matrices. This would reduce data sent from system ram to the video card and multiplications done for each transformation. The only thing I'm not sure how to do is translations. Can quaternions represent translations? Thanks. -Nick
Advertisement
Quote:Original post by nickwinters
Can quaternions represent translations?
No, not on their own. But that's not a problem: just use a quaternion to represent the rotation, and a separate vector to represent the translation.


Quaternion cannot also represent scaling. So you would need two vectors and one quaternion to represent a full transformation which you could do with a single matrix. One vector for translation,one for scaling and the quaternion for rotation. But in the end you will still have to convert the quaternion data to a 3x3 matrix.
Not that it has any practical value, but you can use a (additional) quaternion to represent translation:

Instead of
Q_old_pos := [0, old_pos.x, old_pos.y, old_pos.z]Q_new_pos := Q_rot * Q_old_pos * ~Q_rot[_, new_pos.x, new_pos.y, new_pos.z] := Q_new_posnew_pos := new_pos + trans

use
Q_old_pos := [0, old_pos.x, old_pos.y, old_pos.z]Q_trans := [0, trans.x, trans.y, trans.z]Q_new_pos := Q_rot * Q_old_pos * ~Q_rot + Q_trans[_, new_pos.x, new_pos.y, new_pos.z] := Q_new_pos 


But this is just a "notational trick" and makes no real difference in implementation.
___________________________Buggrit, millennium hand and shrimp!
Quote:Original post by BornToCode
Quaternion cannot also represent scaling. So you would need two vectors and one quaternion to represent a full transformation which you could do with a single matrix. One vector for translation,one for scaling and the quaternion for rotation. But in the end you will still have to convert the quaternion data to a 3x3 matrix.


Quaternions =can= be used to represent uniform scalings:

whereas x -> Q.x.Q* with a unit quaternion Q represents a rotation with centre O, the same transformation with arbitrary Q represents a rotation with centre O combined with a uniform magnification (i.e. an isotropic blow-up or shrink-down) with a magnification factor |Q|^2.

Whenever Q <> 0 (or equivalently: |Q| > 0), the rotation part of this transformation is represented by the unit quaternion Q/|Q|.

With Q = 0, all of 3D space collapses into the single point O.

The practical meaning of all this remains to be seen: who has ever met the 3D space transformation group consisting of 3D displacements combined with uniform magnifications with factors > 0? (all orientation-preserving 3D similarity transformations)
Or with factors <> 0, positive and negative? (all 3D similarity transformations, preserving or reversing orientation)

Johan E. Mebius

Anyone have a code/psuedocode example of how this would be done -- just the rotation. Say I have a cube composed of 4 vertices. How would I rotate it on a given axis using quaternions?
Quote:Original post by drvannostrand

Anyone have a code/psuedocode example of how this would be done -- just the rotation. Say I have a cube composed of 4 vertices. How would I rotate it on a given axis using quaternions?
Assuming you already know how to construct a quaternion representing a given axis-angle rotation, the equation to rotate a vector using a quaternion is then:
v' = q*v*q~
Or:
v' = q~*v*q
Here, q is the quaternion in question, ~ is the conjugate, and v is the vector in quaternion form, that is, stored in the imaginary part of the quat with the real part set to an arbitrary value (typically 0). The first form is the 'mathematically correct' form, but the second is also sometimes used (e.g. in the DirectX math library) to mirror the use of row-vector transforms.

In practice, quaternion rotations are rarely applied this way. Instead, the quaternion is converted to a matrix representing the rotation, and the matrix is used to actually apply the transformation.

This topic is closed to new replies.

Advertisement