Game Development Reference
In-Depth Information
− m 22 + m 33 = −(1−2y 2 −2z 2 ) − (1−2x 2 −2z 2 ) + (1−2x 2 −2y 2 )
= 4z 2 − 1,
−m 11
(8.23)
m 11
− m 22
− m 33 + 1
x =
,
(8.24)
2
−m 11 + m 22
− m 33 + 1
y =
,
(8.25)
2
−m 11
− m 22 + m 33 + 1
2
z =
.
(8.26)
Unfortunately, we cannot use this trick for all four components, since
the square root will always yield positive results. (More accurately, we have
no basis for choosing the positive or negative root.) However, since q and
q represent the same orientation, we can arbitrarily choose to use the
nonnegative root for one of the four components and still always return a
correct quaternion. We just can't use the above technique for all four values
of the quaternion.
Another line of attack is to examine the sum and difference of diagonally
opposite matrix elements:
m 12 + m 21 = (2xy + 2wz) + (2xy − 2wz) = 4xy,
(8.27)
m 12 − m 21 = (2xy + 2wz) − (2xy − 2wz) = 4wz,
(8.28)
m 31 + m 13 = (2xz + 2wy) + (2xz − 2wy) = 4xz,
(8.29)
m 31
− m 13 = (2xz + 2wy) − (2xz − 2wy) = 4wy,
(8.30)
m 23 + m 32 = (2yz + 2wx) + (2yz − 2wx) = 4yz,
(8.31)
m 23
− m 32 = (2yz + 2wx) − (2yz − 2wx) = 4wx.
(8.32)
Armed with these formulas, we develop a two-step strategy. We first
solve for one of the components from the trace, using one of Equations (8.21)-
(8.26). Then we plug that known value into Equations (8.27)-(8.32) to solve
for the other three. Essentially, this strategy boils down to selecting a row
from Table 8.2 and then solving the equations in that row from left to right.
The only question is, “Which row should we use?” In other words,
which component should we solve for first? The simplest strategy would be
to just pick one arbitrarily and always use the same procedure, but this is
no good. Let's say we choose to always use the top row, meaning we solve
for w from the trace, and then for x, y, and z with the equations on the right
side of the arrow. But if w = 0, the divisions to follow will be undefined.
Even if w > 0, a small w will produce numeric instability. Shoemake [62]
suggests the strategy of first determining which of w, x, y, and z has the
largest absolute value (which we can do without performing any square
roots), computing that component using the diagonal of the matrix, and
then using it to compute the other three according to Table 8.2.
Search WWH ::




Custom Search