Maths - Affine Conversion - Matrix to Quaternion/Vector

Definition of terms:

It you want to consider the rotation only then the code for this is shown here.

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:

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 here.

= 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

metadata block
see also:


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.

cover 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 and axis-angle.

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2017 Martin John Baker - All rights reserved - privacy policy.