Skip to main content

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​

Properties​

w​

• Readonly w: number

四元数的w实部。

The quaternion's w value.

Defined in​

api.d.ts:11791


x​

• Readonly x: number

四元数的x虚部。

The quaternion's x value.

Defined in​

api.d.ts:11773


y​

• Readonly y: number

四元数的y虚部。

The quaternion's y value.

Defined in​

api.d.ts:11779


z​

• Readonly z: number

四元数的z虚部。

The quaternion's z value.

Defined in​

api.d.ts:11785

Methods​

clone​

▸ clone(): KQuaternion

克隆自己,返回一个新的四元数对象。

Get the cloned object of this quaternion.

Returns​

KQuaternion

返回一个新的克隆对象。

Return a new clone quaternion object.

Defined in​

api.d.ts:11823


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:11915


copyFrom​

▸ copyFrom(quaternion): void

从另外一个四元数对象复制数据,覆盖自己的数据成员。

Copy values from another quaternion.

Parameters​

NameTypeDescription
quaternionKQuaternion输入另一个四元数。 The another quaternion.

Returns​

void

Defined in​

api.d.ts:11833


dot​

▸ dot(v): number

求取和另外一个四元数的点积。

Calculates the dot product of quaternions v and this one

Parameters​

NameTypeDescription
vKQuaternion输入另一个四元数。 The another quaternions.

Returns​

number

返回两个四元数的点积。

Return two quaternionss dot value.

Defined in​

api.d.ts:11929


fromArray​

▸ fromArray(array): void

从数组中读取数据,赋值给自己的数据成员。

Copy values (x, y, z and w) from an array with 4 elements.

Parameters​

NameTypeDescription
arraynumber[]输入数组,含x, y, z, w信息。 The input array in [x, y, z, w].

Returns​

void

Defined in​

api.d.ts:12056


getAngle​

▸ getAngle(): number

获取以弧度为单位的旋转角度。

Returns​

number

返回旋转角度。

Angle of rotation about the axis, in radius.

Defined in​

api.d.ts:11876


getAxis​

▸ getAxis(): KVector3d

获取旋转轴。如果旋转角度是零的话,返回一个各分量为零的旋转轴。

Returns​

KVector3d

返回旋转轴。

The axis of rotation (normalized); return a zero vector if angle of rotation is zero.

Defined in​

api.d.ts:11867


isEqual​

▸ isEqual(quaternion): boolean

判断是不是和联外一个四元数相等。

Whether two quaternions are equal.

Parameters​

NameTypeDescription
quaternionKQuaternion输入另一个四元数。 The another quaternion.

Returns​

boolean

返回两个四元数是否相等。

Return true if two quaternions are equal.

Defined in​

api.d.ts:12046


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:11953


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:11942


multiply​

▸ multiply(q): void

右乘一个四元数。

Multiplies this quaternion by q.

Parameters​

NameTypeDescription
qKQuaternion输入另一个四元数。 The another quaternion.

Returns​

void

Defined in​

api.d.ts:11971


multiplyQuaternions​

▸ multiplyQuaternions(a, b): void

把两个四元数的乘机结果赋值给自己。

Sets this quaternion to a x b.

Parameters​

NameTypeDescription
aKQuaternion输入一个四元数。 The input quaternion.
bKQuaternion输入另一个四元数。 The another quaternion.

Returns​

void

Defined in​

api.d.ts:11995


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:11961


premultiply​

▸ premultiply(q): void

左乘一个四元数。

Pre-multiplies this quaternion by q.

Parameters​

NameTypeDescription
qKQuaternion输入另一个四元数。 The another quaternion.

Returns​

void

Defined in​

api.d.ts:11981


reverse​

▸ reverse(): void

把自己变成自己的逆变换。

Reverse this quaternion.

Returns​

void

Defined in​

api.d.ts:11906


set​

▸ set(x, y, z, w): void

设置四元数的虚部和实部。

Set quaternion's x, y, z and w

Parameters​

NameTypeDescription
xnumber四元数的x虚部。 The quaternion's x value.
ynumber四元数的y虚部。 The quaternion's y value.
znumber四元数的z虚部。 The quaternion's z value.
wnumber四元数的w实部。 The quaternion's w value.

Returns​

void

Defined in​

api.d.ts:11813


setFromAxisAngle​

▸ setFromAxisAngle(axis, angle): void

从绕某个给定轴旋转给定角度的表示形式转换成四元数的表示形式,并设置到自己的数据成员。

Sets this quaternion from rotation specified by axis and angle. NOTE: the axis will be normalized.

Parameters​

NameTypeDescription
axisKVector3d输入给定轴。 The input specified axis.
anglenumber输入旋转角度。 The input rotate angle in radians.

Returns​

void

Defined in​

api.d.ts:11858


setFromEuler​

▸ setFromEuler(euler): void

把一个欧拉角转化成四元数形式,并设置到自己的数据成员。

Set values by an input euler object.

Parameters​

NameTypeDescription
eulerKEuler输入欧拉角。 The input euler.

Returns​

void

Defined in​

api.d.ts:11843


setFromRotationMatrix​

▸ setFromRotationMatrix(m): void

从一个变换矩阵提取旋转变换,转换成四元数形式,并设置到自己的数据成员。

Sets this quaternion from rotation component of the input matrix.

Parameters​

NameTypeDescription
mKMatrix4输入变换矩阵。 The input matrix.

Returns​

void

Defined in​

api.d.ts:11886


setFromUnitVectors​

▸ setFromUnitVectors(vFrom, vTo): void

从一个向量到另外一个向量的旋转变化形式,转化成四元数表示形式,并设置到自己的数据成员。

Sets this quaternion to the rotation required to rotate direction vector vFrom to direction vector vTo.

Parameters​

NameTypeDescription
vFromKVector3d输入被旋转的向量。 The input vector to be rotated.
vToKVector3d输入旋转后的向量。 The input vector after rotation.

Returns​

void

Defined in​

api.d.ts:11900


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​

NameTypeDescription
qbKQuaternion输入另一个四元数。 The another quaternion.
tnumber输入插值比例。 The interpolate ratio.

Returns​

void

Defined in​

api.d.ts:12012


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​

NameTypeDescription
directionKVector3d输入方向向量。 The input direction vector.
twistKQuaternion输出绕方向向量旋转的四元数。 Update rotate quaternion around the direction vector.
swingKQuaternion输出绕垂直于方向向量的向量旋转的四元数。 Update rotate quaternion around axis that is perpendicular to direction vector.

Returns​

void

Defined in​

api.d.ts:12032


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:12066