## Libraries.Compute.Quaternion Documentation

Quaternion is a class representing a quaternion, which are useful for 3D computer graphics.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number length = quaternion:Length()

output "The length of the quaternion is " + length``````

Inherits from: Libraries.Language.Object

## Summary

### Actions Summary Table

ActionsDescription
Add(number x, number y, number z, number w)This action adds the passed values representing a quaternion to this quaternion.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns an integer.
Conjugate()This action conjugates the quaternion.
Copy()This action creates and returns a copy of the quaternion.
DotProduct(number x, number y, number z, number w)This action finds the dot product between this quaternion and the quaternion with the passed x, y, z, and w values.
DotProduct(Libraries.Compute.Quaternion other)This action finds the dot product between this quaternion and the passed quaternion.
DotProduct(number x1, number y1, number z1, number w1, number x2, number y2, number z2, number w2)This action finds the dot product between the two quaternions with the passed x, y, z, and w values.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
Exponent(number alpha)This action raises the quaternion to the passed number.
GetAngle()This action gets the angle in degrees of the rotation of the quaternion.
GetAngleAround(Libraries.Compute.Vector3 axis)This action gets the angle in degrees of the rotation around the specified axis.
GetAngleAround(number axisX, number axisY, number axisZ)This action gets the angle in degrees of the rotation around the specified axis.
GetAngleAroundRadians(number axisX, number axisY, number axisZ)This action gets the angle in radians of the rotation around the specified axis.
GetAngleAroundRadians(Libraries.Compute.Vector3 axis)This action gets the angle in radians of the rotation around the specified axis.
GetAngleRadians()This action gets the angle in radians of the rotation of the quaternion.
GetAxisAngle(Libraries.Compute.Vector3 axis)This action gets the axis angle representation of the rotation in degrees of the quaternion.
GetAxisAngleRadians(Libraries.Compute.Vector3 axis)This action gets the axis angle representation of the rotation in radians of the quaternion.
GetGimbalPole()This action gets the pole of the gimbal lock if there is one.
GetHashCode()This action gets the hash code for an object.
GetPitch()This action gets the pitch euler angle in degrees, which is the rotation around the x-axis.
GetPitchRadians()This action gets the pitch euler angle in radians, which is the rotation around the x-axis.
GetRoll()This action gets the roll euler angle in degrees, which is the rotation around the z-axis.
GetRollRadians()This action gets the roll euler angle in radians, which is the rotation around the z-axis.
GetSwingTwist(Libraries.Compute.Vector3 axis, Libraries.Compute.Quaternion swing, Libraries.Compute.Quaternion twist)This action gets the swing rotation and the twist rotation for the specified axis.
GetSwingTwist(number axisX, number axisY, number axisZ, Libraries.Compute.Quaternion swing, Libraries.Compute.Quaternion twist)This action gets the swing rotation and the twist rotation for the specified axis.
GetW()This action gets the w value of the quaternion
GetX()This action gets the x value of the quaternion
GetY()This action gets the y value of the quaternion
GetYaw()This action gets the yaw euler angle in degrees, which is the rotation around the y-axis.
GetYawRadians()This action gets the yaw euler angle in radians, which is the rotation around the y-axis.
GetZ()This action gets the z value of the quaternion
IsIdentity()This action determines whether the quaternion is the identity quaternion.
IsIdentity(number tolerance)This action determines whether the quaternion is the identity quaternion to within the passed tolerance.
Length(number x, number y, number z, number w)This action returns the length of the quaternion with the passed x, y, z, and w values.
Length()This action returns the length of the quaternion.
LengthSquared()This action returns the square of the length of the quaternion.
LengthSquared(number x, number y, number z, number w)This action returns the square of the length of the quaternion with the passed x, y, z, and w values.
MakeInverse()only accepts normalized v0 and
Multiply(Libraries.Compute.Vector3 inputVector)changes the current quaterni
Multiply(number scalar)This action multiplies the quaternion by the passed scalar value
Multiply(number x, number y, number z, number w)This action multiplies the quaternion by the passed values representing a quaternion.
Multiply(Libraries.Compute.Quaternion other)This action multiplies the quaternion by the passed quaternion.
Normalize()This action normalizes the quaternion so that its length is between 0 and 1.
QuaternionRotate(Libraries.Compute.Vector3 v)use an arbituary vect
Set(number x, number y, number z, number w)This action sets the quaternion's values to the passed values.
Set(Libraries.Compute.Vector3 axis, number angle)This action sets the quaternion from the given axis and the angle around the axis.
Set(Libraries.Compute.Quaternion quaternion)This action sets the quaternion using the x, y, z, and w values from the passed quaternion.
SetAsShortestArcQuaternion(Libraries.Compute.Vector3 v0, Libraries.Compute.Vector3 v1)only accepts normalized v0 and
SetEulerAngles(number yaw, number pitch, number roll)This action sets the quaternion to the given euler angles in degrees
SetEulerAnglesRadians(number yaw, number pitch, number roll)This action sets the quaternion to the given euler angles in radians
SetFromAxes(boolean normalizeAxes, number xAxisX, number xAxisY, number xAxisZ, number yAxisX, number yAxisY, number yAxisZ, number zAxisX, number zAxisY, number zAxisZ)This action sets the quaternion from the given x, y, and z axes which all have to be orthogonal.
SetFromAxes(number xAxisX, number xAxisY, number xAxisZ, number yAxisX, number yAxisY, number yAxisZ, number zAxisX, number zAxisY, number zAxisZ)This action sets the quaternion from the given x, y, and z axes which all have to be orthogonal.
SetFromAxis(number x, number y, number z, number degrees)This action sets the quaternion from the given axis and angle around that axis.
SetFromAxis(Libraries.Compute.Vector3 axis, number degrees)This action sets the quaternion from the given axis and angle around that axis.
SetFromAxisRadians(number x, number y, number z, number radians)This action sets the quaternion from the given axis and angle around that axis.
SetFromAxisRadians(Libraries.Compute.Vector3 axis, number radians)This action sets the quaternion from the given axis and angle around that axis.
SetFromCross(Libraries.Compute.Vector3 vector1, Libraries.Compute.Vector3 vector2)This action sets the quaternion to be the rotation between the two passed vectors
SetFromCross(number x1, number y1, number z1, number x2, number y2, number z2)This action sets the quaternion to be the rotation between the two passed vectors
SetFromMatrix(Libraries.Compute.Matrix3 matrix)This action sets the quaternion using the passed matrix.
SetFromMatrix(Libraries.Compute.Matrix4 matrix)This action sets the quaternion using the passed matrix.
SetFromMatrix(boolean normalizeAxes, Libraries.Compute.Matrix3 matrix)This action sets the quaternion using the passed matrix.
SetFromMatrix(boolean normalizeAxes, Libraries.Compute.Matrix4 matrix)This action sets the quaternion using the passed matrix.
SetToIdentity()This action sets the quaternion to the identity quaternion.
SphericalLinearInterpolation(Libraries.Containers.Array<Libraries.Compute.Quaternion> quaternions, Libraries.Containers.Array<number> weights)This action performs a spherical linear interpolation on multiple quaternions and stores the result in the calling quaternion.
SphericalLinearInterpolation(Libraries.Compute.Quaternion endQuaternion, number alpha)This action performs a spherical linear interpolation between this quaternion and the passed quaternion by the passed alpha value.
SphericalLinearInterpolation(Libraries.Containers.Array<Libraries.Compute.Quaternion> quaternions)This action performs a spherical linear interpolation on multiple quaternions and stores the result in the calling quaternion.
ToMatrix()This action builds a 4x4 matrix (a Matrix4 object) with the rotation matrix represented by this quaternion.
Transform(Libraries.Compute.Vector3 vector)This action transforms the passed vector using the quaternion.

