## 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

## Actions Documentation

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

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

#### 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

Example

``````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 + "]"
``````

This action adds the passed quaternion to this quaternion.

#### Return

Libraries.Compute.Quaternion: The sum of the quaternions

Example

``````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 + "]"
``````

### 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.

#### Return

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

Example

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

### Conjugate()

This action conjugates the quaternion.

#### Return

Libraries.Compute.Quaternion: The conjugate of the quaternion

Example

``````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 + "]"
``````

### Copy()

This action creates and returns a copy of the quaternion.

#### Return

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

Example

``````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 + "]"
``````

### 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.

#### 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

Example

``````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
``````

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

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

#### Return

number: The dot product of the two quaternions

Example

``````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
``````

### 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.

#### 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

Example

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

Quaternion quaternion

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

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

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

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

#### Return

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

Example

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

### Exponent(number alpha)

This action raises the quaternion to the passed number.

#### Parameters

• number alpha: The power to raise the quaternion to

#### Return

Libraries.Compute.Quaternion: The quaternion raised to alpha

Example

``````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 + "]"
``````

### GetAngle()

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

#### Return

number: The angle in degrees of the rotation

Example

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

Quaternion quaternion

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

number degrees = quaternion:GetAngle()

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

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

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

#### Return

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

Example

``````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
``````

### 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.

#### 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

Example

``````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
``````

### 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.

#### 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

Example

``````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
``````

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

#### Return

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

Example

``````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
``````

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

#### Return

number: The angle in radians of the rotation

Example

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

Quaternion quaternion

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

``````

### 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.

#### Return

number: The angle in degrees

Example

``````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"
``````

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.

#### Return

Example

``````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.

#### Return

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

Example

``````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
``````

### GetHashCode()

This action gets the hash code for an object.

#### Return

integer: The integer hash code of the object.

Example

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

### 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.

#### Return

number: The rotation around the x-axis in degrees

Example

``````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
``````

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.

#### Return

number: The rotation around the x-axis in radians

Example

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

Quaternion quaternion

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

quaternion:Normalize()

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

### 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.

#### Return

number: The rotation around the z-axis in degrees

Example

``````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
``````

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.

#### Return

number: The rotation around the z-axis in radians

Example

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

Quaternion quaternion

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

quaternion:Normalize()

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

### 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.

#### Parameters

Example

``````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.

#### 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

Example

``````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 + "]"
``````

### GetW()

This action gets the w value of the quaternion

#### Return

number: The w value of the quaternion

Example

``````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
``````

### GetX()

This action gets the x value of the quaternion

#### Return

number: The x value of the quaternion

Example

``````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
``````

### GetY()

This action gets the y value of the quaternion

#### Return

number: The y value of the quaternion

Example

``````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
``````

### 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.

#### Return

number: The rotation around the y-axis in degrees

Example

``````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
``````

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.

#### Return

number: The rotation around the y-axis in radians

Example

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

Quaternion quaternion

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

quaternion:Normalize()

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

### GetZ()

This action gets the z value of the quaternion

#### Return

number: The z value of the quaternion

Example

``````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
``````

### IsIdentity()

This action determines whether the quaternion is the identity quaternion.

#### Return

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