跳到主要内容

KQuaternion interface

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

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

Signature:

export interface KQuaternion 

Properties

Property

Modifiers

Type

Description

w

readonly

number

四元数的w实部。

The quaternion's w value.

x

readonly

number

四元数的x虚部。

The quaternion's x value.

y

readonly

number

四元数的y虚部。

The quaternion's y value.

z

readonly

number

四元数的z虚部。

The quaternion's z value.

Methods

Method

Description

clone()

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

Get the cloned object of this quaternion.

conjugate()

把自己变成自己的共轭形式。 共轭形式是指绕旋转轴转动相反角度。

Returns the rotational conjugate of this quaternion. The conjugate of a quaternion represents the same rotation in the opposite direction about the rotational axis.

copyFrom(quaternion)

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

Copy values from another quaternion.

dot(v)

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

Calculates the dot product of quaternions v and this one

fromArray(array)

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

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

getAngle()

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

返回旋转角度。

Angle of rotation about the axis, in radius.

getAxis()

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

返回旋转轴。

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

isEqual(quaternion)

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

Whether two quaternions are equal.

length()

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

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

lengthSq()

求取各元素的平方和。

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

multiply(q)

右乘一个四元数。

Multiplies this quaternion by q.

multiplyQuaternions(a, b)

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

Sets this quaternion to a x b.

normalize()

归一化这个四元数。 归一化后它仍旧表示相同的旋转变换,只是长度变为1。

Normalizes this quaternion - that is, calculated the quaternion that performs the same rotation as this one, but has length equal to 1.

premultiply(q)

左乘一个四元数。

Pre-multiplies this quaternion by q.

reverse()

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

Reverse this quaternion.

set(x, y, z, w)

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

Set quaternion's x, y, z and w

setFromAxisAngle(axis, angle)

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

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

setFromEuler(euler)

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

Set values by an input euler object.

setFromRotationMatrix(m)

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

Sets this quaternion from rotation component of the input matrix.

setFromUnitVectors(vFrom, vTo)

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

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

slerp(qb, t)

和另外一个四元数做球面线性插值。

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.

swingTwistDecomposition(direction, twist, swing)

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

toArray()

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

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