## Actions Documentation

### Add(number x, number y, number z, number w)

This action adds the passed values representing a quaternion to this quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The sum is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number x: The x value of the quaternion to add
• number y: The y value of the quaternion to add
• number z: The z value of the quaternion to add
• number w: The w value of the quaternion to add

#### Return

Libraries.Compute.Quaternion: The sum of the quaternions

This action adds the passed quaternion to this quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion leftHandSide
Quaternion rightHandSide

leftHandSide:Set(1, 2, 3, 4)
rightHandSide:Set(5, 6, 7, 8)

number x = leftHandSide:GetX()
number y = leftHandSide:GetY()
number z = leftHandSide:GetZ()
number w = leftHandSide:GetW()

output "The sum is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The sum of the quaternions

### Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Example Code

``````Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)``````

#### Return

integer: The Compare result, Smaller, Equal, or Larger.

### Conjugate()

This action conjugates the quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Conjugate()

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is: [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The conjugate of the quaternion

### Copy()

This action creates and returns a copy of the quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion
quaternion:Set(1, 2, 3, 4)

Quaternion copy

copy = quaternion:Copy()

number x = copy:GetX()
number y = copy:GetY()
number z = copy:GetZ()
number w = copy:GetW()

output "The quaternion is: [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: a new quaternion that is a copy of this quaternion

### DotProduct(number x, number y, number z, number w)

This action finds the dot product between this quaternion and the quaternion with the passed x, y, z, and w values.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number dotProduct = quaternion:DotProduct(5, 6, 7, 8)

output "The dot product is " + dotProduct``````

#### Parameters

• number x: The x value of the other quaternion
• number y: The y value of the other quaternion
• number z: The z value of the other quaternion
• number w: The w value of the other quaternion

#### Return

number: The dot product of the two quaternions

### DotProduct(Libraries.Compute.Quaternion other)

This action finds the dot product between this quaternion and the passed quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion
Quaternion other

quaternion:Set(1, 2, 3, 4)
other:Set(5, 6, 7, 8)

number dotProduct = quaternion:DotProduct(other)

output "The dot product is " + dotProduct``````

#### Return

number: The dot product of the two quaternions

### DotProduct(number x1, number y1, number z1, number w1, number x2, number y2, number z2, number w2)

This action finds the dot product between the two quaternions with the passed x, y, z, and w values.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

number dotProduct = quaternion:DotProduct(1, 2, 3, 4, 5, 6, 7, 8)

output "The dot product is " + dotProduct``````

#### Parameters

• number x1: The x value of the first quaternion
• number y1: The y value of the first quaternion
• number z1: The z value of the first quaternion
• number w1: The w value of the first quaternion
• number x2: The x value of the second quaternion
• number y2: The y value of the second quaternion
• number z2: The z value of the second quaternion
• number w2: The w value of the second quaternion

#### Return

number: The dot product of the two quaternions

### Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

``````use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)``````

