Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use quaternions to describe a rotation angle which is more than 360 degrees?

Tags:

c++

math

graphics

I'm trying to use quaternions to do rotation animation. My algorithm creates Quaternions, and slerps every frame. Here is my code to construct a quaternion by the axis and the rotation angle.

template <typename U>
Quaternion(Vector3<U> vec, const float& angle)
{
    vec.normalize();
    float cosa = cos(angle/2);
    float sina = sin(angle/2);
    w = cosa;
    x = sina * vec.x;
    y = sina * vec.y;
    z = sina * vec.z;
}

Then I found that when I tried to rotate 4π radians, the animation does not work because the quaternion I created is equivalent to 0 degrees. I wonder if quaternions can represent rotations over 360 degrees? Or is my animation algorithm in need of improvement?

like image 457
M.Zhao Avatar asked Dec 19 '18 12:12

M.Zhao


1 Answers

I wonder if quaternions can represent rotations over 360 degrees?

No, it can not.

Quaternions between the range [360;720] will treated as rotations at the other direction: [-360;0].

And quaternions between the range [720*k; 720*(k+1)] will be treated as rotations [0;720].

If you use slerp for this kind of animation, quaternions are not good for them.

Quaternions can only slerp between angles which are smaller than 360.

If you still want to do this, use a different representation, like axis-angle.

like image 78
geza Avatar answered Sep 28 '22 03:09

geza