I’m having some trouble with my quaternion rotation class that I thought I’d figured out long ago, but now that I’m carefully checking the numbers, it’s not working as I expect. The issue is I want to move between rotations and angular velocities easily, and my rotation class uses quaternions for the internal representation. The math is straightforward and laid out in many different references:

w = ( 2 / dt * ( q1 - q0 ) * q0^-1 ).xyz;

q1 = q0 + dt * 1/2 * ( <wx,wy,wz,0> * q0 )

These equations relate an initial rotation quaternion q0, a final rotation quaterntion q1, a timestep dt, and an angular velocity 3-vector w. So now let’s look at an example in detail.

// identity rotation

q0 = <0,0,0,1>

// 90 degrees about x-axis

q1 = <0.707,0,0,0.707>

dt = 1

From the first equation (derivative, outputs angular velocity), I’d expect to get <1.571,0,0> - 90 degrees about the x-axis per unit time. But let’s step through the equation:

// component-wise subtraction

q1 - q0 = <0.707,0,0,-0.293>

// inverse of identity is identity

q0^-1 = q0

// multiply by identity

( q1 - q0 ) * q0^-1 = <0.707,0,0,-0.293>

2 / dt = 2

// multiply by scalar

2 * ( ( q1 - q0 ) * q0^-1 ) = <1.414,0,0,-0.586>

So w = <1.414,0,0>, which is *81* degrees about the x-axis! The same problem happens when integrating. If I set w = <1.571,0,0> (90 degrees about x-axis), dt = 1, and q0 = <0,0,0,1>, the output q1 = <0.618,0,0,0.786>, which is *76* degrees about the x-axis.

And of course, the sanity check is that I should be able to take the derivative and then the integral and get the original result back, but if I start with

q0 = <0,0,0,1>

q1 = <0.707,0,0,0.707>

dt = 1

I get after the derivative and then integral

w = <1.414,0,0>

q1’ = <0.577,0,0,0.816>

Which is only 70 degrees about the x-axis (so the errors from derivation and integration aren’t symmetric - they accumulate instead of cancelling out).

What’s going on? Anyone have some insight? Thanks!

-stephen diverdi