#### Return

boolean: True if the hash codes are equal and false if they are not equal.

### Exponent(number alpha)

This action raises the quaternion to the passed number.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Exponent(3)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number alpha: The power to raise the quaternion to

#### Return

Libraries.Compute.Quaternion: The quaternion raised to alpha

### GetAngle()

This action gets the angle in degrees of the rotation of the quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number degrees = quaternion:GetAngle()

output "The angle in degrees is " + degrees``````

#### Return

number: The angle in degrees of the rotation

### GetAngleAround(Libraries.Compute.Vector3 axis)

This action gets the angle in degrees of the rotation around the specified axis. The axis must be normalized.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Vector3

Quaternion quaternion

Vector3 axis
axis:Set(5, 4, 3)
axis:Normalize()

quaternion:Set(1, 2, 3, 4)

number rotation = quaternion:GetAngleAround(axis)

output "The rotation around is " + rotation``````

#### Return

number: The angle in degrees of the rotation around the passed axis

### GetAngleAround(number axisX, number axisY, number axisZ)

This action gets the angle in degrees of the rotation around the specified axis. The axis must be normalized.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number rotation = quaternion:GetAngleAround(1, 0, 0)

output "The rotation around is " + rotation``````

#### Parameters

• number axisX: The x component of the normalized axis to get the angle for
• number axisY: The y component of the normalized axis to get the angle for
• number axisZ: The z component of the normalized axis to get the angle for

#### Return

number: The angle in degrees of the rotation around the passed axis

### GetAngleAroundRadians(number axisX, number axisY, number axisZ)

This action gets the angle in radians of the rotation around the specified axis. The axis must be normalized.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number rotation = quaternion:GetAngleAroundRadians(1, 0, 0)

output "The rotation around is " + rotation``````

#### Parameters

• number axisX: The x component of the normalized axis to get the angle for
• number axisY: The y component of the normalized axis to get the angle for
• number axisZ: The z component of the normalized axis to get the angle for

#### Return

number: The angle in radians of the rotation around the passed axis

This action gets the angle in radians of the rotation around the specified axis. The axis must be normalized.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Vector3

Quaternion quaternion

Vector3 axis
axis:Set(5, 4, 3)
axis:Normalize()

quaternion:Set(1, 2, 3, 4)

output "The rotation around is " + rotation``````

#### Return

number: The angle in radians of the rotation around the passed axis

This action gets the angle in radians of the rotation of the quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

#### Return

