Some time ago, I read some articles and contents about three-dimensional rotation on the Internet. I found that many people would talk about quaternion from Euler Angle, and explained many concepts in a long time. After reading, it was still difficult to establish a clear cognition and how to use it correctly. So I decided to write an article on the four common expressions of rotation (Euler Angle, matrix, axial Angle rotation, quaternion) from a programming perspective (other fields may have a different understanding of rotation).

The original link

Different types of expression

First we define two types of expressions: geometric and mathematical.

The geometric expression

The geometric expression means that you can immediately visualize rotation in your mind, and obviously only euler Angle and axial Angle rotation of the above four expressions can immediately visualize rotation.

R(Euler): x=45°, y=45°, z=45°, order=xyz

R(axis-angle): Axis =(0, 0, 1), Angle =45° indicates that the Axis (0, 0, 1) is rotated 45 degrees

The geometry is straightforward, but calculating combinations of multiple angles is a very common scenario, and doing it this way is cumbersome, You can use your knowledge of geometry to calculate how an object rotated around axis=(0,0,1), Angle =45° and axis(1,0,0), Angle =45° will result in the form of an axis Angle.

A mathematical expression

The mathematical expression is not as intuitive as the geometric expression, but it is very convenient for calculating multiple combinations of angles

For example, axis=(0,0,1) and Angle =45° correspond to a matrix M(R1) that looks like this


[ 0.9996242168594817 0.027412133592044294 0   0.027412133592044294 0.9996242168594817 0   0 0 1 ] \begin{bmatrix} 0.9996242168594817&-0.027412133592044294&0 \\\ 0.027412133592044294&0.9996242168594817&0 \\\ 0& 0 & 1 \end{bmatrix}

Axis (1,0,0), Angle =45° and the corresponding matrix M(R2) looks like this


[ 1 0 0   0 0.9996242168594817 0.027412133592044294   0 0.027412133592044294 0.9996242168594817 ] \begin{bmatrix} 1&0&0 \\ 0&0.9996242168594817&-0.027412133592044294 \\ 0&0.027412133592044294&0.9996242168594817 \\ 0&0.027412133592044294&0.9996242168594817 \end{bmatrix}

And then you compute the combination of these two rotations directly by multiplying the matrix M(R2) x M(R1) (the matrix is applied from right to left, with the rotation of the leading row on the right).

A quaternion is a bit like a matrix, and its application and combination are all through quaternion multiplication. The properties of multiplication by left and right are the same as those of a matrix, which will be described in the following sections.

The practical application

Now let’s look at how these two expressions divide up in practice. Suppose we need to implement a 3d rotation control. The user can rotate the model by dragging and dropping, similar to the rotation control in Blender shown below. Drag the red circle to rotate the object around the X axis, the green Y axis, and the blue Z axis (note that the axes here are global coordinates).

The essence of the process here is that the user inputs a geometric representation (axis rotation), converts it into a mathematical representation within the program, and merges it with the previous rotation R(input rotation) x R(current rotation), and finally converts it into a transformation matrix to render the model.

In addition, the rotation information for the current model will be displayed on the right side of Blender, where the mathematical representation is transformed into a geometric representation for the user to display. (Showing quaternions directly here may serve a special purpose, since Axis Angle and quaternions can be converted directly)

It can be said that geometric representation is more interactive, while mathematical representation is more computational.

Euler Angle with universal joint deadlock

When you talk about Euler angles you’re going to talk about universal joint deadlocks, and then you’re going to talk about quaternions. About quaternion next section, first talk about the universal joint deadlock problem, what is the cause of this problem? What will be the impact?

Cause of universal joint deadlock

A lot of people like to bring this around when they’re explaining gimbal deadlocks

I’ve always found this kind of diagram hard to understand, mainly because it’s hard to relate euler angles to it, and I’d rather look at this explanation based on the formula.

In short, if the Euler angles are rotated in order of XYZ, when the rotation of Y causes the rotated Z to coincide with the rotated X, then a universal joint deadlock occurs, and the XZ axis is essentially a rotation of the same axis in the global coordinate system.

The effect of universal joint deadlock

So what are the practical problems of losing a degree of freedom? This is rarely mentioned in articles, but I will mention a few I came across here. Problems occur when the user enters an Euler Angle R(Euler): x=0°, Y =90°, Z =45°, order=xyz, and then converts it to a mathematical expression in the program. It is obvious that this is an Euler Angle with universal joint deadlocks, all rotations of x + z == 45° are equal, and the original Angle cannot be restored when rotated back.

Why do we need quaternions?

I never quite understood why quaternions were always mentioned together with Euler angles. First of all, they are different types of expressions and should not be mentioned in the same sentence. I think the correct statement is that euler Angle has the problem of universal joint deadlock, which needs to be solved by using the axial Angle rotation, and quaternion is the mathematical expression of the axial Angle rotation.

Quaternion basis

What a few words also explain is not very clear, suggest to have time to read this article.

Contrast with matrix

Axial rotation can be converted to matrices and quaternions, so how to choose which method to use?

Quaternions have some performance advantages for rotation calculations alone, but matrices are faster for other transformations (offset, scale, etc.) depending on the actual scenario.

In addition, quaternions have a unique characteristic that interpolation calculation is very convenient. At present, the interpolation of rotation basically uses quaternions for interpolation, so it is recommended to use quaternions directly if the data is used for rotation animation, otherwise there will be the cost of conversion.

Reference

  • Krasjet. Making. IO/quaternion /… (Highly recommended)