When to use Quaternion vs Euler Angles?

This is a ‘best practices’ question as well as a clarification one. I get that Euler angles are a way to read Quaternions as a vector3 value, but when would you ever want to use Euler Angles? Why not just use Quaternions all the time?

I’m hoping to get some examples from everyone on when to use each of them, in order to help wrap my head around it by seeing it in practice. The simpler/cleaner the example the better but anything helps! Thank you!

Quaternions have some advantages when it comes to gimbal lock and smooth interpolation. Their main downside is that they rely on advanced math – math that even experienced developers often find difficult and confusing.

From the scripting manual:

[Quaternions] are based on complex numbers and are not easy to understand intuitively. You almost never access or modify individual Quaternion components (x,y,z,w); most often you would just take existing rotations (e.g. from the Transform) and use them to construct new rotations (e.g. to smoothly interpolate between two rotations). The Quaternion functions that you use 99% of the time are: Quaternion.LookRotation, Quaternion.Angle, Quaternion.Euler, Quaternion.Slerp, Quaternion.FromToRotation, and Quaternion.identity. (The other functions are only for exotic uses.)

People very rarely interact with quaternions directly. As it turns out, it’s almost always easier to manipulate them using other representations:

  • Angle-axis representation specifies a unit vector and a rotation about that vector (see ToAngleAxis and AngleAxis pages).
  • Euler angle representation specifies rotation about the Z, X, and Y axes, in that order (see eulerAngles and Euler pages).

The scripting manual suggests some of the most common tricks for manipulating or generating quaternions.

There are some scholarly articles around the net, if you’d like to understand more about the math behind quaternions. If you plan on using them a lot, I highly recommend at least skimming some.

I recommend using quaternion variables to represent two things: an object’s rotation, and/or a rotation which you’d like to apply to some object. Even when using them for that purpose, it’s almost always easier to generate them using the methods described above, or by taking an existing quaternion and rotating it by some amount you just generated.

It’s very rare that you need to actively examine or manipulate quaternions that you didn’t create yourself. It’s usually easier to use vector math to solve problems, including clever use of dot and cross products.