Quaternion Class
A Quaternion describes a rotation in 3D space. The Quaternion is mathematically defined as Q = xi + yj + z*k + w, where (i,j,k) are imaginary basis vectors. (x,y,z) can be seen as a vector related to the axis of rotation, while the real multiplier, w, is related to the amount of rotation.
Constructor
Quaternion
-
x
-
y
-
z
-
w
Parameters:
-
x
NumberMultiplier of the imaginary basis vector i.
-
y
NumberMultiplier of the imaginary basis vector j.
-
z
NumberMultiplier of the imaginary basis vector k.
-
w
NumberMultiplier of the real part.
Item Index
Methods
Methods
copy
-
source
Copies value of source to this quaternion.
Parameters:
-
source
Quaternion
Returns:
this
inverse
-
target
Get the inverse quaternion rotation.
Parameters:
-
target
Quaternion
Returns:
mult
-
q
-
target
Quaternion multiplication
Parameters:
-
q
Quaternion -
target
QuaternionOptional.
Returns:
normalize
()
Normalize the quaternion. Note that this changes the values of the quaternion.
normalizeFast
()
Approximation of quaternion normalization. Works best when quat is already almost-normalized.
set
-
x
-
y
-
z
-
w
Set the value of the quaternion.
Parameters:
-
x
Number -
y
Number -
z
Number -
w
Number
setFromAxisAngle
-
axis
-
angle
Set the quaternion components given an axis and an angle.
Parameters:
-
axis
Vec3 -
angle
Numberin radians
setFromEuler
-
x
-
y
-
z
-
order
Parameters:
-
x
Number -
y
Number -
z
Number -
order
StringThe order to apply angles: 'XYZ' or 'YXZ' or any other combination
setFromVectors
-
u
-
v
Set the quaternion value given two vectors. The resulting rotation will be the needed rotation to rotate u to v.
toArray
()
Convert to an Array
Returns:
Array
toAxisAngle
-
targetAxis
Converts the quaternion to axis/angle representation.
Parameters:
-
targetAxis
Vec3Optional. A vector object to reuse for storing the axis.
Returns:
Array An array, first elemnt is the axis and the second is the angle in radians.
toEuler
-
target
-
string
Convert the quaternion to euler angle representation. Order: YZX, as this page describes: http://www.euclideanspace.com/maths/standards/index.htm
Parameters:
-
target
Vec3 -
string
Objectorder Three-character string e.g. "YZX", which also is default.
toString
()
Convert to a readable format
Returns:
string
Properties
w
Number
The multiplier of the real quaternion basis vector.