Game Development Reference
In-Depth Information
Finally, we present the complete rotation matrix constructed from a
quaternion:
2
3
1 − 2y 2 − 2z 2
Converting a quaternion
to a 3 × 3 rotation
matrix
2xy + 2wz
2xz − 2wy
4
5
1 − 2x 2 − 2z 2
2xy − 2wz
2yz + 2wx
.
(8.20)
2xz + 2wy
2yz − 2wx
1 − 2x 2 − 2y 2
Other variations can be found in other sources. 17 For example m 11 =
−1 + 2w 2 + 2z 2 also works, since w 2 + x 2 + y 2 + z 2 = 1. In deference
to Shoemake, who brought quaternions to the attention of the computer
graphics community, we've tailored our derivation to produce the version
from his early and authoritative source [62].
8.7.4
Converting a Matrix to a Quaternion
To extract a quaternion from the corresponding rotation matrix, we reverse
engineer Equation (8.20). Examining the sum of the diagonal elements
(known as the trace of the matrix) we get
tr( M ) = m 11 + m 22 + m 33
= (1 − 2y 2 − 2z 2 ) + (1 − 2x 2 − 2z 2 ) + (1 − 2x 2 − 2y 2 )
= 3 − 4(x 2 + y 2 + z 2 )
= 3 − 4(1 − w 2 )
= 4w 2 − 1,
and therefore we can compute w by
m 11 + m 22 + m 33 + 1
2
w =
.
The other three elements can be computed in a similar way, by negating
two of the three elements in the trace:
− m 33 = (1−2y 2 −2z 2 ) − (1−2x 2 −2z 2 ) − (1−2x 2 −2y 2 )
= 4x 2 − 1, (8.21)
−m 11 + m 22 − m 33 = −(1−2y 2 −2z 2 ) + (1−2x 2 −2z 2 ) − (1−2x 2 −2y 2 )
= 4y 2 − 1,
m 11
− m 22
(8.22)
17 Including the first edition of this topic [16].
 
Search WWH ::




Custom Search