# Converting from Euler angles to axis-angle and back

I've been writing a small utility library for converting different 3D rotation representations. My sources are mainly Wikipedia, a couple text books, and Martin Baker's excellent site. I've been unit testing each of my conversions (using values verified with MATLAB), and the only ones that don't hold up are the Euler angles to axis-angle conversion and the inverse of that. Using Martin Baker's conventions of bank=Rx, heading=Ry, and attitude=Rz, I'm unable to achieve the correct output.

I'm using his equations from here for axis-angle to Euler, and here for Euler to axis-angle, but they are not matching my sample cases. I'm thinking it may be confusion over ordering.

Given Rx, Ry, and Rz representing rotation about the X, Y, and Z axes, respectively, and applied in XYZ order (i.e. first rotate around X, then Y, then Z), what is the conversion from Euler angles to axis-angle, and vice versa?

NOTE: Ultimately I can always fall back to converting through another representation such as a quaternion, as those pairs of conversions work. However, I'd like to understand the direct conversion.

I am aware of this question that has been asked here previously, but the accepted solution is overly formal and I can't quite extract the simple conversion equations. The second answer converts through a rotation matrix, and, as I mentioned, I'd like to find a direct conversion.

• Martin Baker assumes Euler angles are applied in the sequence y, z, x. It's strange, however, that you seem to have correct conversions between Euler and quaternions but not Euler and axis-angle, since the steps for each conversion are almost the same. Jun 12 '17 at 21:30
• @DavidK: I saw his convention was YZX, which is why I think it may be an ordering issue. I can't seem to determine the correct adjustments. The reason I have working Euler/Quaternion conversions is because I used Wikipedia as my source for that pair. Similarly I used this site for Euler/Rotation Matrices. Martin Baker seems to be the only resource for direct Euler/Axis-Angle conversion equations though Jun 12 '17 at 21:32
• Same problem trying to understand Baker's site, which defaults to XZY rotation order (where Y is applied first). I even tried all the possible combinations of axis flipping, and figure out what was the right order, but I couldn't get it working for all the possible orders. For reference, here's the brute-force search: Javascript commit -- In the end I gave up and used matrices. You can see that conversion in Three.js src May 23 '19 at 17:21
• Another good resource is this 3D Rotation Converter site, that uses the Three.js library under the hood. I used it to generate unit tests for my code. May 23 '19 at 17:23
• Does it HAVE to be Euler angles, or do you just want 3 rotational angles? Euler angles have an order applied, Log quaternions turn directly from X/Y/Z to angle, axis of rotation normal. I've been working on log quaternion rotations with github.com/d3x0r/stfrphysics; which has some links to live demos (all in JS and three.js actually) Aug 12 '20 at 8:28