Skip to content

Math types

Vectors, rotations, transforms, colors, and time.

Vec3

Class

A simple Vector type which holds 3 Numbers, X+ is Forward, Y+ is Right, Z+ is Up

Properties

Property Type Description
x number The X Component of the Vector, Positive is Forward
y number The Y Component of the Vector, Positive is Right
z number The Z Component of the Vector, Positive is Up

Methods

Method Description
projectOnTo Projects self onto a
length Gets the magnitude of the vector
squaredLength Gets the squared magnitude of the vector
normalize Creates a unit vector of length 1
getSafeNormal Creates a unit vector of length 1. Returns zero vector by default if vector length is too small to safely normalize.
isNormalized Checks whether the vector is normalized
getMax Get the maximum value of the vector's components
getMin Get the minimum value of the vector's components
getAbsMax Get the maximum absolute value of the vector's components
getAbsMin Get the minimum absolute value of the vector's components
getAbs Get a copy of this vector with absolute value of each component
isNearlyZero Checks whether a vector is near to zero within a reasonable tolerance
isZero Checks whether all components of a vector are exactly zero
getSignVector Get a copy of the vector as sign only. Each component ise set to +1 or -1, with the sign of zero treated as +1
rotateAngleAxis Rotates self by degrees around axis. Assumes axis is normalized
rotateAngleAxisRad Rotates self by radians around axis. Assumes axis is normalized
containsNan Utility to check if there are any non-finite values (NaN or Inf) in this vector
dot Calculate the dot product of two vectors
cross Calculate the cross product of two vectors
distance Calculate the distance between two vectors
lerp Interpolates between two points start and end with 0 <= t <= 1

projectOnTo

projectOnTo(a: Vec3) -> Vec3

Projects self onto a

Parameters

Name Type
a Vec3

Returns: Vec3


length

length() -> number

Gets the magnitude of the vector

Returns: number


squaredLength

squaredLength() -> number

Gets the squared magnitude of the vector

Returns: number


normalize

normalize() -> Vec3

Creates a unit vector of length 1

Returns: Vec3


getSafeNormal

getSafeNormal() -> Vec3

Creates a unit vector of length 1. Returns zero vector by default if vector length is too small to safely normalize.

Returns: Vec3


isNormalized

isNormalized() -> boolean

Checks whether the vector is normalized

Returns: boolean


getMax

getMax() -> number

Get the maximum value of the vector's components

Returns: number


getMin

getMin() -> number

Get the minimum value of the vector's components

Returns: number


getAbsMax

getAbsMax() -> number

Get the maximum absolute value of the vector's components

Returns: number


getAbsMin

getAbsMin() -> number

Get the minimum absolute value of the vector's components

Returns: number


getAbs

getAbs() -> Vec3

Get a copy of this vector with absolute value of each component

Returns: Vec3


isNearlyZero

isNearlyZero() -> boolean

Checks whether a vector is near to zero within a reasonable tolerance

Returns: boolean


isZero

isZero() -> boolean

Checks whether all components of a vector are exactly zero

Returns: boolean


getSignVector

getSignVector() -> Vec3

Get a copy of the vector as sign only. Each component ise set to +1 or -1, with the sign of zero treated as +1

Returns: Vec3


rotateAngleAxis

rotateAngleAxis(degrees: number, axis: Vec3) -> Vec3

Rotates self by degrees around axis. Assumes axis is normalized

Parameters

Name Type
degrees number
axis Vec3

Returns: Vec3


rotateAngleAxisRad

rotateAngleAxisRad(radians: number, axis: Vec3) -> Vec3

Rotates self by radians around axis. Assumes axis is normalized

Parameters

Name Type
radians number
axis Vec3

Returns: Vec3


containsNan

containsNan() -> boolean

Utility to check if there are any non-finite values (NaN or Inf) in this vector

Returns: boolean


dot

dot(rhs: Vec3) -> number

Calculate the dot product of two vectors

