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)

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

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

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

Add(Libraries.Compute.Quaternion quaternion)

This action adds the passed quaternion to this quaternion.

Parameters

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)

leftHandSide:Add(rightHandSide)

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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

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

GetAngleAroundRadians(Libraries.Compute.Vector3 axis)

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

Parameters

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)

number rotation = quaternion:GetAngleAroundRadians(axis)

output "The rotation around is " + rotation

GetAngleRadians()

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)

number radians = quaternion:GetAngleRadians()

output "The angle in radians is " + radians

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.

Parameters

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"

GetAxisAngleRadians(Libraries.Compute.Vector3 axis)

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.

Parameters

Return

number: The angle in radians

Example

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

Quaternion quaternion
Vector3 axis

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

number radians = quaternion:GetAxisAngleRadians(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 " + radians + " radians"

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

GetPitchRadians()

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()

number pitch = quaternion:GetPitchRadians()

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

GetRollRadians()

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()

number roll = quaternion:GetRollRadians()

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

GetYawRadians()

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()

number yaw = quaternion:GetYawRadians()

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 otherwise

Example

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

IsIdentity(number tolerance)

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

Parameters

  • number tolerance: The tolerance value

Return

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

Example

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

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.

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

Example

use Libraries.Compute.Quaternion

Quaternion quaternion

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

output "The length of the quaternion is " + length

Length()

This action returns the length of the quaternion.

Return

number: The length of the quaternion

Example

use Libraries.Compute.Quaternion

Quaternion quaternion

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

number length = quaternion:Length()

output "The length of the quaternion is " + length

LengthSquared()

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

Return

number: The square of the length of the quaternion

Example

use Libraries.Compute.Quaternion

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

number lengthSquared = quaternion:LengthSquared()

output "The length squared is " + lengthSquared

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.

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

Example

use Libraries.Compute.Quaternion

Quaternion quaternion

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

output "The length squared is " + lengthSquared

MakeInverse()

only accepts normalized v0 and v1

Multiply(Libraries.Compute.Vector3 inputVector)

changes the current quaternion

Parameters

Multiply(number scalar)

This action multiplies the quaternion by the passed scalar value

Parameters

  • number scalar: The scalar to multiply the quaternion by

Return

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

Example

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

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

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

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

Example

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

Multiply(Libraries.Compute.Quaternion other)

This action multiplies the quaternion by the passed quaternion.

Parameters

Return

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

Example

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

Normalize()

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

Return

Libraries.Compute.Quaternion: The normalized quaternion

Example

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

QuaternionRotate(Libraries.Compute.Vector3 v)

use an arbituary vector

Parameters

Return

Libraries.Compute.Vector3:

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

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

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

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 quaternion is: [" + x + ", " + y + ", " + z + ", " + w + "]"

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

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

Parameters

Return

Libraries.Compute.Quaternion: The quaternion after setting

Example

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

Set(Libraries.Compute.Quaternion quaternion)

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

Parameters

Return

Libraries.Compute.Quaternion: The quaternion after setting

Example

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

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

only accepts normalized v0 and v1

Parameters

SetEulerAngles(number yaw, number pitch, number roll)

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

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

Example

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

SetEulerAnglesRadians(number yaw, number pitch, number roll)

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

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

Example

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

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.

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

Example

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

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.

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

Example

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

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

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

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

Example

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

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

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

Parameters

Return

Libraries.Compute.Quaternion: The quaternion after setting

Example

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

SetFromAxisRadians(number x, number y, number z, number radians)

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

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 radians

Return

Libraries.Compute.Quaternion: The quaternion after setting

Example

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

SetFromAxisRadians(Libraries.Compute.Vector3 axis, number radians)

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

Parameters

Return

Libraries.Compute.Quaternion: The quaternion after setting

Example

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

Math math

Quaternion quaternion

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

quaternion:SetFromAxisRadians(axis, 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 + "]"

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

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

Parameters

Return

Libraries.Compute.Quaternion: The quaternion after setting

Example

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

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

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

Example

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

SetFromMatrix(Libraries.Compute.Matrix3 matrix)

This action sets the quaternion using the passed matrix.

Parameters

Return

Libraries.Compute.Quaternion: The quaternion after setting

Example

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

SetFromMatrix(Libraries.Compute.Matrix4 matrix)

This action sets the quaternion using the passed matrix.

Parameters

Return

Libraries.Compute.Quaternion: The quaternion after setting

Example

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

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

This action sets the quaternion using the passed matrix.

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

Example

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

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

This action sets the quaternion using the passed matrix.

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

Example

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

SetToIdentity()

This action sets the quaternion to the identity quaternion.

Return

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

Example

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

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.

Parameters

Return

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

Example

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)

quaternions:Add(quaternion2)
quaternions:Add(quaternion3)
quaternions:Add(quaternion4)

weights:Add(0.5)
weights:Add(0.5)
weights:Add(0.5)

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

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.

Parameters

Return

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

Example

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

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.

Parameters

Return

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

Example

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)

quaternions:Add(quaternion2)
quaternions:Add(quaternion3)
quaternions:Add(quaternion4)

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

ToMatrix()

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

Return

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

Example

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

Transform(Libraries.Compute.Vector3 vector)

This action transforms the passed vector using the quaternion.

Parameters

Return

Libraries.Compute.Vector3: The transformed vector

Example

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