Current location - Training Enrollment Network - Mathematics courses - 3D Shape: The Story of Matrix, Euler Angle, Quaternion and Direction
3D Shape: The Story of Matrix, Euler Angle, Quaternion and Direction
I have studied 3D graphics for nearly two weeks, and I want to study it most. Because of Euler angle and quaternion, the research progress of OpenGL ES has slowed down. After learning this piece, I will teach you how to make a regular cube with rotation and revolution with OpenGL ES. The effect is as follows.

Before talking about the relationship between matrix, Euler angle and quaternion and angular displacement, let's talk about the difference between direction, orientation and angular displacement.

In real life, we seldom distinguish the difference between "direction" and "orientation" (non-road idiot's point of view). For example, a friend comes to visit you, but he may get off at a bus stop. You went to see him, but you couldn't find him. You hurriedly called him "Brother, which direction are you in?" Or "Brother, where are you?" If you don't carefully taste these two sentences, the difference is not too big. After a painful phone call, you succeed, but you don't care about the difference between "direction" and "orientation" So in geometry, what is the difference between the two?

Here, I will steal some examples from the book. For example, if a vector is selected along its own direction, it will not change any of its attributes, as shown in the figure below, because a vector has only direction but no orientation.

So for an object, the situation is different. If an object faces a certain direction and then rotates, then the object will change in space. As shown in the figure below, when the cone rotates, its spatial position will change, that is, its orientation will change.

The above gives us a general idea of the difference between the direction and orientation of an object, so how do we describe an orientation in space? This requires the use of angular displacement.

Let me start with a similar example. How do we describe the position of an object in space? You need to put the object in a specific coordinate system (it looks rough). For example, we say that in a coordinate system, there is a point QR [0,0, 1], which is expressed in our own coordinate system. If placed in other coordinate systems, the current three basis vectors may change. This is because the reference points are different. As for how the basis vector changes, we need the knowledge about rotation matrix in 3D graphics: matrix and linear transformation. This is not much to explain. For example, in the figure below, the new coordinate system composed of vectors p, q, r Q and r is represented by the original coordinate system, as shown in the figure on the right.

In fact, for our development, we only need to know that the orientation can be represented by a 3×3 matrix. The matrix represents the transformed basis vector. Next, let's talk about the advantages and disadvantages of using matrix to represent angular displacement. I'll just take what the book says. No wonder you want to study as an official.

Of course, we use matrix to represent angular displacement just for understanding. Next, let's take a look at how to use Euler angle to represent orientation.

Many people may be exposed to matrices in college, but Euler angles may be less exposed, at least as a student of physics. At first, I found the Euler angle difficult to understand, but after reading the 3D graphics, I found that it would be more intuitive and easier to use the Euler angle to represent the orientation than the matrix. Let's take a look at the relevant knowledge of Euler angles. The following basic concepts are similar to those in the book, because I thought it would be good to write one in the book, so I wrote it.

Firstly, the basic idea of Euler angle is to decompose angular displacement into a sequence of three rotations around three mutually perpendicular axes. So how are these three perpendicular axes defined? In fact, any three axes can be in any order, but the most commonly used is the rotation sequence composed of Cartesian coordinate system in a certain order. The most commonly used convention is the so-called "heading-pitch-slope" convention. In this system, the direction is defined as heading angle, pitch angle and tilt angle. Among them, in the left-handed coordinate system, we define the heading angle as rotation around the Y axis, the pitch angle as rotation around the X axis, and the tilt angle as rotation around the Z axis. The rotation rule follows the left-handed rule (see the rotation module in 3D Graphics: Matrix and Linear Transformation for details). Its basic idea is to make the object start from the "standard" orientation, that is, the coordinate axis of the object is aligned with the inertial coordinate axis. Let the object reach the final spatial orientation after heading, pitching and tilting rotation.

For example, a cone is shown below. At first, its own coordinate axis coincides with the inertial coordinate axis.

Then I set the heading angle to 45. According to the left-handed rule (usually used, but not necessarily kept to determine the positive direction of each rotation), it will rotate clockwise.

Then the coordinate system of the object changes as follows. The coordinate axis of the cone is no longer consistent with the inertial coordinate axis, and the X axis and Z axis have changed accordingly. Of course, the spatial orientation of the object has also changed accordingly.

Then pitch and tilt rotation, which rotate around X axis and Z axis respectively, are similar to heading rotation, and finally the final spatial orientation of the cone is obtained. It should be noted here that the rotation axis is its own axis, whether it is heading rotation, pitch rotation or slope rotation! Not the axis of inertia!

Above, we have seen how the "heading-pitching-embankment" convention system makes the spatial orientation rotate. Next, let's take a look at other conventions about Euler angles.

Next, let's take a look at the advantages and disadvantages of Euler angles. It reveals that the disadvantage of Euler angle is actually the reason of universal lock.

In fact, there will be a very interesting phenomenon when using Euler angle, that is, universal lock. Let's take a look at the "header-pitch-tilt" system. If the pitch angle is 90, something will happen. What will happen? If the heading angle and inclination angle are the same, then you will find that the final orientation of the object is the same. How is that possible? This is more embarrassing. In fact, similar to this kind of rotation, when the pitch angle is 90, the object lacks a rotation axis. That is, when the pitch angle is 90, then the slope is 0. There is only one axis of rotation in the course. Is it an idiot circle? No problem, I want to share a video below. I think this video will be more vivid than words. Please study it yourself.

After reading the matrix and Euler angle, let's look at quaternions. When a new concept of quaternion appeared in front of my eyes, I wondered if it was called quaternion because there were four numbers. In fact, quaternion is actually composed of a scalar component and a 3D vector component to express the direction. Two notations of quaternion are as follows: [ω, ν], [ω, (x, y, z).

Plural numbers have really been useless for a long time. We have been exposed to simple plural since high school. Now let's talk about the complex number briefly. Actually, I also reviewed it by the way

First, the complex number is in the form of a+bi, where I? =- 1, where a is called the real part (real part) and b is called the imaginary part (imaginary part). For the operation of complex numbers, we mainly talk about the modulus of complex numbers, which can well represent the rotation transformation in 2D. Let's first look at the rotation matrix in the 2D environment mentioned above.

Then, let's look at an example. Suppose a complex number v = (x, y) is rotated by θ degrees to get V', as shown in the figure below.

In order to complete this rotation, we need to introduce the second complex q = (cosθ, sinθ), and now the rotated complex v' can be calculated by complex multiplication. The calculation process is as follows.

v = x +yi

q = cosθ+isθ

v ' = VQ =(x+yi)(cosθ+isinθ)=(xcosθ-ysinθ)+(xsinθ+ycosθ)I

The effect of the rotation matrix is the same as that in the above 2D environment, but the form is different.

Having said so much, what is the relationship between quaternions and complex numbers? In fact, a quaternion [w, (x, y, z)] defines the complex number w +xi +yj +zk, which means that a quaternion contains a real part and three imaginary parts.

In fact, the emergence of quaternions also has a story. I will move the book directly as a relaxing moment in boring study (in fact, it is a natural egg? ), Irish mathematician Hamilton has always wanted to expand complex numbers from 2D to 3D. At first, he thought that the complex number in 3D should have a real part and two imaginary parts. Later, he didn't create such a meaningful complex number with a real part and two imaginary parts. 1948+0843, on his way to a lecture, he suddenly realized that there should be three imaginary numbers instead of two. He created this new equation for complex travelers in Bloom.

Me? = j? = k? = - 1

ij = k,ji = -k

jk = i,kj = -i

ki = j,ik = -j

We already know about the matrix and Euler angle. Now let's look at how quaternions represent angular displacement. In 3D environment, any angular displacement can be understood as rotation around an axis. In 3D Graphics: Matrix and Linear Transformation, there is a formula that rotates around any 3D axis (remember the initial verification process, which took a day? The formula is as follows, where θ represents the rotation angle and n represents the rotation axis. Therefore, the axis-angle pair (n, θ) defines an angular displacement: rotating θ around the axis specified by n. 。

The explanation of quaternion is actually the axial angle pair of angular displacement. But n and θ are not directly put into quaternions. Their forms are as follows.

Then the question is coming, why not put it directly in quaternion? There is a reason for this, and I will explain it in the next quaternion correlation operation. Now I know that the explanation of quaternion is actually the axial angle pair mode of angular displacement.

& lt/b & gt;

After writing this article, I finally have a general understanding of matrix, Euler angle, quaternion, angular displacement and orientation. On the whole, I felt really bored, but I persisted. I hope my friends can keep reading. If you don't understand or have questions, you can discuss with Sao Dong. I will continue to study quaternion in the next "3D Image", but only the knowledge related to quaternion operation. I hope everyone will continue to pay attention.

Finally, you should attach a Pdf version of the:> portal.