View Full Version : gimbal lock

03-15-2002, 08:45 AM

I want to rotate a 3D scene In the way it should be using a trackball but using a mouse. Im sure most of you know whats the gimbal lock problem. Ive found some papers and a library but its not useful for me. Do you know where to find some information that can teach me the math basis of the problem and how to solve it?. I am trying to do it mapping the coordinates of the camera over a virtual sphere without the use of quats but Its quite difficult. Where can I find a "stupids for" tutorial about this?..

many thanks.

03-15-2002, 03:15 PM

03-15-2002, 11:38 PM
Originally posted by satan:

thanks a lot. Lets see If I can I achive my objectives...

03-16-2002, 02:43 AM
If it is not for 'serious commercial use' then I have (very ugly) but simple bodge.

03-16-2002, 04:00 AM
Assuming that you have a target 'up' vector, you can do a cross product between that and your scene's 'up' vector (prolly (0;1;0)). Normalize the result, that's your rotation axis. Get the angle between the two up vectors. If the angle is very small, don't bother to rotate, as your rotation axis may be very close to (0;0;0) anyway, otherwise that's your rotation angle. Use angle-axis rotation (glRotatef(angle,axis.x,axis.y,axiz.z); or so), using these two results. That should solve gimbal lock.

Or just use quats http://www.opengl.org/discussion_boards/ubb/biggrin.gif

03-17-2002, 10:48 AM
Here is a example of the problem of gimble lock:

0. Stand up if your chair doesn't spin.
1. Pitch your head up 90 degrees. p=90,y=0,r=0. You are looking straight up.
2. Roll CW 90 degrees. p=90,y=0,r=90. You are still looking straight up but now you have turned to the left.
3. Pitch down 90 degrees. p=0, y=0, r=90.
You are now looking to the left with your head straight (as if p=0,y=90,r=0), but according to your Euler angles, you should be looking straight ahead with your head tilted over to the right.

There are two ways to fix this.

1. Use a rotation matrix or quaternions to keep track orientation.
2. Allow only one angle (typically yaw) to go up to (and beyond) +/- 90 degrees.

03-19-2002, 07:03 AM
I don't agree with the math above, it is like the proof that 1==2, you are 'dividing by zero'.

Yaw is not a defined quantity when pitch = 90 degrees. Therein lies the strangeness.

Theorem: 2 = 1


Given: A = B
Multiply by A: A^2 = BA
Subtract B^2: A^2 - B^2 = BA - B^2
Factor: (A + B) (A - B) = B (A - B)
Cancel: (A + B) = B
Substitute: B + B = B
Collect: 2B = B
Cancel: 2 = 1


(Acknowledge Gerry Roach for the proof typing)

[This message has been edited by nickels (edited 03-19-2002).]