Represents a rotation in the quaternion formulation (x, y, z, w).
Note that it is not strictly necessary to understand quaternions to use these obejcts; you can just treat them as opaque representations of rotations.
NOTE: Quaternion objects are temporary. You can only use them in the frame in which they were generated. If you need to save a Quaternion across multiple frames, use a QuaternionBox instead. For more information, see Object Lifetimes and Userdata Binding.
Constructors and accessors
Related sample code
Other related reference items
Related help topics
angle ( quat ) : numberReturns the rotation angle represented by this quaternion.
|
quat : | The quaternion whose rotation angle will be returned. |
number |
The rotation angle of the quaternion's up vector around the facing direction, expressed in radians. |
axis_angle ( axis, angle ) : stingray.QuaternionCreates a new quaternion that represents a rotation with the specified angle around the specified axis.
|
axis : | The main axis for the quaternion. | |
angle : | number | The angle around the main axis, expressed in radians. |
The newly created quaternion. |
Equivalent to stingray.Quaternion().
Related sample code
conjugate ( quat ) : stingray.QuaternionReturns the conjugate of the specified quaternion: a quaternion where the X, Y and Z values are negated, but the W component remains unchanged.
|
quat : | The quaternion whose conjugate will be returned. |
The conjugate of quat. |
decompose ( quat ) : stingray.Vector3, numberDecomposes the specified quaternion into a facing direction and a rotation angle.
|
quat : | The quaternion to decompose. |
The X, Y and Z values that define the facing direction of the quaternion. | |
number |
The rotation of the quaternion's up vector around the facing direction, expressed in radians. |
dot ( quat_a, quat_b ) : numberReturns the dot product of the two specified quaternions.
|
quat_a : | The first quaternion. | |
quat_b : | The second quaternion. |
number |
The dot product. |
equal ( quat_a, quat_b ) : booleanIndicates whether or not the two quaternions are equivalent.
|
quat_a : | The first quaternion. | |
quat_b : | The second quaternion. |
boolean |
true if all members of the two quaternions are equal, or false otherwise. |
forward ( quat ) : stingray.Vector3Returns the forward axis of the rotation represented in the specified quaternion.
|
quat : | The quaternion whose axis will be retrieved. |
The forward axis of the quaternion rotation. |
Related sample code
from_elements ( x, y, z, w ) : stingray.QuaternionCreates a new Quaternion from the given elements.
|
x : | number | The X element. |
y : | number | The Y element. |
z : | number | The Z element. |
w : | number | The W element. |
The newly created quaternion. |
Related sample code
from_euler_angles_xyz ( x, y, z ) : stingray.QuaternionCreates a new Quaternion from Euler angles.
|
x : | number | The euler X axis rotation, expressed in degrees. |
y : | number | The euler Y axis rotation, expressed in degrees. |
z : | number | The euler Z axis rotation, expressed in degrees. |
The newly created quaternion. |
from_matrix4x4 ( matrix ) : stingray.QuaternionCreates a new quaternion from the rotation expressed in the specified matrix.
|
matrix : | A matrix that contains the rotation you want to extract. |
The newly created quaternion. |
Related sample code
identity ( ) : stingray.QuaternionReturns the identity quaternion, which represents no change in rotation.
|
This function does not accept any parameters. |
The identity quaternion. |
Related sample code
inverse ( quat ) : stingray.QuaternionInverts the specified quaternion, and returns the result.
|
quat : | The quaternion to be inverted. |
The inverted rotation. |
Related sample code
is_valid ( quat ) : booleanIndicates whether or not the quaternion is composed entirely of valid values.
|
quat : | The quaternion to test. |
boolean |
Returns true if all components of the quaternion are valid numbers, or false if any component is #NaN or #INF. |
lerp ( quat_a, quat_b, t ) : stingray.QuaternionProduces a new rotation by interpolating, or "lerping", between the two specified quaternions.
|
quat_a : | The first quaternion. | |
quat_b : | The second quaternion. | |
t : | number | The ratio, or interpolation point, between the two quaternions. May be any value between 0 and 1 inclusive. Values closer to 0 produce rotations closer to quat_a; values closer to 1 produce rotations closer to quat_b. |
The resulting Quaternion. |
The lerp performed by this function is a normalized lerp, or nlerp, which usually gives the best result.
Related sample code
look ( dir, up ) : stingray.QuaternionCreates a new quaternion with the rotation needed in order to be facing in the specified direction, with the specified up vector.
|
dir : | The forward direction for the quaternion. | |
up : | Optional; specifies the up vector for the new quaternion. If omitted, the positive direction of the Z axis is used: (0,0,1). The ? notation indicates that this type is optional: there may be zero or one instances of it. |
The newly created quaternion. |
matrix4x4 ( quat ) : stingray.Matrix4x4Converts the rotation expressed by the specified quaternion into a Matrix4x4.
|
quat : | The quaternion to convert. |
A Matrix4x4 that expresses the same rotation as the quaternion. |
multiply ( quat_a, quat_b ) : stingray.QuaternionMultiplies the two specified quaternions together, and returns the result.
|
quat_a : | The first quaternion. | |
quat_b : | The second quaternion. |
The product of the multiplication. |
This creates the rotation you would get by first rotating the object by quat_b, then rotating it by quat_a.
Related sample code
norm ( quat ) : numberReturns the norm, or length, of the specified quaternion.
|
quat : | The quaternion whose length will be returned. |
number |
The length of the quaternion. |
normalize ( quat ) : stingray.QuaternionNormalizes the specified quaternion, and returns the result.
|
quat : | The quaternion to be normalized. |
The normalized rotation. |
right ( quat ) : stingray.Vector3Returns the right axis of the rotation represented in the specified quaternion.
|
quat : | The quaternion whose axis will be retrieved. |
The right axis of the quaternion rotation. |
rotate ( quat, vector ) : stingray.Vector3Rotates the specified vector by the specified quaternion, and returns the result.
|
quat : | The quaternion that will be used to rotate the vector. | |
vector : | The vector to be rotated. |
The vector after rotation. |
set_xyzw ( quat, x, y, z, w ) : stingray.QuaternionSets all of the individual component values of the specified quaternion from individual floating-point values.
|
quat : | The quaternion to set up. | |
x : | number | The new X component value for the quaternion's main axis. |
y : | number | The new Y component value for the quaternion's main axis. |
z : | number | The new Z component value for the quaternion's main axis. |
w : | number | The new W component value, defining the rotation of the up vector around the quaternion's main axis. |
The resulting quaternion. |
to_elements ( quat ) : number, number, number, numberDecomposes the specified quaternion into its four component values.
|
quat : | The quaternion to decompose into its elements. |
number |
The X component value of the quaternion's axis. |
number |
The Y component value of the quaternion's axis. |
number |
The Z component value of the quaternion's axis. |
number |
The W component value: the rotation of the local up vector around the quaternion's axis. |
to_euler_angles_xyz ( quat ) : number, number, numberReturns the quaternion euler angles.
|
quat : | The quaternion to convert. |
number |
The euler X axis rotation, expressed in degrees. |
number |
The euler Y axis rotation, expressed in degrees. |
number |
The euler Z axis rotation, expressed in degrees. |
Related sample code
to_string ( quat ) : stringReturns a string representation of the specified quaternion.
|
quat : | The quaternion to return as a string. |
string |
The string representation. |
Use this function only for debugging purposes.
up ( quat ) : stingray.Vector3Returns the up axis of the rotation represented in the specified quaternion.
|
quat : | The quaternion whose axis will be retrieved. |
The up axis of the quaternion rotation. |