Abstract
There are many types of expressions of rotation, including oarla, rotation matrix, axis angle, and four elements. What we want to learn today is the most commonly used four elements in game development.
From the Euclidean and axial angles to the Quaternary
Before talking about the four elements, let's take a look at the simple angle and the axial angle.
The Euclidean angle uses the simplest values of X, Y, and Z to indicate the rotation angles on the X, Y, and Z axes respectively. The values are 0-360 (or 0-2 pi). Generally, roll is used, pitch and yaw are used to indicate the rotation values of these components. Note that the rotation here is for the world coordinate system, which means that the first rotation will not affect the second or third axis.
The problems that may easily occur in the ouarla corner are: 1) the rotation axis is not easy to be interpolated in any direction; 2) the universal joint deadlock; 3) the order of rotation cannot be determined.
The axis angle is a rotation angle defined by the unit vector, and a scalar rotation angle is added to indicate rotation. Usually [x, y, z, theta], the first three represent the axis, and the last one represent the angle. The representation is intuitive and compact.
One of the biggest limitations of the axis angle is that it cannot be simply interpolated. In addition, rotation in the axis angle form cannot be directly applied to points or vectors and must be converted to a matrix or four elements.
The four elements are like the evolution of the axis angle. They also use a three-dimensional vector to represent the axis and an angle component to represent the rotation angle around the axis, that is, (X, Y, Z, W ), where
w = cos(theta/2) x = ax * sin(theta/2) y = ay * sin(theta/2) z = az * sin(theta/2)
(Ax, ay, AZ) indicates the axis vector, and theta indicates the rotation angle around this axis. Each number in the Quaternary element is a processed axis and angle. The four tuples described in the axis angle are not something in a space. First (ax, ay, AZ) it is a vector under a three-dimensional coordinate, while Theta is the angle under the level coordinate. Simply combining them together does not guarantee the stability of their interpolation results, because they cannot be normalized, therefore, it cannot be ensured that the length of the vector obtained after the final interpolation (the distance between two points after the Rotation Transformation) is equal, while the Quaternary element is in a unified four-dimensional space, facilitating normalization for interpolation, the Axis and angle can be easily obtained for the information data of 3D images, so it is not appropriate to use the Quaternary element. Compared with the matrix, the four elements only need to store four floating point numbers, which has obvious advantages.
Related computing of four elements
Multiplication
Given two element numbers, p and q, represent the p and q rotation respectively, the product PQ indicates the synthesis of the two rotating elements (I .e., after the Q is rotated, P is rotated), rather than the addition. The multiplication of the Quaternary element is defined as follows. A simple allocation law is used:
Q1 * q2 =
(W1 * W2-X1 * x2-Y1 * Y2-z1 * Z2) +
(W1 * X2 + X1 * W2 + Y1 * Z2-z1 * Y2) I +
(W1 * Y2-X1 * Z2 + Y1 * W2 + z1 * x2) J +
(W1 * Z2 + X1 * Y2-Y1 * X2 + z1 * W2) k
Q = W + x I + y j + z K can be divided into pure W and vector x I + y j + z K, Q is expressed as (S, v), where S represents a pure volume of W, V represents the vector x I + y j + z K, so the multiplication of the Quaternary element can also be expressed:
Q1 * q2 = (S1 + V1) * (s2 + V2) = S1 * S2-v1.v2 + v1xv2 + S1 * V2 + S2 * V1
Modulo
N (q) = | q | = x2 + Y2 + z2 + W2
Unitization
Normalize (q) = Q/| q | = Q/(x2 + Y2 + z2 + W2)
Search for the combination
Q * = (-X,-y,-Z, W)
Inverse
For the definition of vector inverse, Q-1 = Q */| q |2
For the unit of four elements, the denominator is 1, Q-1 = Q * = (-X,-y,-Z, W)
Rotate a vector with a quaternary Element
Given a vector V, then given a rotation unit, the four elements Q, let v rotate Q.
First, rewrite V to the form of four elements v = (X, Y, Z, 0). Then, to rotate V, multiply it by the vector V before Q, and then multiply it by Q.-1.
V' = qvq-1
Of course, the same is true if Q is multiplied by the following, because all elements are four elements.
If you want to rotate multiple Enis, for example, r = r1r2r3.
Pay attention to the sequence.
Linear interpolation of Quaternary element and spherical linear interpolation
The convenient interpolation of the four elements is the biggest advantage of the four elements. Linear interpolation is the simplest and highly efficient. Given two rotating four elements QA and QB represent rotating a and B, find the rotating t between rotating a and rotating B:
Note that t actually follows T on the string rather than on the sphere. This will cause the angle change to be not constant when T changes at a constant speed.
To solve this problem, a spherical linear interpolation occurs. Given the four elements Q and Q,
Theta is the angle between two four elements,
Conversion of four elements
Four-element conversion to ouarla
Four Elements
Four-element rotation matrix
Reference
Game Engine architecture Chapter 4
Computer Graphics: quad-data and computation-http://openhome.cc/Gossip/ComputerGraphics/QuaternionsRotate.htm
Quaternion (Quaternary) and rotation as well as the meaning of yaw, pitch, roll--http://www.wy182000.com/2012/07/17/quaternion%E5%9B%9B%E5%85%83%E6%95%B0%E5%92%8C%E6%97%8B%E8%BD%AC%E4%BB%A5%E5%8F%8Ayaw-pitch-roll-%E7%9A%84%E5%90% AB %E4%B9%89/
Thoroughly understand the Quaternary Element