Slerp gives wrong values when fed an euler matrix [0,90,0]

7 views (last 30 days)
I am trying out the slerp function to create an interpolation function so i made a simple program to test it on different values :
a = [0,90,1];
b = [1,1,1];
rotationSequence = 'XYZ';
rotationType = 'frame';
% conversion to quaternions
aa = quaternion(a,'eulerd',rotationSequence,rotationType);
bb = quaternion(b,'eulerd',rotationSequence,rotationType);
% Apply Spherical linear interpolation
cc = slerp(aa, bb, 0);
% Conversion back to euler
c = eulerd(cc,rotationSequence,rotationType);
A 0 is supposed to give me back the exact same a. But I get weird values everytime I put 90° in the second element of my matrix.
If I put :
  • a = [0,90,1] --> I get c = [1.0000,90,0]
  • a = [0,90,2] --> I get c = [2.0000,90,0]
  • a = [0,90,3] --> I get c = [3,90,0]
  • a = [0,90,4] --> I get c = [4.0000,90,0]
  • a = [0,90,5] --> I get c = [48.814074834290350,89.999999146226360,48.814074834290350]
  • a = [1,90,1] --> I get c = [2.0000,90,0]
  • a = [5,90,5] --> I get c = [10,90,0]
Changing the rotation sequence or the rotation type will give wrong results as well.
Can anyone help me understand why ?

Accepted Answer

Brian Fanous
Brian Fanous on 28 Jun 2022
What you are seeing is known as gimbal lock. You have set your a variable to a Euler angle singularity. Specifically in this case, because the Y rotation is set to 90 degrees, the X and Z rotations effectively do the same thing. You've lost a degree of freedom in your math. Wikipedia has a nice description.
Once you've converted from Euler angles to quaternions, you've lost the (notational) allocation of the non-Y rotation to either X or Z. Going back to Euler angles after slerp cannot rediscover where you had originally put the non-Y rotation.
Two things might help illustrated this:
  • Try this same experiment but not at gimbal lock. For example, setting a = [0 80 1] will work as you expect. The closer the middle angle gets to 90 degrees, the more likely you'll hit the gimbal lock condition.
  • Comparing Euler angles is a poor way to compare rotations for exactly reason you've found. If you want to compare two orientations use the quaternion dist method instead: dist(aa,cc). This will give you the angular distance between two orientations. Even at your gimbal lock example, you'll see the angular distance is 0.

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!