How do we interpolate between two quaternions representing rotations? For instance we may want to fill in some gaps between calculated rotations to make an animation less jerky.

if q is the quaternion which
rotates from qa to qb then:

qb = qa * q

multiplying both sides by conj(qa) gives:

q = conj(qa) * qb

The real part of a multiplication is:

real((qa.w + i qa.x + j qa.y + k qa.z)*(qb.w + i qb.x + j qb.y + k qb.z)) =
qa.w * qb.w - qa.x*qb.x - qa.y*qb.y- qa.z*qb.z

So using the conjugate of qa gives:

real((qa.w - i qa.x - j qa.y - k qa.z)*(qb.w + i qb.x + j qb.y + k qb.z)) =
qa.w*qb.w + qa.x*qb.x + qa.y*qb.y+ qa.z*qb.z

real(q) = cos(t/2)

Therefore

cos(theta/2) = qa.w*qb.w + qa.x*qb.x + qa.y*qb.y+ qa.z*qb.z

(It is interesting that this looks like a vector dot product).

So what is the equation that allows us to calculate the interpolated quaternion?

There seems to be a paper about this which everyone quotes: [Ken Shoemake, Animating rotation with quaternion curves in SIGGraph '85 proceedings]. However this seems to require membership so I have not read this.

where:

- qm = interpolated quaternion
- qa = quaternion a (first quaternion to be interpolated between)
- qb = quaternion b (second quaternion to be interpolated between)
- t = a scalar between 0.0 (at qa) and 1.0 (at qb)
- θ is half the angle between qa and qb

How do we convert from cos(theta) to sin(theta)

is it best to use:

sin(theta) = sin(acos(cos(theta)))

or

sin(theta) = sqrt(1-cos(theta)^{2})

## Example 2Let us take the 90 degree rotation in example 1 on transforms page and calculate two interpolated points. ## First method: axis-angleSince the angles are simple we can calculate the result from q = cos(t/2) + i ( x1 * sin(t/2)) + j (y1 * sin(t/2)) + k ( z1 * sin(t/2)) So the quaternions represented the two interpolated points are: q1 = 0.966 + i 0 + j 0 + k 0.259 q2 = 0.866 + i 0 + j 0 + k 0.5 ## Second method: using SLERPTry spherical interpolating between the rotated value (0.7071 + k 0.7071) and the non-rotated, identity, value (1). theta = 90 degrees using the above method cos(theta) = 0.7071 therefore theta = 45 degrees sin(theta) = 1 for q1 t = 0.33, for q2 t = 0.66 q1 = ((1) sin ((1-t) theta) + (0.7071 + k 0.7071) sin (t theta)) / sin(theta ) = (sin(30 degrees) + (0.7071 + k 0.7071) sin (15 degrees)) / sin( 45 degrees) q1 =( 0.5 + 0.7071 * 0.2588 + k (0.7071 * 0.2588))/0.7071 q1 = (0.68299748 + k 0.18299748 )/0.7071 q1 = 0.9659 + k 0.2588 This is theresult for q1, now calculate the result for q2, q2 = ((1) sin ((1-t) theta) + (0.7071 + k 0.7071) sin (t theta)) / sin(theta ) = ((1) sin(15 degrees) + (0.7071 + k 0.7071) sin (30 degrees)) / sin( 45 degrees) q2 = (0.2588 + 0.7071* 0.5 + k (0.7071* 0.5))/0.7071 q2 = (0.61235 + k 0.35355) /0.7071 q2 = 0.866 + k 0.5 this gives gives the same answer, but only if theta = angle between quaternions /2 |