In Unity3d, the rotation is represented by a number of four yuan, and the number of four is called quaternion. For example, Transform.rotation is a four-dollar number, which consists of four parts quaternion = (xi + YJ + ZK + W) = (x,y,z,w)
1. Http://en.wikipedia.org/wiki/Quaternion has a definition of four yuan
2. Http://en.wikipedia.org/wiki/Quaternions_%26_spatial_rotation about the basic concepts and usage of the rotation of the four-dollar number
quaternion (x, Y, z) is related to the axis of revolution, W is related to the angle of rotation around the axis, because they all have to go through algebra to derive the axis of rotation and the angle of rotation. In Unity3d, the quaternion multiplication operation (operator * There are two types of operations:
(1) quaternion * quaternion, e.g. q = t * p; This is to rotate a point first with the T operation and then the P operation.
(2) quaternion * Vector3, such as P:vector3, T:quaternion, q:quaternion; q = t * p; This is the rotation of the point P-precession T operation;
I'm doing a 2nd operation, which is to rotate a vector;
First, the basic mathematical equations for quaternion are: Q = cos (A/2) + i (x * sin (A/2)) + j (Y * sin (A/2)) + K (z * sin (A/2)) (A is the rotation angle)
Q.W = cos (ANGLE/2)
q.x = axis.x * sin (ANGLE/2)
q.y = Axis.y * sin (ANGLE/2)
q.z = axis.z * sin (ANGLE/2)
As long as we have an angle, we can give four parts of the value of four yuan, for example, I want to let the point M=vector3 (o,p,q) rotate 90 degrees clockwise around the x axis, then the corresponding quaternion value should be:
Q:quaternion;
q.x = 1 * sin (90 degrees/2) = sin (45 degrees) = 0.7071
Q.Y = 0;
q.z = 0;
Q.W = cos (90 degrees/2) = cos (45 degrees) = 0.7071
Q = (0.7071, 0, 0, 0.7071);
m = Q * m; (The point m is rotated 90 degrees clockwise around the x-axis (1,0,0))
- <span style="FONT-SIZE:12PX;" > var M:vector3;
- var t1:quaternion;
- m = Vector3 (1,0,0);
- T1 = quaternion (0.7,0,0,0.7);
- m = t1*m;</span>
This is the most basic use of quaternion, the main point of view, you can calculate the quaternion, and then the point coordinate rotation.
Preliminary experience of rotating a coordinate point with quaternion in Unity3d