KQuaternion
kds-plugin-document / Exports / KQuaternion
Interface: KQuaternion
四元数(quaternion)是用来表示旋转变换的一种形式,它可以避免欧拉角的万向节死锁问题。
An interface representing quaternion. Quaternion is used for rotating models without encountering the dreaded gimbal lock issue, amongst other advantages.
Table of contents
Properties
Methods
- clone
- conjugate
- copyFrom
- dot
- fromArray
- getAngle
- getAxis
- isEqual
- length
- lengthSq
- multiply
- multiplyQuaternions
- normalize
- premultiply
- reverse
- set
- setFromAxisAngle
- setFromEuler
- setFromRotationMatrix
- setFromUnitVectors
- slerp
- swingTwistDecomposition
- toArray
Properties
w
• Readonly w: number
四元数的w实部。
The quaternion's w value.
Defined in
api.d.ts:10192
x
• Readonly x: number
四元数的x虚部。
The quaternion's x value.
Defined in
api.d.ts:10174
y
• Readonly y: number
四元数的y虚部。
The quaternion's y value.
Defined in
api.d.ts:10180
z
• Readonly z: number
四元数的z虚部。
The quaternion's z value.
Defined in
api.d.ts:10186
Methods
clone
▸ clone(): KQuaternion
克隆自己,返回一个新的四元数对象。
Get the cloned object of this quaternion.
Returns
返回一个新的克隆对象。
Return a new clone quaternion object.
Defined in
api.d.ts:10224
conjugate
▸ conjugate(): void
把自己变成自己的共轭形式。 共轭形式是指绕旋转轴转动相反角度。
Returns the rotational conjugate of this quaternion. The conjugate of a quaternion represents the same rotation in the opposite direction about the rotational axis.
Returns
void
Defined in
api.d.ts:10316
copyFrom
▸ copyFrom(quaternion): void
从另外一个四元数对象复制数据,覆盖自己的数据成员。
Copy values from another quaternion.
Parameters
| Name | Type | Description |
|---|---|---|
quaternion | KQuaternion | 输入另一个四元数。 The another quaternion. |
Returns
void
Defined in
api.d.ts:10234
dot
▸ dot(v): number
求取和另外一个四元数的点积。
Calculates the dot product of quaternions v and this one
Parameters
| Name | Type | Description |
|---|---|---|
v | KQuaternion | 输入另一个四元数。 The another quaternions. |
Returns
number
返回两个四元数的点积。
Return two quaternionss dot value.
Defined in
api.d.ts:10330
fromArray
▸ fromArray(array): void
从数组中读取数据,赋值给自己的数据成员。
Copy values (x, y, z and w) from an array with 4 elements.
Parameters
| Name | Type | Description |
|---|---|---|
array | number[] | 输入数组,含x, y, z, w信息。 The input array in [x, y, z, w]. |
Returns
void
Defined in
api.d.ts:10457
getAngle
▸ getAngle(): number
获取以弧度为单位的旋转角度。
Returns
number
返回旋转角度。
Angle of rotation about the axis, in radius.
Defined in
api.d.ts:10277
getAxis
▸ getAxis(): KVector3d
获取旋转轴。如果旋转角度是零的话,返回一个各分量为零的旋转轴。
Returns
返回旋转轴。
The axis of rotation (normalized); return a zero vector if angle of rotation is zero.
Defined in
api.d.ts:10268
isEqual
▸ isEqual(quaternion): boolean
判断是不是和联外一个四元数相等。
Whether two quaternions are equal.
Parameters
| Name | Type | Description |
|---|---|---|
quaternion | KQuaternion | 输入另一个四元数。 The another quaternion. |
Returns
boolean
返回两个四元数是否相等。
Return true if two quaternions are equal.
Defined in
api.d.ts:10447
length
▸ length(): number
求取这个四元数当成一个四维向量,求取它的欧几里得长度。
Computes the Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector.
Returns
number
返回欧几里得长度。
Return length.
Defined in
api.d.ts:10354
lengthSq
▸ lengthSq(): number
求取各元素的平方和。
Computes the Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector. This can be useful if you are comparing the lengths of two quaternions, as this is a slightly more efficient calculation than length().
Returns
number
返回各元素的平方和。
Return square length.
Defined in
api.d.ts:10343
multiply
▸ multiply(q): void
右乘一个四元数。
Multiplies this quaternion by q.
Parameters
| Name | Type | Description |
|---|---|---|
q | KQuaternion | 输入另一个四元数。 The another quaternion. |
Returns
void
Defined in
api.d.ts:10372
multiplyQuaternions
▸ multiplyQuaternions(a, b): void
把两个四元数的乘机结果赋值给自己。
Sets this quaternion to a x b.
Parameters
| Name | Type | Description |
|---|---|---|
a | KQuaternion | 输入一个四元数。 The input quaternion. |
b | KQuaternion | 输入另一个四元数。 The another quaternion. |
Returns
void
Defined in
api.d.ts:10396
normalize
▸ normalize(): void
归一化这个四元数。 归一化后它仍旧表示相同的旋转变换,只是长度变为1。
Normalizes this quaternion - that is, calculated the quaternion that performs the same rotation as this one, but has length equal to 1.
Returns
void
Defined in
api.d.ts:10362
premultiply
▸ premultiply(q): void
左乘一个四元数。
Pre-multiplies this quaternion by q.
Parameters
| Name | Type | Description |
|---|---|---|
q | KQuaternion | 输入另一个四元数。 The another quaternion. |
Returns
void
Defined in
api.d.ts:10382
reverse
▸ reverse(): void
把自己变成自己的逆变换。
Reverse this quaternion.
Returns
void
Defined in
api.d.ts:10307
set
▸ set(x, y, z, w): void
设置四元数的虚部和实部。
Set quaternion's x, y, z and w
Parameters
| Name | Type | Description |
|---|---|---|
x | number | 四元数的x虚部。 The quaternion's x value. |
y | number | 四元数的y虚部。 The quaternion's y value. |
z | number | 四元数的z虚部。 The quaternion's z value. |
w | number | 四元数的w实部。 The quaternion's w value. |
Returns
void
Defined in
api.d.ts:10214
setFromAxisAngle
▸ setFromAxisAngle(axis, angle): void
从绕某个给定轴旋转给定角度的表示形式转换成四元数的表示形式,并设置到自己的数据成员。
Sets this quaternion from rotation specified by axis and angle. NOTE: the axis will be normalized.
Parameters
| Name | Type | Description |
|---|---|---|
axis | KVector3d | 输入给定轴。 The input specified axis. |
angle | number | 输入旋转角度。 The input rotate angle in radians. |
Returns
void
Defined in
api.d.ts:10259
setFromEuler
▸ setFromEuler(euler): void
把一个欧拉角转化成四元数形式,并设置到自己的数据成员。
Set values by an input euler object.
Parameters
| Name | Type | Description |
|---|---|---|
euler | KEuler | 输入欧拉角。 The input euler. |
Returns
void
Defined in
api.d.ts:10244
setFromRotationMatrix
▸ setFromRotationMatrix(m): void
从一个变换矩阵提取旋转变换,转换成四元数形式,并设置到自己的数据成员。
Sets this quaternion from rotation component of the input matrix.
Parameters
| Name | Type | Description |
|---|---|---|
m | KMatrix4 | 输入变换矩阵。 The input matrix. |
Returns
void
Defined in
api.d.ts:10287
setFromUnitVectors
▸ setFromUnitVectors(vFrom, vTo): void
从一个向量到另外一个向量的旋转变化形式,转化成四元数表示形式,并设置到自己的数据成员。
Sets this quaternion to the rotation required to rotate direction vector vFrom to direction vector vTo.
Parameters
| Name | Type | Description |
|---|---|---|
vFrom | KVector3d | 输入被旋转的向量。 The input vector to be rotated. |
vTo | KVector3d | 输入旋转后的向量。 The input vector after rotation. |
Returns
void
Defined in
api.d.ts:10301
slerp
▸ slerp(qb, t): void
和另外一个四元数做球面线性插值。
Handles the spherical linear interpolation between quaternions. t represents the amount of rotation between this quaternion (where t is 0) and qb (where t is 1). This quaternion is set to the result.
Parameters
| Name | Type | Description |
|---|---|---|
qb | KQuaternion | 输入另一个四元数。 The another quaternion. |
t | number | 输入插值比例。 The interpolate ratio. |
Returns
void
Defined in
api.d.ts:10413
swingTwistDecomposition
▸ swingTwistDecomposition(direction, twist, swing): void
Decompose the rotation on to 2 parts http://www.euclideanspace.com/maths/geometry/rotations/for/decomposition/index.htm twist = rotation around the direction vector swing = rotation around axis that is perpendicular to direction vector rotate = swing * twist
Parameters
| Name | Type | Description |
|---|---|---|
direction | KVector3d | 输入方向向量。 The input direction vector. |
twist | KQuaternion | 输出绕方向向量旋转的四元数。 Update rotate quaternion around the direction vector. |
swing | KQuaternion | 输出绕垂直于方向向量的向量旋转的四元数。 Update rotate quaternion around axis that is perpendicular to direction vector. |
Returns
void
Defined in
api.d.ts:10433
toArray
▸ toArray(): number[]
四元数转成数据表达形式。
Convert to a array containing x, y, z, w.
Returns
number[]
返回数组[x, y, z, w]。
Return array in [x, y, z , w].
Defined in
api.d.ts:10467