312 GPGPU Programming for Games and Science
}
}
else
{
if (r11 >=r22) // u1 ˆ2 l ar g es t −magnitude
{
U = (( r10 + r01 )/2 , r11 + 1 , ( r12 + r21 )/2 );
}
else // u2 ˆ2 la rg es t −magnitude
{
U = (( r20 + r02 )/2 , ( r21 + r12 )/2 , r22 + 1);
}
}
Normalize(U);
LISTING 6.35: Determining the largest-magnitude component of U from
the products of components.
Numerical bias is avoided by averaging the off-diagonal terms, ensuring the
results are the same for R or R
T
. It does not matter that the normalization
computes a positive entry in U corresponding to the specially computed diag-
onal entry. For a rotation by π radians, R(U,π)andR(−U,π)arethesame
rotation matrix.
6.3.6.5 Axis-Angle to Quaternion
This conversion is simple. The quaternion angle is half the rotation ...