number: The angle in radians of the rotation

### GetAxisAngle(Libraries.Compute.Vector3 axis)

This action gets the axis angle representation of the rotation in degrees of the quaternion. The passed axis will be given the axis of the rotation and the action will return the rotation angle in degrees. The passed vector is altered by this action. The existing values of the vector are ignored.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Vector3

Quaternion quaternion
Vector3 axis

quaternion:Set(1, 2, 3, 4)

number degrees = quaternion:GetAxisAngle(axis)

number x = axis:GetX()
number y = axis:GetY()
number z = axis:GetZ()

output "The rotation axis is [" + x + ", " + y + ", " + z + "]"
output "The rotation angle is " + degrees + " degrees"``````

#### Return

number: The angle in degrees

This action gets the axis angle representation of the rotation in radians of the quaternion. The passed axis will be given the axis of the rotation and the action will return the rotation angle in radians. The passed vector is altered by this action. The existing values of the vector are ignored.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Vector3

Quaternion quaternion
Vector3 axis

quaternion:Set(1, 2, 3, 4)

number x = axis:GetX()
number y = axis:GetY()
number z = axis:GetZ()

output "The rotation axis is [" + x + ", " + y + ", " + z + "]"

### GetGimbalPole()

This action gets the pole of the gimbal lock if there is one.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number pole = quaternion:GetGimbalPole()

if pole = 1
output "The gimbal pole is the north pole."
elseif pole = -1
output "The gimbal pole is the south pole."
else
output "There is no gimbal pole."
end``````

#### Return

integer: : 1 for the north pole, -1 for the south pole, 0 if there is no gimbal lock

### GetHashCode()

This action gets the hash code for an object.

Example Code

``````Object o
integer hash = o:GetHashCode()``````

#### Return

integer: The integer hash code of the object.

### GetPitch()

This action gets the pitch euler angle in degrees, which is the rotation around the x-axis. The quaternion must be normalized before calling this action.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Normalize()

number pitch = quaternion:GetPitch()

output "The pitch in degrees is " + pitch``````

#### Return

number: The rotation around the x-axis in degrees

This action gets the pitch euler angle in radians, which is the rotation around the x-axis. The quaternion must be normalized before calling this action.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Normalize()

output "The pitch in radians is " + pitch``````

#### Return

number: The rotation around the x-axis in radians

### GetRoll()

This action gets the roll euler angle in degrees, which is the rotation around the z-axis. The quaternion must be normalized before calling this action.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Normalize()

number roll = quaternion:GetRoll()

output "The roll in degrees is " + roll``````

#### Return

number: The rotation around the z-axis in degrees

This action gets the roll euler angle in radians, which is the rotation around the z-axis. The quaternion must be normalized before calling this action.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Normalize()

output "The roll in radians is " + roll``````

#### Return

number: The rotation around the z-axis in radians

### GetSwingTwist(Libraries.Compute.Vector3 axis, Libraries.Compute.Quaternion swing, Libraries.Compute.Quaternion twist)

This action gets the swing rotation and the twist rotation for the specified axis. The twist rotation is the rotation around the specified axis. The swing rotation is the rotation of the specified axis itself, which is the rotation around an axis perpendicular to that axis. The passed axis should be normalized.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Vector3

Quaternion quaternion
Quaternion swing
Quaternion twist

Vector3 axis
axis:Set(4, 7, 3)
axis:Normalize()

quaternion:Set(1, 2, 3, 4)

quaternion:GetSwingTwist(axis, swing, twist)

number swingX = swing:GetX()
number swingY = swing:GetY()
number swingZ = swing:GetZ()
number swingW = swing:GetW()

number twistX = twist:GetX()
number twistY = twist:GetY()
number twistZ = twist:GetZ()
number twistW = twist:GetW()

output "The swing is [" + swingX + ", " + swingY + ", " + swingZ + ", " + swingW + "]"
output "The twist is [" + twistX + ", " + twistY + ", " + twistZ + ", " + twistW + "]"``````

### GetSwingTwist(number axisX, number axisY, number axisZ, Libraries.Compute.Quaternion swing, Libraries.Compute.Quaternion twist)

This action gets the swing rotation and the twist rotation for the specified axis. The twist rotation is the rotation around the specified axis. The swing rotation is the rotation of the specified axis itself, which is the rotation around an axis perpendicular to that axis. The passed axis should be normalized.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion
Quaternion swing
Quaternion twist

