四元数用于表示旋转。
A quaternion is a four-tuple of real numbers {x,y,z,w}. A quaternion is a mathematically convenient alternative to the euler angle representation. You can interpolate a quaternion without experiencing gimbal lock. You can also use a quaternion to concatenate a series of rotations into a single representation.
Unity internally uses Quaternions to represent all rotations.
In most cases, you can use existing rotations from methods such as Transform.localRotation or Transform.rotation to construct new rotations. For example, use existing rotations to smoothly interpolate between two rotations.
The most used Quaternion functions are as follows:
Quaternion.LookRotation, Quaternion.Angle, Quaternion.Euler, Quaternion.Slerp, Quaternion.FromToRotation, and Quaternion.identity.
您可以使用 Quaternion.operator * 对旋转进行旋转,或对向量进行旋转。
注意,Unity 使用的是标准化的四元数。
identity | 单位旋转(只读)。 |
eulerAngles | Returns or sets the euler angle representation of the rotation in degree. |
normalized | 返回该四元数,并且量值为 1(只读)。 |
this[int] | 分别使用 [0]、[1]、[2]、[3] 访问 x、y、z、w 分量。 |
w | 四元数的 w 分量。请勿直接修改四元数。 |
x | 四元数的 X 分量。除非您十分了解四元数,否则不要直接进行此种修改。 |
y | 四元数的 Y 分量。除非您十分了解四元数,否则不要直接进行此种修改。 |
z | 四元数的 Z 分量。除非您十分了解四元数,否则不要直接进行此种修改。 |
Quaternion | 使用给定的 x、y、z、w 分量构造新的四元数。 |
Set | 设置现有四元数的 x、y、z 和 w 分量。 |
SetFromToRotation | 创建一个从 fromDirection 旋转到 toDirection 的旋转。 |
SetLookRotation | 使用指定的 forward 和 upwards 方向创建旋转。 |
ToAngleAxis | 将旋转转换为“角-轴”表示形式(角度以度为单位)。 |
ToString | Returns a formatted string for this quaternion. |
Angle | Returns the angle in degrees between two rotations a and b. The resulting angle ranges from 0 to 180. |
AngleAxis | 创建一个围绕 axis 旋转 angle 度的旋转。 |
Dot | 两个旋转之间的点积。 |
Euler | 返回一个旋转,它围绕 z 轴旋转 z 度、围绕 x 轴旋转 x 度、围绕 y 轴旋转 y 度(按该顺序应用)。 |
FromToRotation | Creates a rotation from fromDirection to toDirection. |
Inverse | 返回 rotation 的反转。 |
Lerp | Interpolates between a and b by t and normalizes the result afterwards. |
LerpUnclamped | 在 a 和 b 之间插入 t,然后对结果进行标准化处理。参数 t 不受限制。 |
LookRotation | 使用指定的 forward 和 upwards 方向创建旋转。 |
Normalize | 将此四元数转换为 1,方向相同,但量值为 1。 |
RotateTowards | 将旋转 from 向 to 旋转。 |
Slerp | Spherically linear interpolates between unit quaternions a and b by a ratio of t. |
SlerpUnclamped | Spherically linear interpolates between unit quaternions a and b by t. |
operator * | 将旋转 lhs 和 rhs 组合到一起。 |
operator == | 两个四元数是否相等? |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.