跳到主要内容

KQuaternion 接口

export interface KQuaternion 

四元数(quaternion)是用来表示旋转变换的一种形式,它可以避免欧拉角的万向节死锁问题。

An interface representing quaternion. Quaternion is used for rotating models without encountering the dreaded gimbal lock issue, amongst other advantages.

属性

w

readonly w: number;

四元数的w实部。

The quaternion's w value.

x

readonly x: number;

四元数的x虚部。

The quaternion's x value.

y

readonly y: number;

四元数的y虚部。

The quaternion's y value.

z

readonly z: number;

四元数的z虚部。

The quaternion's z value.

方法

clone

clone(): KQuaternion;

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

Get the cloned object of this quaternion.

返回值: KQuaternion

返回一个新的克隆对象。

Return a new clone quaternion object.

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.

返回值: void

copyFrom

copyFrom(quaternion: KQuaternion): void;

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

Copy values from another quaternion.

参数:

  • quaternion: KQuaternion

    输入另一个四元数。

    The another quaternion.

返回值: void

dot

dot(v: KQuaternion): number;

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

Calculates the dot product of quaternions v and this one

参数:

  • v: KQuaternion

    输入另一个四元数。

    The another quaternions.

返回值: number

返回两个四元数的点积。

Return two quaternionss dot value.

fromArray

fromArray(array: number[]): void;

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

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

参数:

  • array: number[]

    输入数组,含x, y, z, w信息。

    The input array in [x, y, z, w].

返回值: void

getAngle

getAngle(): number;

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

返回旋转角度。

Angle of rotation about the axis, in radius.

返回值: number

getAxis

getAxis(): KVector3d;

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

返回旋转轴。

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

返回值: KVector3d

isEqual

isEqual(quaternion: KQuaternion): boolean;

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

Whether two quaternions are equal.

参数:

  • quaternion: KQuaternion

    输入另一个四元数。

    The another quaternion.

返回值: boolean

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

Return true if two quaternions are equal.

length

length(): number;

求取这个四元数当成一个四维向量,求取它的欧几里得长度。

Computes the Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector.

返回值: number

返回欧几里得长度。

Return length.

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().

返回值: number

返回各元素的平方和。

Return square length.

multiply

multiply(q: KQuaternion): void;

右乘一个四元数。

Multiplies this quaternion by q.

参数:

  • q: KQuaternion

    输入另一个四元数。

    The another quaternion.

返回值: void

multiplyQuaternions

multiplyQuaternions(a: KQuaternion, b: KQuaternion): void;

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

Sets this quaternion to a x b.

参数:

  • a: KQuaternion

    输入一个四元数。

    The input quaternion.

  • b: KQuaternion

    输入另一个四元数。

    The another quaternion.

返回值: void

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.

返回值: void

premultiply

premultiply(q: KQuaternion): void;

左乘一个四元数。

Pre-multiplies this quaternion by q.

参数:

  • q: KQuaternion

    输入另一个四元数。

    The another quaternion.

返回值: void

reverse

reverse(): void;

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

Reverse this quaternion.

返回值: void

set

set(x: number, y: number, z: number, w: number): void;

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

Set quaternion's x, y, z and w

参数:

  • 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.

返回值: void

setFromAxisAngle

setFromAxisAngle(axis: KVector3d, angle: number): void;

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

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

参数:

  • axis: KVector3d

    输入给定轴。

    The input specified axis.

  • angle: number

    输入旋转角度。

    The input rotate angle in radians.

返回值: void

setFromEuler

setFromEuler(euler: KEuler): void;

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

Set values by an input euler object.

参数:

  • euler: KEuler

    输入欧拉角。

    The input euler.

返回值: void

setFromRotationMatrix

setFromRotationMatrix(m: KMatrix4): void;

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

Sets this quaternion from rotation component of the input matrix.

参数:

  • m: KMatrix4

    输入变换矩阵。

    The input matrix.

返回值: void

setFromUnitVectors

setFromUnitVectors(vFrom: KVector3d, vTo: KVector3d): void;

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

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

参数:

  • vFrom: KVector3d

    输入被旋转的向量。

    The input vector to be rotated.

  • vTo: KVector3d

    输入旋转后的向量。

    The input vector after rotation.

返回值: void

slerp

slerp(qb: KQuaternion, t: number): 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.

参数:

  • qb: KQuaternion

    输入另一个四元数。

    The another quaternion.

  • t: number

    输入插值比例。

    The interpolate ratio.

返回值: void

swingTwistDecomposition

swingTwistDecomposition(direction: KVector3d, twist: KQuaternion, swing: KQuaternion): 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

参数:

  • 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.

返回值: void

toArray

toArray(): number[];

四元数转成数据表达形式。

Convert to a array containing x, y, z, w.

返回值: number[]

返回数组[x, y, z, w]。

Return array in [x, y, z , w].