This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Euler angles sign issues

Tags: None
(comma "," separated)
johnm1019
Registered Member
Posts
46
Karma
0

Euler angles sign issues

Mon Jun 03, 2013 9:44 am
I realized Eigen had Euler angles and jumped up and down a few times happy that I didn't have to write and debug the math myself.

I'm writing some unit tests and am having issues reproducing rotation sign. It may be my failure to understand Euler angles or I could be doing the math wrong.
For my first pass attempt I'm trying to replicate the documentation http://eigen.tuxfamily.org/dox/group__Geometry__Module.html#gad118fececd448d7485ffea4858775e5a
Here's my test code
Code: Select all
Eigen::Matrix4f inputMat;
Eigen::Matrix4f outputMat;
Eigen::Array3f inputAngles;
Eigen::Array3f outputAngles;
float minResidual = 0.00001;
float realResidual = 0.0f;

inputMat = outputMat = Eigen::Matrix4f::Identity();
// Hand-Craft, ANG > MAT > ANG
// first quad
inputAngles << M_PI/4, M_PI/4, M_PI/4;
outputMatrix.block<3,3>(0, 0) = (Eigen::AngleAxisf(inputAngles[0], Eigen::Vector3f::UnitZ())
                              * Eigen::AngleAxisf(inputAngles[1], Eigen::Vector3f::UnitX())
                              * Eigen::AngleAxisf(inputAngles[2], Eigen::Vector3f::UnitZ())).toRotationMatrix();
outputAngles = inputMat.block<3,3>(0,0).eulerAngles(2, 0, 2); // follows Z-X-Z

and I get the following output
Code: Select all
inputAngles == [0.78539819, 0.78539819, 0.78539819]
pi/4, pi/4, pi/4
outputAngles == [-2.3561945, -0.78539824, -2.3561945]
-3pi/4, -pi/4, -3pi/4


I am interested in having reversible Euler angles within 360, 180, 180 degrees respectively for phi, theta, and psi as defined https://en.wikipedia.org/wiki/Euler_angles.
Is this possible?

EDIT: for reference, originally I was going to implement this by unabashedly copying from Wiki (as we use right hand as well) http://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions#Conversion_formulae_between_formalisms
johnm1019
Registered Member
Posts
46
Karma
0

Re: Euler angles sign issues

Wed Jun 05, 2013 9:34 am
I solved half the problem.
I thought about it some more and realized that I might be generating LH transformations.
Now my MAT > ANG > MAT works (for RH transformations) but my ANG > MAT > ANG code is not working.

I can fix the MAT > ANG > MAT code above by adding this check after the random generation.
Code: Select all
   outputMat = inputMat;
   if( inputMat.determinant() != 1 )
   {
      // flip from LH to RH
      inputMat.block<3,1>(0,2) *= -1;
   }


Suggestions for solutions to the original problem are still very welcome. I've checked and the first pass ANG > MAT is generating RH transforms (with the Z,X,Z scheme)
johnm1019
Registered Member
Posts
46
Karma
0

Re: Euler angles sign issues

Wed Jun 05, 2013 11:09 am
Diving into this a little more, I found this paper which comments on the implementation from Graphics Gems (as indicated by the Eigen source comments) and suggests some additional modifications to avoid gimbal lock.

It looks reasonable to me and the Eigen code does not appear to adopt these methods. Can someone related to this code in Eigen make an intelligent comment here?
https://d3cw3dd2w32x2b.cloudfront.net/w ... angles.pdf
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Euler angles sign issues

Wed Jun 05, 2013 12:15 pm
I don't have time to look very carefully at this issue, but the proposed strategy in your link sounds much better than what we currently have. Patch welcome;)
johnm1019
Registered Member
Posts
46
Karma
0

Re: Euler angles sign issues  Topic is solved

Mon Jun 17, 2013 7:06 pm
This was resolved recently by the Eigen team. thanks!
http://eigen.tuxfamily.org/bz/show_bug.cgi?id=609


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]