Parameters

Name Type
rhs Vec3

Returns: number


cross

cross(rhs: Vec3) -> Vec3

Calculate the cross product of two vectors

Parameters

Name Type
rhs Vec3

Returns: Vec3


distance

distance(rhs: Vec3) -> number

Calculate the distance between two vectors

Parameters

Name Type
rhs Vec3

Returns: number


lerp

lerp(_end: Vec3, t: number) -> Vec3

Interpolates between two points start and end with 0 <= t <= 1

Parameters

Name Type
_end Vec3
t number

Returns: Vec3

Static properties

Property Type Description
zeroVector Vec3 Zero vector (0,0,0)
oneVector Vec3 One vector (1,1,1)
upVector Vec3 Up vector (0,0,1)
downVector Vec3 down vector (0,0,-1)
leftVector Vec3 Left vector (0,-1,0)
rightVector Vec3 Right vector (0,1,0)
forwardVector Vec3 Forward vector (1,0,0)
backwardVector Vec3 Backward vector (-1,0,0)

Static functions

Method Description
dot Calculate the dot product of two vectors
cross Calculate the cross product of two vectors
distance Calculate the distance between two vectors
lerp Interpolates between two points start and end with 0 <= t <= 1

dot

Vec3.dot(lhs: Vec3, rhs: Vec3) -> number

Calculate the dot product of two vectors

Parameters

Name Type
lhs Vec3
rhs Vec3

Returns: number


cross

Vec3.cross(lhs: Vec3, rhs: Vec3) -> Vec3

Calculate the cross product of two vectors

Parameters

Name Type
lhs Vec3
rhs Vec3

Returns: Vec3


distance

Vec3.distance(lhs: Vec3, rhs: Vec3) -> number

Calculate the distance between two vectors

Parameters

Name Type
lhs Vec3
rhs Vec3

Returns: number


lerp

Vec3.lerp(start: Vec3, _end: Vec3, t: number) -> Vec3

Interpolates between two points start and end with 0 <= t <= 1

Parameters

Name Type
start Vec3
_end Vec3
t number

Returns: Vec3

Vec2

Class

A simple Vector type which holds 3 Numbers, X+ is Forward, Y+ is Right, Z+ is Up

Properties

Property Type Description
x number The X Component of the Vector, Positive is Forward
y number The Y Component of the Vector, Positive is Right

Methods

Method Description
length Gets the magnitude of the vector
squaredLength Gets the squared magnitude of the vector
normalize Creates a unit vector of length 1
getSafeNormal Creates a unit vector of length 1. Returns zero vector by default if vector length is too small to safely normalize.
isNormalized Checks whether the vector is normalized
getMax Get the maximum value of the vector's components
getMin Get the minimum value of the vector's components
getAbsMax Get the maximum absolute value of the vector's components
getAbsMin Get the minimum absolute value of the vector's components
getAbs Get a copy of this vector with absolute value of each component
isNearlyZero Checks whether a vector is near to zero within a reasonable tolerance
isZero Checks whether all components of a vector are exactly zero
getSignVector Get a copy of the vector as sign only. Each component ise set to +1 or -1, with the sign of zero treated as +1
containsNan Utility to check if there are any non-finite values (NaN or Inf) in this vector
dot Calculate the dot product of two vectors
distance Calculate the distance between two vectors
lerp Interpolates between two points start and end with 0 <= t <= 1

length

length() -> number

Gets the magnitude of the vector

Returns: number


squaredLength

squaredLength() -> number

Gets the squared magnitude of the vector

Returns: number


normalize

normalize() -> Vec2

Creates a unit vector of length 1

Returns: Vec2


getSafeNormal

getSafeNormal() -> Vec2

Creates a unit vector of length 1. Returns zero vector by default if vector length is too small to safely normalize.

Returns: Vec2


isNormalized

isNormalized() -> boolean

Checks whether the vector is normalized

Returns: boolean


getMax

