johnbakers
johnbakers

Reputation: 24771

Can a quaternion represent more than 360 degrees of rotation?

I like Euler rotation based on degrees so I can keyframe an animation of a large number of degrees, like 1000, and get multiple full 360-degree revolutions on the object for purposes of setting it spinning, etc.

However I'm at a point now when I was working on something that involved a lot of consecutive animations among two different axes that I think I'm seeing the effects of gimbal lock. When I perform one of the chained animations, my object keeps flipping 180 degrees after it completes a 90-degree rotation. Does this sound like gimbal lock? It only happens after other prior and successful rotations along different axes.

In any case, I tried switching to Quaternions but it appears that quaternions aren't suited for this spinning effect, since they just get you an orientation and they treat a multiple of 360 as 0 using this:

template <typename T>
 inline QuaternionT<T>  QuaternionT<T>::CreateFromAxisAngle(const Vector3<T>& axis, float radians)
 {
QuaternionT<T> q;
q.w = std::cos(radians / 2);
q.x = q.y = q.z = std::sin(radians / 2);
q.x *= axis.x;
q.y *= axis.y;
q.z *= axis.z;
return q;
}

Is it possible to get more than 360 degrees of rotation from a quaternion technique?

Upvotes: 0

Views: 2854

Answers (1)

joojaa
joojaa

Reputation: 4434

Your situation does not sound like a gimbal lock. Gimbal lock is when you can no longer rotate in any other direction but one since your axes are aligned on top of each other*. Sounds more like something a cross product would do. Anyway you shouldn't have any problems since you have only two axes going on for you so as long as you choose suitable rotation order there should no problem with gimbal lock whatsoever.

The reasons quats work is that they represent uniformly the rotation space and that space has no excess values. You can key every 180 to 90 degrees and quats will work right. However they will not interpolate the same way your doing now. In fact you can not rotate over many axes at once there is always just one rotation going on rotating may euler angles simultaneously will just keep turning the secondary rotation direction all the time. One way to do this would be to split up the animation uniformly and interpolate with quats but calculating the keyframe positions with eulers. Another way is to encode rotation cycles in the length of the quat.

In any case the result wont be the same, since you wouldn't get the euler wobble.

* you can visualize this by drawing rings at each axis orientation instead
  of your object and see how they move to overlap (like a gimbal hence the name).

Upvotes: 0

Related Questions