What the idea is behind a quaternion and why do developers prefer them for graphical design?

175 views

I have a high level understanding of the mathematics and concepts but I want a _true_ eli5.

In: 8

3 Answers

Anonymous 0 Comments

Quaternions are immune to [gimbal lock](https://en.wikipedia.org/wiki/Gimbal_lock), which is when you get yourself into a situation where you can’t rotate something in the direction you want directly without first rotating it out of a specific problematic angle, so they are excellent for 3D engines that want to avoid fuckyness when handling rotation. You can optionally have a bunch of convenience functions to convert to/from Euler angles and create rotation matrices (quaternions) from Euler angle rotation vectors (x, y, z angles), but the actual data representation will be quaternions.

Anonymous 0 Comments

Rotations in 3D can be represented by certain matrices (usually 3×3), or by quaternions. The latter are usually much simpler to handle, as the multiplication rules are much simpler.

In the end, they are fully equivalent.

Anonymous 0 Comments

Somebody already talked about gimbal lock and quaternions not being affected.

Another thing is the ability to keep time-integrating a rotation without hitting limits. When you keep rotating an object 30 degrees per timestep you will at some point need to implement a 2-pi-flip or risk overflow of the integrator when long times pass (the number gets to big for the computer to handle, so you subtract 360° every time you go past 180 or -180). Quaternions always stay between -1 and 1 without “manual” correction.

A third thing is relative rotation.

You have one orientation and you want to bring it over to another. Doing it with angles seems simple enough. Just rotate from 30 to 45 degrees, so a 15 degree increment.
Now turn from 179 degrees to -179 degrees. You would have to implement special code to catch this case and move the 2 degrees in the right direction and not the 358 degrees in the wrong one.
Quaternions just WORK, no special code necessary.

But: quaternions are hard to grasp as a human, so we use euler angles as initial conditions and for readout/debugging and direct cosine matrices for coordinate system conversion and chaining transformations through different coordinate systems, because we can do that math in the head if necessary. But in the nitty gritty numerical kernel, nothing beats quaternions, because their math has no poles.