getMax() -> number

Get the maximum value of the vector's components

Returns: number


getMin

getMin() -> number

Get the minimum value of the vector's components

Returns: number


getAbsMax

getAbsMax() -> number

Get the maximum absolute value of the vector's components

Returns: number


getAbsMin

getAbsMin() -> number

Get the minimum absolute value of the vector's components

Returns: number


getAbs

getAbs() -> Vec2

Get a copy of this vector with absolute value of each component

Returns: Vec2


isNearlyZero

isNearlyZero() -> boolean

Checks whether a vector is near to zero within a reasonable tolerance

Returns: boolean


isZero

isZero() -> boolean

Checks whether all components of a vector are exactly zero

Returns: boolean


getSignVector

getSignVector() -> Vec2

Get a copy of the vector as sign only. Each component ise set to +1 or -1, with the sign of zero treated as +1

Returns: Vec2


containsNan

containsNan() -> boolean

Utility to check if there are any non-finite values (NaN or Inf) in this vector

Returns: boolean


dot

dot(rhs: Vec3) -> number

Calculate the dot product of two vectors

Parameters

Name Type
rhs Vec3

Returns: number


distance

distance(rhs: Vec3) -> number

Calculate the distance between two vectors

Parameters

Name Type
rhs Vec3

Returns: number


lerp

lerp(_end: Vec3, t: number) -> Vec2

Interpolates between two points start and end with 0 <= t <= 1

Parameters

Name Type
_end Vec3
t number

Returns: Vec2

Static properties

Property Type Description
zeroVector Vec2 Zero vector (0,0)
oneVector Vec2 One vector (1,1)
unitDiagonal Vec2 Normalized one vector (sqrt(2),sqrt(2))
unitY Vec2 Unit Y vector (0,1)
unitX Vec2 Unit X vector (0,1)

Static functions

Method Description
dot Calculate the dot product of two vectors
distance Calculate the distance between two vectors
lerp Interpolates between two points start and end with 0 <= t <= 1

dot

Vec2.dot(lhs: Vec2, rhs: Vec3) -> number

Calculate the dot product of two vectors

Parameters

Name Type
lhs Vec2
rhs Vec3

Returns: number


distance

Vec2.distance(lhs: Vec2, rhs: Vec3) -> number

Calculate the distance between two vectors

Parameters

Name Type
lhs Vec2
rhs Vec3

Returns: number


lerp

Vec2.lerp(start: Vec2, _end: Vec3, t: number) -> Vec2

Interpolates between two points start and end with 0 <= t <= 1

Parameters

Name Type
start Vec2
_end Vec3
t number

Returns: Vec2

Quat

Class

A simple Quaternion type which holds 4 Numbers

Properties

Property Type Description
x number The X Component of the Quaternion
y number The Y Component of the Quaternion
z number The Z Component of the Quaternion
w number The W Component of the Quaternion

Methods

Method Description
euler Convert a Quaternion into floating-point Euler angles (in degrees)
getForwardVector Get the forward direction (X axis) after it has been rotated by this Quaternion
getRightVector Get the right direction (Y axis) after it has been rotated by this Quaternion
getUpVector Get the up direction (Z axis) after it has been rotated by this Quaternion
rotateVector Rotate a vector by this quaternion
inverse The inverse rotation of this quaternion
normalize Normalize this quaternion if it is large enough. If it is too small, returns an identity quaternion.

euler

euler() -> Vec3

Convert a Quaternion into floating-point Euler angles (in degrees)

Returns: Vec3


getForwardVector

getForwardVector() -> Vec3

Get the forward direction (X axis) after it has been rotated by this Quaternion

Returns: Vec3


getRightVector

getRightVector() -> Vec3

Get the right direction (Y axis) after it has been rotated by this Quaternion

Returns: Vec3


getUpVector

getUpVector() -> Vec3

Get the up direction (Z axis) after it has been rotated by this Quaternion

Returns: Vec3


