Quaternion is a combination of a scalar and a 3D vector. q={W,x,y,z},ogre a default quaternion ={1,0,0,0}, generally used for a bit of space rotation, assuming that the space is called p, the rotation angle is α, the axis of rotation is (x, Y, z), then:
P={0,x0,y0,z0}
q= {cos (α/2), Sina (α/2) nx, sin (α/2)ny, sin (α/2)nz} (n is a unit vector)
P Results =q*p*q-1
Mathematically, quaternion represents complex W+xi+yj+zk, where i,j,k are imaginary units, and the geometric meaning of complex multiplication (fork multiplication) is actually the rotation of the complex number. This is why Ogre uses quaternion (faster and more space-saving than matrix), for the simplest two-dimensional complex p= x + yi, and another q = (conα,sinα) multiplied, it means to rotate the P counterclockwise direction α:p ' = PQ, which is 2D rotation.
If you want to represent 3D rotation, you need 3D complex number, so there is "four Yuan", Q=w+ix+jy+kz (I,j,k are imaginary)
The j,j,k relationship is as follows:
i2 = J2 = K2 =-1
I * j = k =-j * I
J * k = i = k * J
K * i = j =-I * k
Four dollar addition:
Q1 + q2 = (W1+W2) + (X1+X2) i + (y1+y2) j + (Z1+Z2) k
Four-tuple 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
The multiplication is defined in the Ogre source code:
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
);
}
Original address: http://www.beyondc.cn