What is quaternion four-dollar number
In 1843, William Rowan Hamilton invented four yuan, but only in 1985 did a man named Ken Shoemake introduce four dollars into the field of computer graphics processing. Four yuan in 3D graphics is mainly used for rotation, skeletal animation and so on.
Simply put, a four-dollar number describes a rotation: rotates one radian (θ) around any axis (V).
Then the four-dollar Q is related to (v,θ) two parameters.
Specific formula:
Q = (sin (θ/2) * V,cos (θ/2))
Q = (sin (θ/2) * X,sin (θ/2) * Y,sin (θ/2) * Z,cos (θ/2))
using the Quaternion object in UnityCreate a Quaternion object
float radians = 90/360f * Mathf.pi * 2;//vector3 n = vector3.up;//float w = mathf.cos (RADIANS/2);//float s = mathf. Sin (RADIANS/2);//float x = n.x * S;float y = n.y * s;float z = n.z * s;//transform.rotation = new quaternion (x, Y, Z, W);
The code above allows you to set a game object to rotate clockwise 90 degrees along the y-axis upward direction.
Methods for quaternion objectsinstance Method
Set usage
float radians = degress/360f * Mathf.pi * 2;//vector3 n = vector3.up;//float w = mathf.cos (RADIANS/2);//float s = M ATHF. Sin (RADIANS/2);//float x = n.x * S;float y = n.y * s;float z = n.z * s;//quaternion q = new quaternion (); Q.set (x, Y, Z, w);//transform.rotation = q;
Setfromratation usage
quaternion q = new quaternion (); Q.setfromtorotation (Vector3.up, vector3.left);//transform.rotation = q;
Setlookrotation usage
quaternion q = new quaternion (); q.setlookrotation (vector3.back);//transform.rotation = q;
Static Methods
Transform.rotation = Quaternion.identity;//transform.rotation = Quaternion.angleaxis (degress, Vector3.up);// Transform.rotation = Quaternion.dot (Q1, q2);//transform.rotation = Quaternion.inverse (q1);//transform.rotation = Quaternion.lerp (q1,q2,time.deltatime);//transform.rotation = Quaternion.slerp (Q1, Q2, time.deltatime);
[Unity quaternion] four-dollar quaternion calculation method