Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quaternions still have gimbal lock

Instead of Euler angles I moved to Quaternions to represent and process the rotation of a cube in 3D. Although it would solve gimbal lock, I'm still experiencing this issue.

My code is:

// p is the point to be rotated
// angles is a Vector3D representing the rotation angles

var xaxis = new Vector3D(1, 0, 0);
var yaxis = new Vector3D(0, 1, 0);
var zaxis = new Vector3D(0, 0, 1);

p = rotate(p, xaxis, angles.x);
p = rotate(p, yaxis, angles.y);
p = rotate(p, zaxis, angles.z);

The rotate functions comes from http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#Pseudo-code_for_rotating_using_a_quaternion_in_3D_space (translated into JavaScript).

I guess the problem is due to the fact that I still use an order of axes (x y z) which is the main problem of gimbal lock.

How would one implement quaternion rotation in such a way that gimbal lock is solved?

Thanks in advance.

like image 661
pimvdb Avatar asked Dec 14 '25 13:12

pimvdb


1 Answers

Quaternions are not susceptible to gimbal lock, so that's not your problem. If your x, y, and z angles are intended to represent something like Euler angles, the issue is more likely that you're defining xaxis, yaxis, and zaxis relative to the original coordinate system. But that won't give the expected results, because after the first rotation around xaxis, the Y and Z axes don't point in the original directions any more, yet the next two rotations are still referenced to the original coordinate system.

like image 144
Jim Lewis Avatar answered Dec 19 '25 05:12

Jim Lewis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!