quaternion:Set(1, 2, 3, 4)

quaternion:GetSwingTwist(0, 0, 1, swing, twist)

number swingX = swing:GetX()
number swingY = swing:GetY()
number swingZ = swing:GetZ()
number swingW = swing:GetW()

number twistX = twist:GetX()
number twistY = twist:GetY()
number twistZ = twist:GetZ()
number twistW = twist:GetW()

output "The swing is [" + swingX + ", " + swingY + ", " + swingZ + ", " + swingW + "]"
output "The twist is [" + twistX + ", " + twistY + ", " + twistZ + ", " + twistW + "]"``````

#### Parameters

• number axisX: The x component of the axis to get the swing and twist rotations for
• number axisY: The y component of the axis to get the swing and tiwst rotations for
• number axisZ: The z component of the axis to get the swing and twist rotations for
• Libraries.Compute.Quaternion: The quaternion to store the swing rotation in
• Libraries.Compute.Quaternion: The quaternion to store the twist rotation in

### GetW()

This action gets the w value of the quaternion

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number w = quaternion:GetW()

output "The w value of the quaternion is " + w``````

#### Return

number: The w value of the quaternion

### GetX()

This action gets the x value of the quaternion

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number x = quaternion:GetX()

output "The x value of the quaternion is " + x``````

#### Return

number: The x value of the quaternion

### GetY()

This action gets the y value of the quaternion

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number y = quaternion:GetY()

output "The y value of the quaternion is " + y``````

#### Return

number: The y value of the quaternion

### GetYaw()

This action gets the yaw euler angle in degrees, which is the rotation around the y-axis. The quaternion must be normalized before calling this action.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Normalize()

number yaw = quaternion:GetYaw()

output "The yaw in degrees is " + yaw``````

#### Return

number: The rotation around the y-axis in degrees

This action gets the yaw euler angle in radians, which is the rotation around the y-axis. The quaternion must be normalized before calling this action.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Normalize()

output "The yaw in radians is " + yaw``````

#### Return

number: The rotation around the y-axis in radians

### GetZ()

This action gets the z value of the quaternion

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number z = quaternion:GetZ()

output "The z value of the quaternion is " + z``````

#### Return

number: The z value of the quaternion

### IsIdentity()

This action determines whether the quaternion is the identity quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

if quaternion:IsIdentity()
output "The quaternion is the identity quaternion"
else
output "The quaternion is not the identity quaternion"
end``````

#### Return

boolean: true if the quaternion is the identity quaternion, false otherwise

### IsIdentity(number tolerance)

This action determines whether the quaternion is the identity quaternion to within the passed tolerance.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

if quaternion:IsIdentity(0.001)
output "The quaternion is the identity quaternion"
else
output "The quaternion is not the identity quaternion"
end``````

#### Parameters

• number tolerance: The tolerance value

#### Return

boolean: true if the quaternion is the identity quaternion to within the passed tolerance, false otherwise

### Length(number x, number y, number z, number w)

This action returns the length of the quaternion with the passed x, y, z, and w values.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

number length = quaternion:Length(1, 2, 3, 4)

output "The length of the quaternion is " + length``````

#### Parameters

• number x: The x value of the quaternion
• number y: The y value of the quaternion
• number z: The z value of the quaternion
• number w: The w value of the quaternion

#### Return

number: The length of the quaternion

### Length()

This action returns the length of the quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number length = quaternion:Length()

output "The length of the quaternion is " + length``````

#### Return

number: The length of the quaternion

### LengthSquared()

This action returns the square of the length of the quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion
quaternion:Set(1, 2, 3, 4)

number lengthSquared = quaternion:LengthSquared()

output "The length squared is " + lengthSquared``````

#### Return

number: The square of the length of the quaternion

### LengthSquared(number x, number y, number z, number w)

This action returns the square of the length of the quaternion with the passed x, y, z, and w values.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

number lengthSquared = quaternion:LengthSquared(1, 2, 3, 4)

output "The length squared is " + lengthSquared``````

#### Parameters

• number x: The x value of the quaternion
• number y: The y value of the quaternion
• number z: The z value of the quaternion
• number w: The w value of the quaternion

#### Return

number: The square of the length of the quaternion

### MakeInverse()

only accepts normalized v0 and

### Multiply(Libraries.Compute.Vector3 inputVector)

changes the current quaterni

### Multiply(number scalar)

