Representing rotations using quaternions

2.7k Views Asked by At

I'm learning Unity and came across a situation where rotations are represented as Quaternions. I've heard that they where used in computer graphics, but never had to use them until now. What I can't understand is, how do quaternions represents rotations in the three dimensional space?

I know that complex numbers represents rotations in the 2 dimensional space (such as multiplying a number by $i$ would move it by $\frac \pi 2$). This seems logical in the sense that $\Bbb C$ has two unit vectors $i$ and $1$, like the two dimensional space. Why would we need a four dimensional set to represent rotations on a three dimensional space? And what kind of rotation would a quaternion (for example $i+j+k+1$) represent?

Remark:

On the tutorial I'm following to learn Unity, I've used the Quaternion.Euler(float x, float y, float z) function to create a rotation. From the documentation about the later:

Returns a rotation that rotates z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order).

Note that the fourth dimension isn't used to define that rotation.

2

There are 2 best solutions below

0
On BEST ANSWER

The key fact is that:

a rotation of an angle $2\theta$ in space, around an axis passing through the origin, is represented by a quaternion $e^{\mathbf{u}\theta}$, where $\mathbf{u}$ is the imaginary quaternion that correspond to the unit vector oriented along the axis of rotation. So we have the correspondence: $$ \vec{w}=R_{\mathbf{u},\theta} \; \vec{v} \quad \longleftrightarrow \quad \mathbf{w}= e^{\mathbf{u}\theta/2}\mathbf{v}e^{-\mathbf{u}\theta/2} $$

See my answer to :Quaternions vs Axis angle.

For the exponentiaton we have that if $ \mathbf{v} \in \mathbb{H}_P$ is an imaginary quaternion, putting $\theta=|\mathbf{v}|$ we have: $$ e^\mathbf{v}= \cos\theta + \mathbf{v}\;\dfrac{\sin \theta}{\theta} $$

See:Exponential Function of Quaternion - Derivation

0
On

"Why would we need a four dimensional set to represent rotations on a three dimensional space?"

"These articles are too technical for me to understand"

You can pick an axis and do a complex-number-type rotation around that axis. If you do that repeatedly, you may sometimes find that the axis you need to rotate around is the direction of the vector you want to rotate. "Gymbal lock".

Quaternions with four dimensions do two complex rotations at the same time, by the same number of degrees. One of the rotations is perpendicular to the direction of the vector part of the quaternion, and the scalar part of a unit quaternion is like the cosine of the angle you rotate through. That's the rotation you want. BUT at the same time, you get a second complex rotation between the axis dimension and the scalar dimension. Your result is not a vector but a quaternion.

It turns out that you can multiply on the other side to get the rotation you want, but the second rotation is in the opposite direction. So rotate half the angle you want, then on the other side rotate the other half and cancel out the part you don't want. No gymbal lock. You can get some estimate of your rounding error by checking how much the vector length has changed.