Quaternion
Implementation of a quaternion. Quaternions are used to represent rotations.
Implementation of a quaternion. Quaternions are used to represent rotations.
Constructors
Constructor
new Quaternion(
x?,y?,z?,w?):Quaternion
Parameters
x?
number
y?
number
z?
number
w?
number
Returns
Quaternion
Properties
isQuaternion
isQuaternion:
boolean
Check the type whether it belongs to Matrix3. This value should not be changed by user.
Accessors
x
Get Signature
get x():
number
Returns
number
Set Signature
set x(
value):void
Parameters
value
number
Returns
void
y
Get Signature
get y():
number
Returns
number
Set Signature
set y(
value):void
Parameters
value
number
Returns
void
z
Get Signature
get z():
number
Returns
number
Set Signature
set z(
value):void
Parameters
value
number
Returns
void
w
Get Signature
get w():
number
Returns
number
Set Signature
set w(
value):void
Parameters
value
number
Returns
void
Methods
onChangeCallback()
onChangeCallback():
void
The function will be called when _x| x, _y| y _z| z and _w| w is changed.
Returns
void
slerp()
staticslerp(qa,qb,qm,t):Quaternion
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. Also see the static version of the slerp below.
// rotate a mesh towards a target quaternion mesh.quaternion.slerp( endQuaternion, 0.01 );
Parameters
qa
Quaternion
qb
Quaternion
The other quaternion rotation.
qm
Quaternion
t
number
interpolation factor in the closed interval [0, 1].
Returns
Quaternion
slerpFlat()
staticslerpFlat(dst,dstOffset,src0,srcOffset0,src1,srcOffset1,t):void
Like the static slerp method above, but operates directly on flat arrays of numbers.
Parameters
dst
number[]
The output array.
dstOffset
number
An offset into the output array.
src0
number[]
The source array of the starting quaternion.
srcOffset0
number
An offset into the array src0.
src1
number[]
The source array of the target quaternions.
srcOffset1
number
An offset into the array src1.
t
number
Normalized interpolation factor (between 0 and 1).
Returns
void
set()
set(
x,y,z,w):Quaternion
Sets x, y, z, w properties of this quaternion.
Parameters
x
number
y
number
z
number
w
number
Returns
Quaternion
clone()
clone():
Quaternion
Creates a new Quaternion with identical x, y,z and w properties to this one.
Returns
Quaternion
copy()
copy(
quaternion):Quaternion
Copies the x, y, z and w properties of q into this quaternion.
Parameters
quaternion
Quaternion
Returns
Quaternion
setFromEuler()
setFromEuler(
euler,update?):Quaternion
Sets this quaternion from the rotation specified by Euler angle.
Parameters
euler
update?
boolean
Returns
Quaternion
setFromAxisAngle()
setFromAxisAngle(
axis,angle):Quaternion
Sets this quaternion from rotation specified by axis and Float| angle. Adapted from the method here.
Parameters
axis
angle
number
is in radians.
Returns
Quaternion
setFromRotationMatrix()
setFromRotationMatrix(
m):Quaternion
Sets this quaternion from rotation component of m. Adapted from the method here.
Parameters
m
a Matrix4 of which the upper 3x3 of matrix is a pure rotation matrix.
Returns
Quaternion
setFromUnitVectors()
setFromUnitVectors(
vFrom,vTo):Quaternion
Sets this quaternion to the rotation required to rotate direction vector vFrom to direction vector vTo. Adapted from the method here. vFrom and vTo are assumed to be normalized.
Parameters
vFrom
vTo
Returns
Quaternion
conjugate()
conjugate():
Quaternion
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
Quaternion
dot()
dot(
v):number
Calculates the dot product of quaternions v and this one.
Parameters
v
Quaternion
Returns
number
lengthSq()
lengthSq():
number
Computes the squared 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| length().
Returns
number
length()
length():
number
Computes the Euclidean length (straight-line length) of this quaternion, considered as a 4 dimensional vector.
Returns
number
normalize()
normalize():
Quaternion
Normalizes this quaternion - that is, calculated the quaternion that performs the same rotation as this one,
but has length| length equal to 1.
Returns
Quaternion
multiply()
multiply(
q):Quaternion
Multiplies this quaternion by q.
Parameters
q
Quaternion
Returns
Quaternion
premultiply()
premultiply(
q):Quaternion
Pre-multiplies this quaternion by q.
Parameters
q
Quaternion
Returns
Quaternion
multiplyQuaternions()
multiplyQuaternions(
a,b):Quaternion
Sets this quaternion to a x b. Adapted from the method outlined here.
Parameters
a
Quaternion
b
Quaternion
Returns
Quaternion
slerp()
slerp(
qb,t):Quaternion
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. Also see the static version of the method slerp.
// rotate a mesh towards a target quaternion mesh.quaternion.slerp( endQuaternion, 0.01 );
Parameters
qb
Quaternion
The other quaternion rotation.
t
number
interpolation factor in the closed interval [0, 1].
Returns
Quaternion
equals()
equals(
quaternion):boolean
Compares the x, y,z and w properties of v to the equivalent properties of this quaternion to determine if they represent the same rotation.
Parameters
quaternion
Quaternion
Returns
boolean
fromArray()
fromArray(
array,offset?):Quaternion
Sets this quaternion’s x, y, z and w properties from an array.
Parameters
array
ArrayLike<number>
array of format (x, y, z, w) used to construct the quaternion.
offset?
number
(optional) an offset into the array.
Returns
Quaternion
toArray()
toArray(
array?,offset?):number[]
Returns the numerical elements of this quaternion in an array of format [x, y, z, w].
Parameters
array?
number[]
An optional array to store the quaternion. If not specified, a new array will be created.
offset?
number
(optional) if specified, the result will be copied into this array.
Returns
number[]
onChange()
onChange(
callback):Quaternion
A method to call onChangeCallback.
Parameters
callback
Function
Returns
Quaternion