View Full Version : Rotations and Quaternions

chowe6685

10-26-2001, 05:29 PM

I have a simple program in which I try to roll a ball around on a floor, should be no problem. I used the code

glRotatef(xRot, 1,0,0);

glRotatef(zRot, 0,0,1);

to rotate the ball so it looks like its rolling. The problem is that when I call the first function it rotates the Z-axis too and so the second rotation is wrong. I did some research and wrote a quaternion class, but that hasn't helped. I think my problem is called a Gimble Lock. Anyway if anyone has any suggestions I would greatly appreciate them.

witcomb

10-26-2001, 08:07 PM

Well, I don't know what you mean "it rotates the z-axis as well". So I will assume you mean it is rotating about the z-axis as well. This doesn't make any sense though. If you can elaborate about what you mean I might be able to help alittle better.

But, a definition of gimble lock is when two rotational axis' of an object pointing in the same direction. Once this occurs the rotation you apply will not necessarily be applied as expected. Gimbal lock occurs when using Euler angles, because each rotation is applied with independant axis. This means that the rotations for each axis is applied individually in the order of X,Y,Z for example.

So, consider this rotate about the y-axis 90 degrees. The x-axis rotation has already been applied following the X,Y,Z rule. This means that the object frame's z-axis is parallel to the global frames x-axis and when we apply the z-axis rotation it will actually do nothing.

From you explaination of the problem I don't think this is your problem, although it could be a problem in the future. But you would only see that the ball only rotates in one axis and not two axis'

Hope this helps,

Neil

Korval

10-26-2001, 11:23 PM

No, he stated the problem correctly. When you create a rotation matrix around a particular axis, further transformations happen in this rotated reference frame. So, in effect, after the x-axis rotation, the z-axis is not where it should be.

As for solving it, quaternions are one approach. How did you use them?

chowe6685

10-27-2001, 11:52 AM

First I rotated around the x Axis using the quaternion (cos(xRot)/2)+(sin(xRot)/2)i+0j+0k

then I tried to rotate around the old z axis by rotating around the unit vector

(0, sin(xRot), cos(xRot)) using the quaternion

(cos(zRot)/2) + 0i + (sin(xRot)*sin(zRot)/2)j

+ (cos(xRot)*sin(zRot)/2)k

but it ends up causing some really weird rotations that arn't right. Hope that clarifies the problem

Powered by vBulletin® Version 4.2.5 Copyright © 2018 vBulletin Solutions Inc. All rights reserved.