Or we can also write it in the form of a matrix
Observing this formula, we found that multiplying two quaternions requires storing 8 units of data, that is, each quaternion involved in the operation only needs to store 4 units of data. In addition, several special properties are required:
Knowing the above calculation rules, we can use quaternions to calculate the direction transformation process. Remember that we said before that when calculating quaternions, we use vector form to represent them and ensure that they are unit quaternions? In fact, the vector form of quaternions can be further rewritten as polar representation, $q =\ | q\ | [cos\ theta,\ vec {n}\ cdot sin\ theta] $
Where q represents the modulus of the quaternion, the modulus of the quaternion is 1, and θ is the half-angle size of the rotation process represented by the quaternion, that is to say, (2θ) is the size of the rotation angle, and n is the rotation axis. The unit vector of direction. With this representation, the quaternion can represent the direction transformation expressed by any axis angle.
First, the original vector coordinates are expressed as quaternions $p = [0,\ vec {v}] $, and the rotation angle and rotation axis are expressed as unit quaternions q. The rotated vector coordinates can be obtained by $r = q\ cdot p\ cdot q ^ * $or $r = q\ cdot p\ cdot q ^ {-1} $
In fact, the quaternion is to better represent the rotation axis and rotation angle. The rotation axis is a three-dimensional vector, and the rotation angle becomes four-dimensional. The quaternion was chosen to represent it because of some of its characteristics.
Let’s start with the conclusion that quaternion references are used to reduce the amount of computation and storage space occupied during computation.
However, if you are careful enough, you can definitely find that the process of multiplying two quaternions is actually a process of multiplying a 4 × 4 matrix with a 4 × 1 matrix, and the quaternion calculation requires two times this process, including 24 addition operations and 32 multiplication operations. In contrast, the matrix transformation of the Euler angle only needs to perform a multiplication operation of a 3 × 3 matrix and a 3 × 1 matrix, including 6 addition operations and 9 multiplication operations. The amount of operation is obviously Quaternion is larger. If you are more careful, you can find that although there is a 4 × 4 matrix involved in the operation of the quaternion operation, each item in the matrix is the unit data that has been stored, and the 3 × 3 matrix involved in the Euler angle operation It is obtained by 16 multiplication operations, 4 addition operations and 4 sign change operations performed on the stored unit data, but even with these operations, the matrix operation only needs 25 multiplication operations, 10 addition operations and 4 sign change operations. In terms of computational volume, the matrix operation of Euler angles still has an advantage over the quaternion operation. But in fact, the kinematics problems we generally encounter rarely have to do only one direction conversion. For complex systems and robots, we often face a large number of direction conversion processes. In this case, the advantages of quaternions are reflected. We consider quaternion operations for multiple transformations (using the polar coordinate form above):
Use associative law:
Consider the conjugate $ (q_aq_b) ^ *= q ^ * _bq ^ * _a $
It can be found that the operation result in the parentheses on the left and right sides of the original vector ppp is a pair of conjugated quaternions, that is to say, the 3-th easy sign operation can be used instead of the n-th quaternion multiplication operation, which greatly reduces the amount of calculation.
Finally, a little mention, a lot of people who come into contact with this problem are game developers, may have doubts, why there is no such problem in Unity’s Inspector, you can try this, Unity’s Inspector in the Y axis is not the object’s own coordinate axis rotation, so the universal lock is solved, the specific Unity internal rotation is how to see the next blog, here to dig a pit
Reference article: