Version: 2023.1

Quaternion

struct in UnityEngine

切换到手册

描述

四元数用于表示旋转。

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返回或设置旋转的欧拉角表示。
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将旋转转换为“角-轴”表示形式(角度以度为单位)。
ToStringReturns a formatted string for this quaternion.

静态函数

Angle返回两个旋转 a 和 b 之间的角度(以度为单位)。
AngleAxis创建一个围绕 axis 旋转 angle 度的旋转。
Dot两个旋转之间的点积。
Euler返回一个旋转,它围绕 z 轴旋转 z 度、围绕 x 轴旋转 x 度、围绕 y 轴旋转 y 度(按该顺序应用)。
FromToRotationCreates a rotation from fromDirection to toDirection.
Inverse返回 rotation 的反转。
LerpInterpolates 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 旋转。
SlerpSpherically linear interpolates between unit quaternions a and b by a ratio of t.
SlerpUnclampedSpherically linear interpolates between unit quaternions a and b by t.

运算符

operator *将旋转 lhs 和 rhs 组合到一起。
operator ==两个四元数是否相等?