Quaternion is a combination of scalar and a 3D vector. Q = {w, x, y, z}, a default quaternion = {,} In ogre, which is usually used for space rotation. Assume that space is called P at a point, if the rotation angle to be rotated is α and the rotation axis is (x, y, z), then:
P = {0, x0, y0, z0}
Q = {cos (α/2), Sina (α/2)NX, sin (α/2)NY, sin (α/2)NZ }(NUnit vector)
P result = Q * p * q-1
In mathematics, quaternion indicates the plural W + Xi + YJ + ZK, where I, j, and K are all virtual number units, while the plural multiplication (Cross multiplication) in fact, it is to rotate the plural. This is also why the Ogre uses quaternion (faster and more space-saving than matrix). For the simplest Two-Dimensional Complex p = x + yi, And the other q = (con α, if sin α) is multiplied, P is rotated counterclockwise. α: P' = PQ, Which is 2D.
If you want to represent 3D Rotation, you need a 3D complex number, so you have a "Z", q = W + ix + JY + KZ (I, j, k are all virtual numbers)
The relationship between J, J, and K is as follows:
I2 = J2 = K2 =-1
I * j = k =-J * I
J * k = I =-K * j
K * I = J =-I * k
Four element addition:
Q1 + q2 = (W1 + W2) + (X1 + x2) I + (Y1 + y2) J + (Z1 + Z2) k
Four-element multiplication:
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 * X1) J +
(W1 * Z2 + X1 * Y2-Y1 * X2 + z1 * W2) k
In the source code of ogre, multiplication is defined as follows:
Quaternion quaternion: Operator * (const quaternion & rkq) const
{
// Cases p * Q! = Q * P.
Return Quaternion
(
W * rkq. W-x * rkq. x-y * rkq. Y-z * rkq. Z,
W * rkq. x + x * rkq. W + y * rkq. z-z * rkq. y,
W * rkq. Y + y * rkq. W + z * rkq. X-x * rkq. Z,
W * rkq. Z + z * rkq. W + x * rkq. Y-y * rkq. x
);
}