Preliminary experience of rotating a coordinate point with quaternion in Unity3d

Source: Internet
Author: User
Tags cos

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))
    1. <span style="FONT-SIZE:12PX;"  > var M:vector3;
    2. var t1:quaternion;
    3. m = Vector3 (1,0,0);
    4. T1 = quaternion (0.7,0,0,0.7);
    5. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.