Definition of terms:
It you want to consider the rotation only then the code for this is shown
Alternatively if we want to consider the possibility that there is also a translation
from the centre, and that the rotation may not be about the centre but may be
about some arbitrary point, then we need to extend the notation as follows:
- A 3D vector has to be added to the quaternion so that together they can
specify the position and orientation.
- The matrix has to be increased from 3x3 to 4x4 so that it can specify the
position and orientation. (as explained
Rotation about a point other than origin
Quaternions and 3x3 matrices alone can only represent rotations about the origin.
But if we include a 3D vector with the quaternion we can use this to represent
the point about which we are rotating. Also if we use a 4x4 matrix then this
can hold a translation (as explained
here) and therefore can specify a rotation about a point.
The following code generates a 3D vector (representing the centre of rotation)
from the 4x4 matrix. The theory is given
||= 1/det[m] *
|(m11 - 1)*m22 - m12*m21
||m02*m21 - m01*(m22 - 1)
||m01*m12 - m02*(m11 - 1)
|m12*m20 - m10*(m22 - 1)
||m00*(m22 - 1) - m02*m20
||m02*m10 - (m00 - 1)*m12
|m10*m21 - (m11 - 1)*m20
||m01*m20 - (m00 - 1)*m21
||m00*(m11 - 1) - m01*m10
|Correspondence about this page
Book Shop - Further reading.
Where I can, I have put links to Amazon for books that are relevant to
the subject, click on the appropriate country flag to get more details
of the book or to buy it from them.
If you are interested in 3D games, this looks like a good book to have on the
shelf. If, like me, you want to have know the theory and how it is derived then
there is a lot for you here. Including - Graphics pipeline, scenegraph, picking,
collision detection, bezier curves, surfaces, key frame animation, level of detail,
terrain, quadtrees & octtrees, special effects, numerical methods. Includes
CDROM with code.
3D Game engine design also includes conversions between matrix, quaternions
Commercial Software Shop
Where I can, I have put links to Amazon for commercial software, not
directly related to the software project, but related to the subject being
discussed, click on the appropriate country flag to get more details of
the software or to buy it from them.
This site may have errors. Don't use for critical systems.