Class: Quaternion

Quaternion

new Quaternion(x, y, z, w)

Name Type Default Description
x Number 0 optional

X component

y Number 0 optional

Y component

z Number 0 optional

Z component

w Number 1 optional

W component

Members Show Inherited

Name Type Default Description
className String Quaternion

类名

isQuaternion Boolean true
elements Float32Array

数据

x Number

X component

y Number

Y component

z Number

Z component

w Number

W component

Methods Show Inherited

Copy the values from one quat to this

Name Type Description
q Quaternion
Returns:
Type Description
Quaternion this

Creates a new quat initialized with values from an existing quaternion

Returns:
Type Description
Quaternion a new quaternion

toArray(array, offset){Array}

转换到数组

Name Type Default Description
array Array.<number> | TypedArray [] optional

数组

offset Number 0 optional

数组偏移值

Returns:
Type Description
Array

fromArray(array, offset){Quaternion}

从数组赋值

Name Type Default Description
array Array.<number> | TypedArray

数组

offset Number 0 optional

数组偏移值

Returns:
Type Description
Quaternion this

Set the components of a quat to the given values

Name Type Description
x Number

X component

y Number

Y component

z Number

Z component

w Number

W component

Returns:
Type Description
Quaternion this

Set this to the identity quaternion

Returns:
Type Description
Quaternion this

Sets a quaternion to represent the shortest rotation from one vector to another.

Name Type Description
a Vector3

the initial vector

b Vector3

the destination vector

Returns:
Type Description
Quaternion this

setAxes(view, right, up){Quaternion}

Sets the specified quaternion with values corresponding to the given axes. Each axis is a vec3 and is expected to be unit length and perpendicular to all other specified axes.

Name Type Description
view Vector3

the vector representing the viewing direction

right Vector3

the vector representing the local "right" direction

up Vector3

the vector representing the local "up" direction

Returns:
Type Description
Quaternion this

setAxisAngle(axis, rad){Quaternion}

Sets a quat from the given angle and rotation axis, then returns it.

Name Type Description
axis Vector3

the axis around which to rotate

rad Number

the angle in radians

Returns:
Type Description
Quaternion this

getAxisAngle(out_axis){Number}

Gets the rotation axis and angle for a given quaternion. If a quaternion is created with setAxisAngle, this method will return the same values as providied in the original parameter list OR functionally equivalent values. Example: The quaternion formed by axis [0, 0, 1] and angle -90 is the same as the quaternion formed by [0, 0, 1] and 270. This method favors the latter.

Name Type Description
out_axis Vector3

Vector receiving the axis of rotation

Returns:
Type Description
Number Angle, in radians, of the rotation

Adds two quat's

Name Type Description
q Quaternion
Returns:
Type Description
Quaternion this

Multiplies two quat's

Name Type Description
q Quaternion
Returns:
Type Description
Quaternion this

premultiply the quat

Name Type Description
q Quaternion
Returns:
Type Description
Quaternion this

Scales a quat by a scalar number

Name Type Description
scale Vector3

the vector to scale

Returns:
Type Description
Quaternion this

Rotates a quaternion by the given angle about the X axis

Name Type Description
rad Number

angle (in radians) to rotate

Returns:
Type Description
Quaternion this

Rotates a quaternion by the given angle about the Y axis

Name Type Description
rad Number

angle (in radians) to rotate

Returns:
Type Description
Quaternion this

Rotates a quaternion by the given angle about the Z axis

Name Type Description
rad Number

angle (in radians) to rotate

Returns:
Type Description
Quaternion this

Calculates the W component of a quat from the X, Y, and Z components. Assumes that quaternion is 1 unit in length. Any existing W component will be ignored.

Returns:
Type Description
Quaternion this

dot(q){Number}

Calculates the dot product of two quat's

Name Type Description
q Quaternion
Returns:
Type Description
Number dot product of two quat's

Performs a linear interpolation between two quat's

Name Type Description
q Quaternion
t Number

interpolation amount between the two inputs

Returns:
Type Description
Quaternion this

Performs a spherical linear interpolation between two quat

Name Type Description
q Quaternion
t Number

interpolation amount between the two inputs

Returns:
Type Description
Quaternion this

sqlerp(qa, qb, qc, qd, t){Quaternion}

Performs a spherical linear interpolation with two control points

Name Type Description
qa Quaternion
qb Quaternion
qc Quaternion
qd Quaternion
t Number

interpolation amount

Returns:
Type Description
Quaternion this

Calculates the inverse of a quat

Returns:
Type Description
Quaternion this

Calculates the conjugate of a quat If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.

Returns:
Type Description
Quaternion this

length(){Number}

Calculates the length of a quat

Returns:
Type Description
Number length of this

squaredLength(){Number}

Calculates the squared length of a quat

Returns:
Type Description
Number squared length of this

Normalize this

Returns:
Type Description
Quaternion this

Creates a quaternion from the given 3x3 rotation matrix.

NOTE: The resultant quaternion is not normalized, so you should be sure to renormalize the quaternion yourself where necessary.

Name Type Description
m Matrix3

rotation matrix

Returns:
Type Description
Quaternion this

Creates a quaternion from the given 3x3 rotation matrix.

NOTE: The resultant quaternion is not normalized, so you should be sure to renormalize the quaternion yourself where necessary.

Name Type Description
m Matrix4

rotation matrix

Returns:
Type Description
Quaternion this

exactEquals(q){Boolean}

Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)

Name Type Description
q Quaternion
Returns:
Type Description
Boolean

equals(q){Boolean}

Returns whether or not the quaternions have approximately the same elements in the same position.

Name Type Description
q Quaternion
Returns:
Type Description
Boolean

Creates a quaternion from the given euler.

Name Type Description
euler Euler
Returns:
Type Description
Quaternion this
Name Type Description
q Quaternion

Alias for Quaternion#length