rotateVector

rotateVector(vector: Vec3) -> Vec3

Rotate a vector by this quaternion

Parameters

Name Type
vector Vec3

Returns: Vec3


inverse

inverse() -> Quat

The inverse rotation of this quaternion

Returns: Quat


normalize

normalize() -> Quat

Normalize this quaternion if it is large enough. If it is too small, returns an identity quaternion.

Returns: Quat

Static properties

Property Type Description
identity Quat The identity quaternion, one with no rotation (0,0,0,1)

Static functions

Method Description
fromEuler Convert (roll, pitch, yaw) Euler angles (in degrees) into a Quaternion.
fromDirection Return the Quaternion orientation corresponding to the direction in which the vector points.
fromXZ Create a quaternion from forward and up vectors
findBetweenVectors Finds the smallest rotation between two vectors
slerp Spherical linear interpolation between a and b by 0 <= t <= 1

fromEuler

Quat.fromEuler(Roll: number, Pitch: number, Yaw: number) -> Quat

Convert (roll, pitch, yaw) Euler angles (in degrees) into a Quaternion.

Parameters

Name Type
Roll number
Pitch number
Yaw number

Returns: Quat


fromDirection

Quat.fromDirection(FromDirection: Vec3) -> Quat

Return the Quaternion orientation corresponding to the direction in which the vector points.

Parameters

Name Type
FromDirection Vec3

Returns: Quat


fromXZ

Quat.fromXZ(Forward: Vec3, Up: Vec3) -> Quat

Create a quaternion from forward and up vectors

Parameters

Name Type
Forward Vec3
Up Vec3

Returns: Quat


findBetweenVectors

Quat.findBetweenVectors(Start: Vec3, _end: Vec3) -> Quat

Finds the smallest rotation between two vectors

Parameters

Name Type
Start Vec3
_end Vec3

Returns: Quat


slerp

Quat.slerp(From: Quat, To: Quat, T: number) -> Quat

Spherical linear interpolation between a and b by 0 <= t <= 1

Parameters

Name Type
From Quat
To Quat
T number

Returns: Quat

Transform

Class

A simple Transform type which holds 3 Numbers, X+ is Forward, Y+ is Right, Z+ is Up

Properties

Property Type Description
position Vec3 The position of the transform
rotation Quat The rotation of the transform
scale Vec3 The scale of the transform

Static properties

Property Type Description
identity Transform Identity transform

DateTime

Class

A simple DateTime type which holds 3 Numbers, X+ is Forward, Y+ is Right, Z+ is Up

Properties

Property Type Description
ticks number The number of ticks (100 ns) since January 1 0001

Static functions

Method Description
getCurrentTime Get the current time

getCurrentTime

DateTime.getCurrentTime() -> DateTime

Get the current time

Returns: DateTime

Color

Class

A simple Color type which holds 4 Numbers

Properties

Property Type Description
R number The X Component of the Color
G number The Y Component of the Color
B number The Z Component of the Color
W number The W Component of the Color

Static properties

Property Type Description
White Color Gets the White Color
Black Color Gets the Black Color
Transparent Color Gets the Transparent Color
Red Color Gets the Red Color
Green Color Gets the Green Color
Blue Color Gets the Blue Color
Yellow Color Gets the Yellow Color
Cyan Color Gets the Cyan Color
Magenta Color Gets the Magenta Color
Orange Color Gets the Orange Color
Purple Color Gets the Purple Color
Turquoise Color Gets the Turquoise Color
Silver Color Gets the Silver Color
Emerald Color Gets the Emerald Color

LinearColor

Class

A simple LinearColor type which holds 4 Numbers

Properties

Property Type Description
R number The X Component of the LinearColor
G number The Y Component of the LinearColor
B number The Z Component of the LinearColor
W number The W Component of the LinearColor
A number The alpha (W) Component of the LinearColor

Static properties

Property Type Description
White LinearColor The X Component of the LinearColor