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:
-
xNumberMultiplier of the imaginary basis vector i.
-
yNumberMultiplier of the imaginary basis vector j.
-
zNumberMultiplier of the imaginary basis vector k.
-
wNumberMultiplier of the real part.
Item Index
Methods
Methods
copy
-
source
Copies value of source to this quaternion.
Parameters:
-
sourceQuaternion
Returns:
this
inverse
-
target
Get the inverse quaternion rotation.
Parameters:
-
targetQuaternion
Returns:
mult
-
q -
target
Quaternion multiplication
Parameters:
-
qQuaternion -
targetQuaternionOptional.
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:
-
xNumber -
yNumber -
zNumber -
wNumber
setFromAxisAngle
-
axis -
angle
Set the quaternion components given an axis and an angle.
Parameters:
-
axisVec3 -
angleNumberin radians
setFromEuler
-
x -
y -
z -
order
Parameters:
-
xNumber -
yNumber -
zNumber -
orderStringThe 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:
-
targetAxisVec3Optional. 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:
-
targetVec3 -
stringObjectorder 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.
