Skip to main content

Class: Quaternion

四元数,主要用于在三维世界描述旋转

const a = new Quaternion(0, 0, 0, 0);

Hierarchy

  • default

    Quaternion

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Quaternion(x?, y?, z?, w?): Quaternion

Parameters

NameTypeDefault valueDescription
xnumber0x 坐标,默认为 0
ynumber0y 坐标,默认为 0
znumber0z 坐标,默认为 0
wnumber0w 坐标,默认为 0

Returns

Quaternion

Overrides

Vector.constructor

Defined in

src/math/Quaternion.ts:45

Properties

elements

elements: Float32Array | Float64Array

Overrides

Vector.elements

Defined in

src/math/Quaternion.ts:35

Accessors

x

get x(): number

获取 x 值

Returns

number

number;

Defined in

src/math/Quaternion.ts:58

set x(x): void

设置 x 值

Parameters

NameType
xnumber

Returns

void

Defined in

src/math/Quaternion.ts:66


y

get y(): number

获取 y 值

Returns

number

number;

Defined in

src/math/Quaternion.ts:75

set y(y): void

设置 y 值

Parameters

NameType
ynumber

Returns

void

Defined in

src/math/Quaternion.ts:83


z

get z(): number

获取 z 值

Returns

number

number;

Defined in

src/math/Quaternion.ts:92

set z(z): void

设置 z 值

Parameters

NameType
znumber

Returns

void

Defined in

src/math/Quaternion.ts:100


w

get w(): number

获取 w 值

Returns

number

number;

Defined in

src/math/Quaternion.ts:109

set w(w): void

设置 w 值

Parameters

NameType
wnumber

Returns

void

Defined in

src/math/Quaternion.ts:117

Methods

fromObject

fromObject(object): Quaternion

从对象赋值 Quaternion 的 x、y、z、w 值

Parameters

NameType
objectObject
object.xany
object.yany
object.zany
object.wany

Returns

Quaternion

Defined in

src/math/Quaternion.ts:126


toObject

toObject(): Object

转换到对象

Returns

Object

NameType
xnumber
ynumber
znumber
wnumber

Defined in

src/math/Quaternion.ts:138


fromAxisAngle

fromAxisAngle(axis, rad): Quaternion

给定的角度和旋转轴设置此四元数的值

Parameters

NameType
axisVector3
radnumber

Returns

Quaternion

Defined in

src/math/Quaternion.ts:152


getAxisAngle

getAxisAngle(axis?): any

从此四元数获取旋转轴和旋转角度

Parameters

NameType
axisVector3

Returns

any

Defined in

src/math/Quaternion.ts:162


fromEuler

fromEuler(e): Quaternion

从给定的欧拉角 e 创建四元数

Parameters

NameType
eEuler

Returns

Quaternion

Defined in

src/math/Quaternion.ts:172


fromMat3

fromMat3(m): Quaternion

从给定的 3x3 旋转矩阵创建四元数

Parameters

NameType
mMatrix3

Returns

Quaternion

Defined in

src/math/Quaternion.ts:182


set

set(x, y, z, w): Quaternion

Parameters

NameType
xany
yany
zany
wany

Returns

Quaternion

Defined in

src/math/Quaternion.ts:187


length

length(): any

计算四元数的直线长度

Returns

any

Defined in

src/math/Quaternion.ts:196


multiply

multiply(a, b?): Quaternion

计算四元数的乘积

Parameters

NameType
aQuaternion
b?Quaternion

Returns

Quaternion

Defined in

src/math/Quaternion.ts:205


slerp

slerp(q, t): Quaternion

处理四元数之间的球面线性插值

Parameters

NameType
qQuaternion
tnumber

Returns

Quaternion

Defined in

src/math/Quaternion.ts:221


invert

invert(): Quaternion

翻转该四元数

Returns

Quaternion

Defined in

src/math/Quaternion.ts:230


conjugate

conjugate(): Quaternion

计算此四元数的旋转共轭(围绕旋转轴在相反方向上的旋转)

Returns

Quaternion

Defined in

src/math/Quaternion.ts:239


normalize

normalize(): Quaternion

(归一化)四元数。 即计算与该四元数具有相同旋转、但长度为1的四元数

Returns

Quaternion

Defined in

src/math/Quaternion.ts:248


dot

dot(q): any

计算四元数 q 与当前四元数的点积

Parameters

NameType
qQuaternion

Returns

any

Defined in

src/math/Quaternion.ts:258


angleTo

angleTo(q): any

以弧度返回该四元数与四元数 q 之间的夹角。

Parameters

NameType
qQuaternion

Returns

any

Defined in

src/math/Quaternion.ts:266


clone

clone(): Quaternion

创建一个与该四元数具有相同x、y、z和w 属性的四元数

Returns

Quaternion

Defined in

src/math/Quaternion.ts:273


copy

copy(q): Quaternion

复制四元数 q 的 x、y、z 和 w 属性到该四元数中。

Parameters

NameType
qQuaternion

Returns

Quaternion

Defined in

src/math/Quaternion.ts:281


equals

equals(q): any

比较两个四元数是否相同

Parameters

NameType
qQuaternion

Returns

any

Defined in

src/math/Quaternion.ts:291


onChange

onChange(fn): void

监听四元数变更

Parameters

NameTypeDescription
fnICallback回调函数

Returns

void

Defined in

src/math/Quaternion.ts:299


triggerChange

triggerChange(): void

触发所有的回调函数

Returns

void

Defined in

src/math/Quaternion.ts:308


toString

toString(): string

转换为字符串

Returns

string

Defined in

src/math/Quaternion.ts:315


fromArray

fromArray(array, offset?): Quaternion

从数组构建向量数据

Parameters

NameTypeDefault valueDescription
arrayanyundefined原始数组
offsetnumber0数组偏移量

Returns

Quaternion

Inherited from

Vector.fromArray

Defined in

src/math/Vector.ts:15


toArray

toArray(out?, offset?): Float32Array | Float64Array | number[]

从向量转换到数组

Parameters

NameTypeDefault valueDescription
outFloat32Array | Float64Array | number[][]输出数据
offsetnumber0偏移量

Returns

Float32Array | Float64Array | number[]

Inherited from

Vector.toArray

Defined in

src/math/Vector.ts:28