BSNS102 Study Guide - Final Guide: Unit Vector, Linear Combination, Linear Interpolation
Document Summary
Chapter 10: orientation and angular displacement in 3d translation into code is more complicated than necessary. The code below shows how we could compute the value of qt. Listing 10. 1: code to raise a quaternion to a power. // check for the case of an identity quaternion. // this will protect against divide by zero if (fabs(w) < . 9999f) { // extract the half angle alpha (alpha = theta/2) float alpha = acos(w); // compute new alpha value float newalpha = alpha * exponent; // compute new w value w = cos(newalpha); // compute new xyz values float mult = sin(newalpha) / sin(alpha); x *= mult; y *= mult; z *= mult; There are a few points to notice about this code. n first, the check for the identity quaternion is necessary, since a value of w = 1 would cause the compututation of mult to divide by zero. This does not create a loss of generality.