Quaternion
Overview
Quaternions are 4-dimensional vectors that are used to represent rotations.
Examples
local rotation = Quaternion.fromYawPitchRoll(0.3, 0.0, 2.0)
local otherRotation = Quaternion.fromYawPitchRoll(0.0, 1.5, 0.0)
local finalRotation = rotation:RotateBy(otherRotation)
local v = Vector3.new(0.0, 1.0, 0.0)
local rotatedV = v:Rotate(finalRotation)
Methods and Properties
fromYawPitchRoll
function Quaternion.fromYawPitchRoll(yaw : Float, pitch : Float, roll : Float) -> Quaternion
Constructs a quaternion from the provided yaw, pitch, and roll values.
| Parameter |
Type |
Description |
| yaw |
Float |
Yaw rotation in radians. |
| pitch |
Float |
Pitch rotation in radians. |
| roll |
Float |
Roll rotation in radians. |
| Returns |
Description |
| Vector |
Contains the absolute value representation of the provided vector. |
Example
local a = Quaternion.fromYawPitchRoll(0.3, 0.0, 2.0)
fromMatrix
function Quaternion.fromMatrix(source : Matrix33) -> Quaternion
Constructs a quaternion from the provided rotation matrix.
| Parameter |
Type |
Description |
| source |
Matrix33 |
Matrix containing the rotation to convert. |
| Returns |
Description |
| Quaternion |
Quaternion representing the rotation contained in the provided matrix. |
Example
local mat = Matrix33.rotationY(2.0)
local quaternion = Quaternion.fromMatrix(mat)
rotateBy
function Quaternion:rotateBy(rotation : Quaternion) -> Quaternion
Constructs a quaternion representing the rotation of the source quaternion by the provided rotation quaternion.
| Parameter |
Type |
Description |
| rotation |
Quaternion |
Represents the rotation to apply. |
| Returns |
Description |
| Quaternion |
Result of rotating the current quaternion by the rotation quaternion. |
Example
local rotation = Quaternion.fromYawPitchRoll(0.3, 0.0, 2.0)
local otherRotation = Quaternion.fromYawPitchRoll(0.0, 1.5, 0.0)
local finalRotation = rotation:RotateBy(otherRotation)