[Unity quaternion] four-dollar quaternion calculation method

Source: Internet
Author: User
Tags cos instance method sin

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

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.