math types

vec2

class vec2
static vec2(x)
static vec2(x, y)

Create a new vec2 by setting both values at once or each one individually

static min(v1, v2)

Return a vec2 containing the component-wise minimum of two vectors

static max(v1, v2)

Return a vec2 containing the component-wise maximum two vectors

x: number

The x component of this vector

y: number

The y component of this vector

length: number

The length of this vector

length2: number

The squared length of this vector

normalize()

Normalize this vector

normalized()

Return a normalized copy of this vector

dot(v)

Perform a scalar dot product with another vector and return the result

distance(v)

Calculate the distance (i.e. L1 norm) to another vector

distance2(v)

Calculate the squared distance (i.e. L2 norm) to another vector

reflect(normal)

Reflect this vector about another

refract(normal, ior)

Refract this vector though another with a given index or refraction

lerp(v, t)

Interpolate this vector with another by the a given factor (typically between 0 and 1)

abs()

Return a copy of this vector with component-wise absolute values

unpack() x, y

Unpack this vector as multiple number values

vec3

class vec3
static vec3(x)
static vec3(x, y, z)

Create a new vec3 by setting all values at once or each one individually

static min(v1, v2)

Return a vec3 containing the component-wise minimum of two vectors

static max(v1, v2)

Return a vec3 containing the component-wise maximum two vectors

x: number

The x component of this vector

y: number

The y component of this vector

z: number

The z component of this vector

length: number

The length of this vector

length2: number

The squared length of this vector

normalize()

Normalize this vector

normalized()

Return a normalized copy of this vector

dot(v)

Perform a scalar dot product with another vector and return the result

cross(v)

Perform a cross product with another vec3 and return the result

distance(v)

Calculate the distance (i.e. L1 norm) to another vector

distance2(v)

Calculate the squared distance (i.e. L2 norm) to another vector

reflect(normal)

Reflect this vector about another

refract(normal, ior)

Refract this vector though another with a given index or refraction

lerp(v, t)

Interpolate this vector with another by the a given factor (typically between 0 and 1)

abs()

Return a copy of this vector with component-wise absolute values

unpack() x, y, z

Unpack this vector as multiple number values

vec4

class vec4
static vec4(x)
static vec4(x, y, z, w)

Create a new vec4 by setting all values at once or each one individually

static min(v1, v2)

Return a vec4 containing the component-wise minimum of two vectors

static max(v1, v2)

Return a vec4 containing the component-wise maximum two vectors

x: number

The x component of this vector

y: number

The y component of this vector

z: number

The z component of this vector

w: number

The w component of this vector

length: number

The length of this vector

length2: number

The squared length of this vector

normalize()

Normalize this vector

normalized()

Return a normalized copy of this vector

dot(v)

Perform a scalar dot product with another vector and return the result

distance(v)

Calculate the distance (i.e. L1 norm) to another vector

distance2(v)

Calculate the squared distance (i.e. L2 norm) to another vector

reflect(normal)

Reflect this vector about another

refract(normal, ior)

Refract this vector though another with a given index or refraction

lerp(v, t)

Interpolate this vector with another by the a given factor (typically between 0 and 1)

abs()

Return a copy of this vector with component-wise absolute values

unpack() x, y, z, w

Unpack this vector as multiple number values

quat

class quat
static quat()
static quat(x, y, z, w)

Create a new quat

static lookRotation(forward, up)
Returns:

A quat that points in the forward direction using up to orient it correctly

static fromToRotate(from, to)
Parameters:
  • from (vec3) – The direction to rotate from

  • to (vec3) – The direction to rotate to

Returns:

a quat containing a relative rotation between the from and to vectors

static angleAxis(angle, axis)
Parameters:
  • angle (number) – The amount of rotation in degrees

  • axis (vec3) – The axis of rotation

Returns:

a new quat containing a rotation defined by angle (in degrees) rotated about the axis vector

static eulerAngles(x, y, z)
Parameters:
  • x (number) – The amount of rotation about the x axis (yaw) in degrees

  • y (number) – The amount of rotation about the y axis (pitch) in degrees

  • z (number) – The amount of rotation about the z axis (roll) in degrees

Returns:

a new quat containing a rotation defined by 3 euler angles (i.e. yaw, pitch roll) in radians

x: number

The x component of this vector

y: number

The y component of this vector

z: number

The z component of this vector

w: number

The w component of this vector

angles: vec3

A set of euler angles (in degrees) that generates the same rotation as this quaternion

Please note that the potential euler angles from any given quaternion are ambiguous and should not be relied upon for smooth or consistent rotations especially when interpolating them

slerp(q, t)
Parameters:
  • q – The other quaternion to slerp to

  • t – The amount of interpolation (from 0 to 1)

Returns:

a new quat that is spherically interpolated from this quaternion to q via t (between 0 and 1)

conjugate()
Returns:

a new quat containing the conjugate of this quaternion

normalize()

Normalizes this quaternion

normalized()
Returns:

a normalized copy of this quaternion

mat2

class mat2

A simple 2x2 matrix

Each entry can be accessed via an index as well

m = mat2(1) -- init with diagonals set to 1
print(m[1]) -- prints '1.0'
static mat2()
static mat2(s)
static mat2(v1, v2)
static mat2(m11, m12, m21, m22)

Create a new mat2, default, diagonals, 2 vec2 objects or all 4 entries

inverse()
Returns:

the inverse of this matrix

transpose()
Returns:

the transpose of this matrix

determinant()
Returns:

the determinant of this matrix

row(index)
Returns:

the row at a given index (starting at 1)

Return type:

vec2

column(index)
Returns:

the column at a given index (starting at 1)

Return type:

vec2

mat3

class mat2

A simple 3x3 matrix

Each entry can be accessed via an index as well

m = mat3(1) -- init with diagonals set to 1
print(m[1]) -- prints '1.0'
static mat3()
static mat3(s)
static mat3(v1, v2, v3)
static mat3(m11, m12, m31, ..., m33)

Create a new mat3, default, diagonals, 3 vec3 objects or all 9 entries

inverse()
Returns:

the inverse of this matrix

transpose()
Returns:

the transpose of this matrix

determinant()
Returns:

the determinant of this matrix

row(index)
Returns:

the row at a given index (starting at 1)

Return type:

vec3

column(index)
Returns:

the column at a given index (starting at 1)

Return type:

vec3

mat4

class mat2

A simple 4x4 matrix, typically used for 3D homogonous transformations

Each entry can be accessed via an index as well

m = mat4(1) -- init with diagonals set to 1
print(m[1]) -- prints '1.0'
static mat4()
static mat4(s)
static mat4(v1, v2, v3, v4)
static mat4(m11, m12, m31, m41, ..., m44)

Create a new mat4, default, diagonals, 4 vec4 objects or all 16 entries

static lookAt(eye, center, up)
static lookAt(matrix, eye, center, up)
static orbit(origin, distance, x, y)
static orbit(matrix, origin, distance, x, y)
static ortho(left, right, top, bottom[, near, far])
static perspective(fovy, aspect, near, far)
static rotate(angle, axis)
static rotate(matrix, angle, axis)
inverse()
Returns:

the inverse of this matrix

transpose()
Returns:

the transpose of this matrix

determinant()
Returns:

the determinant of this matrix

row(index)
Returns:

the row at a given index (starting at 1)

Return type:

vec3

column(index)
Returns:

the column at a given index (starting at 1)

Return type:

vec3

aabb

class bounds.aabb