07.01.2013 Views

3D graphics eBook - Course Materials Repository

3D graphics eBook - Course Materials Repository

3D graphics eBook - Course Materials Repository

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Quaternions and spatial rotation 135<br />

Conversion to and from the matrix representation<br />

From a quaternion to an orthogonal matrix<br />

The orthogonal matrix corresponding to a rotation by the unit quaternion (with |z| = 1) is<br />

given by<br />

From an orthogonal matrix to a quaternion<br />

Finding the quaternion that corresponds to a rotation matrix can be numerically<br />

unstable if the trace (sum of the diagonal elements) of the rotation matrix is zero or very small. A robust method is to<br />

choose the diagonal element with the largest value. Let uvw be an even permutation of xyz (i.e. xyz, yzx or zxy).<br />

The value<br />

will be a real number because . If r is zero the matrix is the identity matrix, and the<br />

quaternion must be the identity quaternion (1, 0, 0, 0). Otherwise the quaternion can be calculated as follows: [3]<br />

Beware the vector convention: There are two conventions for rotation matrices: one assumes row vectors on the left;<br />

the other assumes column vectors on the right; the two conventions generate matrices that are the transpose of each<br />

other. The above matrix assumes column vectors on the right. In general, a matrix for vertex transpose is ambiguous<br />

unless the vector convention is also mentioned. Historically, the column-on-the-right convention comes from<br />

mathematics and classical mechanics, whereas row-vector-on-the-left comes from computer <strong>graphics</strong>, where<br />

typesetting row vectors was easier back in the early days.<br />

(Compare the equivalent general formula for a 3 × 3 rotation matrix in terms of the axis and the angle.)<br />

Fitting quaternions<br />

The above section described how to recover a quaternion q from a 3 × 3 rotation matrix Q. Suppose, however, that<br />

we have some matrix Q that is not a pure rotation — due to round-off errors, for example — and we wish to find the<br />

quaternion q that most accurately represents Q. In that case we construct a symmetric 4×4 matrix<br />

and find the eigenvector (x,y,z,w) corresponding to the largest eigenvalue (that value will be 1 if and only if Q is a<br />

pure rotation). The quaternion so obtained will correspond to the rotation closest to the original matrix Q [4]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!