Postby **Yakk** » Sat May 08, 2010 3:42 pm UTC

Proof of the quaternion rotation identity in particular.

cos alpha/2 + u sin alpha/2 is the quaternion that represents a rotation (clockwise) by angle alpha around axis u.

I'm using the scalar+vector notation for quaternions. Ie, the quaternion (a,b,c,d) is represented as a + (b,c,d). (I hadn't seen it before reading wiki, but I sort of like it). I'm also using bold face to indicate single letters that represent vectors.

In this notation, if we have a + u times b + v, we do the following:

ab + av + bu + u v

but where we use a special multiplication for the vector multiplication:

u v = u x v - < u, v >

where < , > is the dot product and x is the cross product. There are a myriad different ways to define the quaternion multiplication, I just agree with the wiki article that the above is pretty.

Some of what you describe in the OP is fundamentally wrong. Quaternions that are used to represent rotations are unit quaternions. They contain no components that scale up to pi.

A 90 degree rotation around the (1,0,0) axis would look like:

(1/rt(2), 1/rt(2), 0, 0) in 4-vector notation, or

1/rt(2) + (1/rt(2), 0, 0) in scalar+vector notation.

squaring it (180 degree rotation) gives us:

1/2 + (1/2,0,0) + (1/2,0,0) + (1/rt(2),0,0)x(1/rt(2),0,0) - 1/2

= 0 + (1,0,0)

squaring this (a 360 degree rotation) gives us:

0 + 0 + 0 + (1,0,0)x(1,0,0) - 1

= -1, (0,0,0)

Notice the singularity! Here is the other one:

and squaring that (a 720 degree rotation) gives us:

1+ 0 + 0 + 0 x 0 - 0

= 1 + (0,0,0)

Make any sense?

So to extract the axis and angle from a quaternion, first calculate the inverse cos of the first component. Then double. That is the angle of rotation. Now rescale the last 3 components by 1/sqrt(1-first component squared), or by 1/sin(alpha/2) (same difference). Or you could just take the unit vector along the direction of the last 3 components. Note that the singularity (where sin(alpha/2) is 0) that exists here corresponds to no rotation at all. You'll have to be careful when programming this, because of the numerical instability around rotations that are really small could screw you up. (ie, if you take the 1000th root of a quaternion (!) then scale it back up by ^1000, things can get wonkey...)

Then again, taking roots of quaternions gets interesting: there is a fundamental instability problem, because the nth root of a quaternion is any quaternion that, when raised to the power of n, gives the original value.

If you know your complex nth roots of unity, you'll see the problem here. The same situation falls out here. Maybe worse? I cannot recall.

One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.