Quaternion Class Reference

The Quaternion Javascript class. Defines a 4 dimensional value. More...

Public Slots

void setWXYZ (double w, double x, double y, double z)
 Sets the w, x, y, z values to the given values. More...
 
Quaternion getConjugate ()
 Returns the conjugate of the Quaternion. More...
 
Quaternion getInverse ()
 Returns the inverse of the Quaternion. More...
 
bool isIdentity ()
 Returns true if the Quaternion is the identity Quaternion. More...
 
bool isEqual (Quaternion q2)
 Returns true if two Quaternions are equal. More...
 
bool isNotEqual (Quaternion q2)
 Returns true if two Quaternions are NOT equal. More...
 
Point3d toEuler (bool degrees=true)
 Returns a Point3d loaded with the Euler Angles corresponding to the Quaternion. More...
 
void fromEuler (double eulerX, double eulerY, double eulerZ, bool degree=true)
 Initialize the quaternion from a trio of 3 successive Euler angles(degrees or radians). More...
 
Matrix4x4 toMatrix ()
 Returns a Matrix4x4 loaded with the Rotation Matrix corresponding to the Quaternion. More...
 
double getNorm ()
 Returns the norm of the Quaternion. More...
 
double getDotProduct (Quaternion q2)
 Returns the dot product of the given Quaternion parameters. More...
 
Quaternion multiply (Quaternion q2)
 Returns the multiplication product of the given Quaternion parameters. More...
 
Quaternion getNormalized ()
 Returns the normalized Quaternion. More...
 
Vector3d rotateVector (Vector3d vect)
 Rotates a vector by the angle the Quaternion represents. More...
 

Public Member Functions

 Quaternion ()
 Create a new identity Quaternion. More...
 
 Quaternion (double w, double x, double y, double z)
 Create a new Quaternion. More...
 

Properties

double w
 The w value. More...
 
double x
 The x value. More...
 
double y
 The y value. More...
 
double z
 The z value. More...
 

Detailed Description

The Quaternion Javascript class. Defines a 4 dimensional value.

The Quaternion class defines a 4 dimensional value container, and is used to represent a rotation of a 3-D object.

Constructor & Destructor Documentation

◆ Quaternion() [1/2]

Quaternion::Quaternion ( )

Create a new identity Quaternion.

The identity Quaternion is [1, 0, 0, 0].

◆ Quaternion() [2/2]

Quaternion::Quaternion ( double  w,
double  x,
double  y,
double  z 
)

Create a new Quaternion.

Parameters
w: W value.
x: X value.
y: Y value.
z: Z value.

Member Function Documentation

◆ fromEuler

void Quaternion::fromEuler ( double  eulerX,
double  eulerY,
double  eulerZ,
bool  degree = true 
)
slot

Initialize the quaternion from a trio of 3 successive Euler angles(degrees or radians).

var newRotation = new Quaternion;
newRotation.setEuler(90, 45, 45, true); // set the initial values of a quaternion from angles in degrees.
Parameters
eulerX: The angle around the x axis
eulerY: The angle around the y axis
eulerZ: The angle around the z axis
degree: True if the given angles are in degrees, false if they are in radians.

◆ getConjugate

Quaternion Quaternion::getConjugate ( )
slot

Returns the conjugate of the Quaternion.

Changes the Quaternion to its inverse. When the norm of a Quaternion is 1, this is the same as invert().

Returns
The conjugate of the Quaternion.

◆ getDotProduct

double Quaternion::getDotProduct ( Quaternion  q2)
slot

Returns the dot product of the given Quaternion parameters.

The dot product of two Quaternions is the angle between the two rotations.

Parameters
q2: The second Quaternion to use in the calculation.
Returns
The dot product of the two Quaternions.

◆ getInverse

Quaternion Quaternion::getInverse ( )
slot

Returns the inverse of the Quaternion.

Changes the Quaternion to its inverse. When the norm of a Quaternion is 1, this is the same as conjugate(), but less efficient.

Returns
The inverse of the Quaternion.

◆ getNorm

double Quaternion::getNorm ( )
slot

Returns the norm of the Quaternion.

The norm is the 4 dimensional euclidean length of the Quaternion.

Returns
The norm of the Quaternion.

◆ getNormalized

Quaternion Quaternion::getNormalized ( )
slot

Returns the normalized Quaternion.

Normalizing a Quaternion eliminates any errors in its calculation caused by floating-point precision.

A normalized Quaternion is one with a euclidean length (norm) of 1 (Unit length).

Returns
The normalized Quaternion.

◆ isEqual

bool Quaternion::isEqual ( Quaternion  q2)
slot

Returns true if two Quaternions are equal.

Parameters
q2: The Quaternion to compare to.
Returns
true if the two Quaternion are equal.

◆ isIdentity

bool Quaternion::isIdentity ( )
slot

Returns true if the Quaternion is the identity Quaternion.

The identity Quaternion is [1, 0, 0, 0].

Returns
true if the Quaternion is the identity Quaternion.

◆ isNotEqual

bool Quaternion::isNotEqual ( Quaternion  q2)
slot

Returns true if two Quaternions are NOT equal.

Parameters
q2: The Quaternion to compare to.
Returns
true if the two Quaternion are NOT equal.

◆ multiply

Quaternion Quaternion::multiply ( Quaternion  q2)
slot

Returns the multiplication product of the given Quaternion parameters.

The multiplication of two Quaternions is the combination of the 2 angles of the quaternions.

Parameters
q2: The second Quaternion to use in the calculation.
Returns
The combined rotation of the two Quaternions.

◆ rotateVector

Vector3d Quaternion::rotateVector ( Vector3d  vect)
slot

Rotates a vector by the angle the Quaternion represents.

Parameters
vect: The Vector3d to be rotated.
Returns
The rotated Vector3d.
Note
This returns a new Vector3d, and does not modify the Vector3d in the parameter.

◆ setWXYZ

void Quaternion::setWXYZ ( double  w,
double  x,
double  y,
double  z 
)
slot

Sets the w, x, y, z values to the given values.

Parameters
w: W value.
x: X value.
y: Y value.
z: Z value.

◆ toEuler

Point3d Quaternion::toEuler ( bool  degrees = true)
slot

Returns a Point3d loaded with the Euler Angles corresponding to the Quaternion.

Parameters
degrees: Whether or not the Euler Angles are in degrees or radians. (true for degrees)
Returns
A Point3d loaded with the Euler Angles corresponding to the Quaternion.

◆ toMatrix

Matrix4x4 Quaternion::toMatrix ( )
slot

Returns a Matrix4x4 loaded with the Rotation Matrix corresponding to the Quaternion.

The Rotation Matrix is a 3x3 matrix used for rotating vectors.

Returns
A Matrix4x4 loaded with the Rotation Matrix corresponding to the Quaternion.

Property Documentation

◆ w

double Quaternion::w
readwrite

The w value.

◆ x

double Quaternion::x
readwrite

The x value.

◆ y

double Quaternion::y
readwrite

The y value.

◆ z

double Quaternion::z
readwrite

The z value.