This action multiplies the quaternion by the passed scalar value

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Multiply(2)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number scalar: The scalar to multiply the quaternion by

#### Return

Libraries.Compute.Quaternion: The quaternion after being multiplied by the scalar

### Multiply(number x, number y, number z, number w)

This action multiplies the quaternion by the passed values representing a quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Multiply(5, 6, 7, 8)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The product is: [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number x: The x value of the quaternion to multiply by
• number y: The y value of the quaternion to multiply by
• number z: The z value of the quaternion to multiply by
• number w: The w value of the quaternion to multiply by

#### Return

Libraries.Compute.Quaternion: The product of the two quaternions

### Multiply(Libraries.Compute.Quaternion other)

This action multiplies the quaternion by the passed quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion multiplicand
Quaternion multiplier

multiplicand:Set(1, 2, 3, 4)
multiplier:Set(5, 6, 7, 8)

multiplicand:Multiply(multiplier)

number x = multiplicand:GetX()
number y = multiplicand:GetY()
number z = multiplicand:GetZ()
number w = multiplicand:GetW()

output "The product is: [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The product of the two quaternions

### Normalize()

This action normalizes the quaternion so that its length is between 0 and 1.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

quaternion:Normalize()

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The new quaternion is: [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The normalized quaternion

### QuaternionRotate(Libraries.Compute.Vector3 v)

use an arbituary vect

### Set(number x, number y, number z, number w)

This action sets the quaternion's values to the passed values.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:Set(1, 2, 3, 4)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is: [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number x: The value to set as the quaternion's x
• number y: The value to set as the quaternion's y
• number z: The value to set as the quaternion's z
• number w: The value to set as the quaternion's w

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### Set(Libraries.Compute.Vector3 axis, number angle)

This action sets the quaternion from the given axis and the angle around the axis.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Vector3

Quaternion quaternion

Vector3 axis
axis:Set(1, 0, 0)

quaternion:Set(axis, 45)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is: [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### Set(Libraries.Compute.Quaternion quaternion)

This action sets the quaternion using the x, y, z, and w values from the passed quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion
Quaternion setQuaternion

setQuaternion:Set(1, 2, 3, 4)

quaternion:Set(setQuaternion)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is: [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetAsShortestArcQuaternion(Libraries.Compute.Vector3 v0, Libraries.Compute.Vector3 v1)

only accepts normalized v0 and

### SetEulerAngles(number yaw, number pitch, number roll)

This action sets the quaternion to the given euler angles in degrees

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:SetEulerAngles(45, 30, 60)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is: [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number yaw: The rotation around the y-axis in degrees
• number pitch: The rotation around the x-axis in degrees
• number roll: The rotation around the z-axis in degrees

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetEulerAnglesRadians(number yaw, number pitch, number roll)

This action sets the quaternion to the given euler angles in radians

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Math

Math math

Quaternion quaternion

quaternion:SetEulerAnglesRadians(math:pi / 4, math:pi / 6, math:pi / 3)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is: [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number yaw: The rotation around the y-axis in radians
• number pitch: The rotation around the x-axis in radians
• number roll: The rotation around the z-axis in radians

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetFromAxes(boolean normalizeAxes, number xAxisX, number xAxisY, number xAxisZ, number yAxisX, number yAxisY, number yAxisZ, number zAxisX, number zAxisY, number zAxisZ)

This action sets the quaternion from the given x, y, and z axes which all have to be orthogonal.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:SetFromAxes(true, 4, 0, 5, 0, 4, 5, 0, 0, 4)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• boolean normalizeAxes: whether to normalize the axes, which is necessary if they contain scaling
• number xAxisX: The x component of the x axis
• number xAxisY: The y component of the x axis
• number xAxisZ: The z component of the x axis
• number yAxisX: The x component of the y axis
• number yAxisY: The y component of the y axis
• number yAxisZ: The z component of the y axis
• number zAxisX: The x component of the z axis
• number zAxisY: The y component of the z axis
• number zAxisZ: The z component of the z axis

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetFromAxes(number xAxisX, number xAxisY, number xAxisZ, number yAxisX, number yAxisY, number yAxisZ, number zAxisX, number zAxisY, number zAxisZ)

This action sets the quaternion from the given x, y, and z axes which all have to be orthogonal.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:SetFromAxes(0.625, 0, 0.781, 0, 0.625, 0.781, 0, 0, 1)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number xAxisX: The x component of the x axis
• number xAxisY: The y component of the x axis
• number xAxisZ: The z component of the x axis
• number yAxisX: The x component of the y axis
• number yAxisY: The y component of the y axis
• number yAxisZ: The z component of the y axis
• number zAxisX: The x component of the z axis
• number zAxisY: The y component of the z axis
• number zAxisZ: The z component of the z axis

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetFromAxis(number x, number y, number z, number degrees)

This action sets the quaternion from the given axis and angle around that axis.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:SetFromAxis(1, 0, 0, 45)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number x: The x component of the axis
• number y: The y component of the axis
• number z: The z component of the axis
• number degrees: The angle around the axis in degrees

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetFromAxis(Libraries.Compute.Vector3 axis, number degrees)

This action sets the quaternion from the given axis and angle around that axis.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Vector3

Quaternion quaternion

Vector3 axis
axis:Set(1, 0, 0)

quaternion:SetFromAxis(axis, 45)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

This action sets the quaternion from the given axis and angle around that axis.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Math

Math math

Quaternion quaternion

quaternion:SetFromAxisRadians(1, 0, 0, math:pi / 4)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number x: The x component of the axis
• number y: The y component of the axis
• number z: The z component of the axis

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

This action sets the quaternion from the given axis and angle around that axis.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Vector3
use Libraries.Compute.Math

Math math

Quaternion quaternion

Vector3 axis
axis:Set(1, 0, 0)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetFromCross(Libraries.Compute.Vector3 vector1, Libraries.Compute.Vector3 vector2)

This action sets the quaternion to be the rotation between the two passed vectors

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Vector3

Quaternion quaternion

Vector3 first
Vector3 second

first:Set(2, 3, 4)
second:Set(4, 3, 6)

quaternion:SetFromCross(first, second)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetFromCross(number x1, number y1, number z1, number x2, number y2, number z2)

This action sets the quaternion to be the rotation between the two passed vectors

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:SetFromCross(2, 3, 4, 4, 3, 6)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• number x1: The x component of the first vector
• number y1: The y component of the first vector
• number z1: The z component of the first vector
• number x2: The x component of the second vector
• number y2: The y component of the second vector
• number z2: The z component of the second vector

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetFromMatrix(Libraries.Compute.Matrix3 matrix)

This action sets the quaternion using the passed matrix.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Matrix3

Quaternion quaternion

Matrix3 matrix
matrix:Set(4, 0, 5, 0, 4, 5, 0, 0, 4)

quaternion:SetFromMatrix(matrix)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetFromMatrix(Libraries.Compute.Matrix4 matrix)

This action sets the quaternion using the passed matrix.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Matrix4

Quaternion quaternion

Matrix4 matrix
matrix:Set(4, 0, 5, 0, 0, 4, 5, 0, 0, 0, 4, 0, 0, 0, 0, 4)

quaternion:SetFromMatrix(matrix)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetFromMatrix(boolean normalizeAxes, Libraries.Compute.Matrix3 matrix)

This action sets the quaternion using the passed matrix.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Matrix3

Quaternion quaternion

Matrix3 matrix
matrix:Set(4, 0, 5, 0, 4, 5, 0, 0, 4)

quaternion:SetFromMatrix(true, matrix)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• boolean normalizeAxes: whether to remove any scaling. If true, scaling is removed from the matrix
• Libraries.Compute.Matrix3: The matrix to use to set the quaternion

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetFromMatrix(boolean normalizeAxes, Libraries.Compute.Matrix4 matrix)

This action sets the quaternion using the passed matrix.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Matrix4

Quaternion quaternion

Matrix4 matrix
matrix:Set(4, 0, 5, 0, 0, 4, 5, 0, 0, 0, 4, 0, 0, 0, 0, 4)

quaternion:SetFromMatrix(true, matrix)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Parameters

• boolean normalizeAxes: whether to remove any scaling. If true, scaling is removed from the matrix
• Libraries.Compute.Matrix4: The matrix to use to set the quaternion

#### Return

Libraries.Compute.Quaternion: The quaternion after setting

### SetToIdentity()

This action sets the quaternion to the identity quaternion.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion

quaternion:SetToIdentity()

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The identity quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The quaternion as the identity quaternion

### SphericalLinearInterpolation(Libraries.Containers.Array<Libraries.Compute.Quaternion> quaternions, Libraries.Containers.Array<number> weights)

This action performs a spherical linear interpolation on multiple quaternions and stores the result in the calling quaternion.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Containers.Array

Array<Quaternion> quaternions
Array<number> weights

Quaternion quaternion1
quaternion1:Set(1, 2, 3, 4)

Quaternion quaternion2
quaternion2:Set(5, 6, 7, 8)

Quaternion quaternion3
quaternion3:Set(9, 10, 11, 12)

Quaternion quaternion4
quaternion4:Set(13, 14, 15, 16)

quaternion1:SphericalLinearInterpolation(quaternions, weights)

number x = quaternion1:GetX()
number y = quaternion1:GetY()
number z = quaternion1:GetZ()
number w = quaternion1:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The quaternion with the result of all the spherical linear interpolations

### SphericalLinearInterpolation(Libraries.Compute.Quaternion endQuaternion, number alpha)

This action performs a spherical linear interpolation between this quaternion and the passed quaternion by the passed alpha value.

Example Code

``````use Libraries.Compute.Quaternion

Quaternion quaternion
Quaternion endQuaternion

quaternion:Set(1, 2, 3, 4)
endQuaternion:Set(5, 4, 6, 2)

quaternion:SphericalLinearInterpolation(endQuaternion, 0.5)

number x = quaternion:GetX()
number y = quaternion:GetY()
number z = quaternion:GetZ()
number w = quaternion:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The spherical linear interpolation between the two quaternions

### SphericalLinearInterpolation(Libraries.Containers.Array<Libraries.Compute.Quaternion> quaternions)

This action performs a spherical linear interpolation on multiple quaternions and stores the result in the calling quaternion.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Containers.Array

Array<Quaternion> quaternions

Quaternion quaternion1
quaternion1:Set(1, 2, 3, 4)

Quaternion quaternion2
quaternion2:Set(5, 6, 7, 8)

Quaternion quaternion3
quaternion3:Set(9, 10, 11, 12)

Quaternion quaternion4
quaternion4:Set(13, 14, 15, 16)

quaternion1:SphericalLinearInterpolation(quaternions)

number x = quaternion1:GetX()
number y = quaternion1:GetY()
number z = quaternion1:GetZ()
number w = quaternion1:GetW()

output "The quaternion is [" + x + ", " + y + ", " + z + ", " + w + "]"``````

#### Return

Libraries.Compute.Quaternion: The quaternion with the result of all the spherical linear interpolations

### ToMatrix()

This action builds a 4x4 matrix (a Matrix4 object) with the rotation matrix represented by this quaternion.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Matrix4

Quaternion quaternion
Matrix4 matrix

quaternion:Set(1, 2, 3, 4)

matrix = quaternion:ToMatrix()

number row0column0 = matrix:row0column0
number row0column1 = matrix:row0column1
number row0column2 = matrix:row0column2
number row0column3 = matrix:row0column3
number row1column0 = matrix:row1column0
number row1column1 = matrix:row1column1
number row1column2 = matrix:row1column2
number row1column3 = matrix:row1column3
number row2column0 = matrix:row2column0
number row2column1 = matrix:row2column1
number row2column2 = matrix:row2column2
number row2column3 = matrix:row2column3
number row3column0 = matrix:row3column0
number row3column1 = matrix:row3column1
number row3column2 = matrix:row3column2
number row3column3 = matrix:row3column3

output "The matrix is:"
output "|" + row0column0 + ", " + row0column1 + ", " + row0column2 + ", " + row0column3 + "|"
output "|" + row1column0 + ", " + row1column1 + ", " + row1column2 + ", " + row1column3 + "|"
output "|" + row2column0 + ", " + row2column1 + ", " + row2column2 + ", " + row2column3 + "|"
output "|" + row3column0 + ", " + row3column1 + ", " + row3column2 + ", " + row3column3 + "|"``````

#### Return

Libraries.Compute.Matrix4: The matrix built from this quaternion

### Transform(Libraries.Compute.Vector3 vector)

This action transforms the passed vector using the quaternion.

Example Code

``````use Libraries.Compute.Quaternion
use Libraries.Compute.Vector3

Quaternion quaternion
Vector3 vector

quaternion:Set(1, 2, 3, 4)
vector:Set(3, 4, 7)

quaternion:Transform(vector)

number x = vector:GetX()
number y = vector:GetY()
number z = vector:GetZ()

output "The transformed vector is [" + x + ", " + y + ", " + z + "]"``````

#### Return

Libraries.Compute.Vector3: The transformed vector