0

Why do 3D rotation matrix methods typically use a separate vector and angle instead of regular Euler angles?

For example, in glm, given a mat4 model and vec3 rotation, instead of:

model = glm::rotate (model, rotation);

why do I have to write:

model = glm::rotate (model, rotation.x, glm::vec3 (1, 0, 0));
model = glm::rotate (model, rotation.y, glm::vec3 (0, 1, 0));
model = glm::rotate (model, rotation.z, glm::vec3 (0, 0, 1));

Why do they not simply implement this as a single Euler rotation vector, simplifying pretty much every piece of code to ever use the library? I've seen this in other implementations, too.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Ethan McTague
  • 2,236
  • 3
  • 21
  • 53

3 Answers3

1

Firstly its theoretically elegant to think of the set of all rotations as the set of all unit vectors and angles. If you combine two rotations you get a third such rotation.

Internally to the code will represent rotations either as a matrix or possibly a quaternions. If its the latter its particular easy to go between the quaternion and the axis-angle model.

If you have your rotation specified in Euler angles then you can get the rotation matrix by simple composition of the three individual rotations. Doing the converse is less easy if your API only allowed Euler angles yet you have a rotation specified in axis-angle then it would be tricky to calculate the Euler angles.

So a designer of an API will choose a method which is theoretically elegant, is easy to convert to the internal format and provides a system which can be used with a variety of inputs. They may add a convenience method for input in terms of Euler angles depending on how parsimonious they want to make the API.

Salix alba
  • 7,536
  • 2
  • 32
  • 38
0

Because Euler angles are not a good idea in general. You got 6 combinations of ordering the transforms which means using such API would lead to confusions.

On the other hand rotation vector with (0,0,0) as origin is straightforward to imagine and describe and also more accurate. There are two major approaches I use for such rotation:

But there are also others like using quaternions, etc.

Rookies often tend to incline to Euler angles because they seem to be easy to implement but their drawbacks are so significant and often overlooked completely so they stay with them even as pros which pains me as many good games and apps still use them and suffer the consequences due singularities and horribleness to deal with them correctly.

Spektre
  • 49,595
  • 11
  • 110
  • 380
0

Why do they not simply implement this as a single Euler rotation vector, simplifying pretty much every piece of code to ever use the library?

Because it does not "simplifying pretty much every piece of code to ever use the library". Euler angles are prevalent in modeling tools, tutorials, and code written by people who are new to graphics. But when it comes time for serious graphics applications to represent an object's orientation, it is usually does as a matrix itself or as a quaternion. The latter of which can be considered to be an encoding of an angle/axis rotation.

Matrices and quaternions can be composed. Euler angles cannot. Quaternions can be smoothly interpolated, thus allowing for animations of characters. Interpolating multiple Euler angles leads to very unfortunate results. Applying an axial rotation to euler angles is subject to gimbals lock; applying rotations to an orientation (matrix or quaternion) does not. And so forth.

Euler angles are kind of a newbie trap. They're something that's very easy to understand, but ultimately not very useful in the most common cases. It's better to have APIs that don't cater to such traps.

Indeed, there isn't one set of Euler angles; the order that the 3 axial rotations are applied in matters for the results. If you apply the same angles in a different order, you get a different result. And people who use Euler angles will generally choose different Euler angle orderings based on their needs.

So having a glm::rotate function that picks a specific Euler ordering would be useless for anyone who needs a different one.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982