Quaternions vs Euler Angles: Converting Rotations Without Bugs
Why rotation conversions go wrong between libraries, what intrinsic and extrinsic orders mean, how gimbal lock appears, and how to convert reliably.

Quaternions vs Euler Angles: Converting Rotations Without Bugs
If you have ever imported a model and found it lying on its side, or fed IMU data into a game engine and watched the camera spin the wrong way, you have met the rotation conversion problem. The maths is not hard, but the conventions are many. This guide explains the common traps and how to use the free Quaternion and Euler Angle Converter to check your numbers.
Four ways to say the same thing
A rotation in three dimensions can be stored as:
- a quaternion, four numbers with length one
- a 3 by 3 rotation matrix
- an axis plus an angle, or a rotation vector that multiplies them together
- three Euler angles applied one after another
Each has strengths. Quaternions interpolate smoothly and never lock up. Matrices transform vectors directly and chain by multiplication. Axis-angle is easy to picture. Euler angles are what humans and many sensors speak: yaw, pitch and roll.
Trap one: where does w go?
A quaternion has a scalar part w and a vector part x, y, z. Eigen and GLM constructors take w first. three.js, Unity, Unreal, SciPy and ROS messages put it last. Paste the numbers in the wrong order and you get a valid but completely different rotation, which is why the bug is so quiet. The converter asks which order your pasted numbers use, and its code output writes each library's own order for you.
Trap two: twelve orders, two frames
Euler angles need a sequence of axes. Tait-Bryan sequences use three different axes, such as ZYX; proper Euler sequences repeat one, such as ZXZ. That gives twelve sequences. Each can be intrinsic, where every rotation happens about the object's already-rotated axes, or extrinsic, about fixed world axes. So there are 24 ways to read three numbers.
The good news is a simple identity: intrinsic rotations in one order equal extrinsic rotations in the reverse order. Aerospace yaw-pitch-roll is intrinsic ZYX, which is the same as extrinsic XYZ. When two libraries disagree, open the all-conventions tab, find the row that matches the other library's output, and you have identified its convention.
Trap three: gimbal lock
Turn the middle angle of a Tait-Bryan sequence to plus or minus 90 degrees and the first and third axes line up. From then on, only their combined effect matters, and infinitely many angle triples describe the same pose. Code that converts back to Euler angles at that point can produce sudden jumps of 180 degrees, which show up as flicker in animations or spikes in telemetry plots.
The converter detects this case and tells you. It keeps the rotation exact by setting the first angle to zero and putting the rest on the third. If you see this message often in your data, store quaternions instead and only convert to angles for display.
Trap four: almost-rotation matrices
Matrices loaded from text files or computed in single precision drift slightly from perfect orthogonality. Feed one into a strict library and it may refuse, or silently produce skew. Paste the nine numbers into the matrix box and the tool reports the orthogonality error and the determinant. A determinant near minus one means the matrix also mirrors the object, which no quaternion can represent; usually that means a coordinate system with a flipped axis.
Seeing is believing
Numbers alone are hard to check, so the converter draws a coloured cube with its rotated axes. Red marks the body's X axis, green Y and blue Z. If you expect the nose of a drone, its X axis, to point up and left, glance at the red arrow. You can also drag the cube to nudge the rotation, and each drag is one undo step.
Interpolating
The slerp tab blends between the current rotation and a target. Spherical linear interpolation keeps a constant turning speed and always takes the short way round, which is what you want for camera moves and keyframe animation. Blending Euler angles directly does neither, especially near gimbal lock.
Handedness and other caveats
All formulas in the tool are right-handed and active, which matches most maths texts, robotics stacks and three.js. Unity uses a left-handed coordinate system, so some signs differ when you move data between Unity and right-handed tools. The safest habit is a test rotation: rotate 90 degrees about a single axis in both systems and compare before trusting a whole pipeline. Angles are wrapped to the range of minus 180 to 180 degrees, which is one valid choice among several.
A routine that saves time
When rotations come from a new source, convert one known pose, compare all conventions, decide which one the source uses and note it in your code. Then copy the snippet for your target library. Five minutes with a converter beats an afternoon of flipping signs at random.



