math

Interfaces

Functions

math.add2D(v1, v2)

Adds @v1 to @v2.

Arguments:
Returns:

math.IVec2()

math.add3D(v1, v2)

Adds @v1 to @v2.

Arguments:
Returns:

math.IVec3()

math.clamp(v, min, max)

Clamps value @x to fall between @min and @max.

Arguments:
  • vnumber
  • minnumber
  • maxnumber
Returns:

number

math.dot2D(v1, v2)

Returns the inner product (i.e. dot product) of two 2D vectors.

Arguments:
Returns:

number

math.dot3D(v1, v2)

Returns the inner product (i.e. dot product) of two 3D vectors.

Arguments:
Returns:

number

math.dot4D(v1, v2)

Returns the inner product (i.e. dot product) of two 4D vectors.

Arguments:
Returns:

number

math.equal(v0, v1, threshold)

Return true if v0 and v1 are within threshold of one another.

Arguments:
  • v0number
  • v1number
  • thresholdnumber
Returns:

boolean

math.equal2D(v0, v1, threshold)

Returns true if all components of v0 are within threshold of v1.

Arguments:
Returns:

boolean

math.equal3D(v0, v1, threshold)

Returns true if all components of v0 are within threshold of v1.

Arguments:
Returns:

boolean

math.equal4D(v0, v1, threshold)

Returns true if all components of v0 are within threshold of v1.

Arguments:
Returns:

boolean

math.evalLine2D(origin, direction, t)

Evaluates a parametric line: origin + direction*t.

Arguments:
Returns:

math.IVec2()

math.getDistanceToSegment2D(pt, segA, segB)

Returns the squared distance of point @pt to segment @segA-@segB.

Arguments:
Returns:

number

math.getParameter_ClosestPointToSegment2D(point, segOrigin, segDirection)

Returns the parametric factor (between 0 and 1) corresponding to the point on the segment that is closest to @point. To retrieve the actual point on the segment, call: evalLine2D(segOrigin, segDirection, t);

Arguments:
Returns:

number

math.getProjectionFactor2D(vector, axis)

Returns the parametric coordinate t of the projection point of vector unto axis.

Arguments:
Returns:

number

math.getSquaredDistanceToSegment2D(point, segA, segB)

Returns the squared distance of point @pt to segment @segA-@segB.

Arguments:
Returns:

number

math.homogenize3D(v)

Makes a vec3 homogenous, i.e. that the last component is 1.

Arguments:
Returns:

math.IVec3()

math.homogenize4D(v)

Makes a vec4 homogenous, i.e. that the last component is 1.

Arguments:
Returns:

math.IVec4()

math.length2D(v)

Returns the norm of a 2D vector.

Arguments:
Returns:

number

math.length3D(v)

Returns the norm of a 2D vector.

Arguments:
Returns:

number

math.lengthSq2D(v)

Returns the squared norm of a 2D vector.

Arguments:
Returns:

number

math.lengthSq3D(v)

Returns the squared norm of a 3D vector.

Arguments:
Returns:

number

math.mad2D(v1, v2, v3)

Multiplies @v1 and @v2, then adds @v3 to the result.

Arguments:
Returns:

math.IVec2()

math.mad3D(v1, v2, v3)

Multiplies @v1 and @v2, then adds @v3 to the result.

Arguments:
Returns:

math.IVec3()

math.mat3(row0, row1, row2)

Returns a 3x3 matrix composed of 3 rows.

Arguments:
Returns:

math.IMat3()

math.mat3FromArray(rawNumbers)

Builds up a mat3 by feeding it with an array of 9 numbers (column logic)

Arguments:
  • rawNumbersnumber []
Returns:

math.IMat3()

math.mat3Identity()

mat3 identity

Returns:math.IMat3()
math.mat3ToArray(mat)

Builds up a mat3 by feeding it with an array of 9 numbers

Arguments:
Returns:

number []

math.mat4(row0, row1, row2, row3)

Returns a 4x4 matrix composed of 4 rows.

Arguments:
Returns:

math.IMat4()

math.mix(v1, v2, t)

Linear interpolation between @v1 and @v2 using @t as a parameter.

Arguments:
  • v1number
  • v2number
  • tnumber
Returns:

number

math.mul2D(v1, v2)

Multiplies 2D vectors @v1 and @v2 together.

Arguments:
Returns:

math.IVec2()

math.mul3D(v1, v2)

Multiplies 2D vectors @v1 and @v2 together.

Arguments:
Returns:

math.IVec3()

math.mulmat3(m, v)

Transforms a vec3 by a mat3.

Arguments:
Returns:

math.IVec3()

math.mulmat4(m, v)

Transforms a vec4 by a mat4.

Arguments:
Returns:

math.IVec4()

math.muls2D(v1, s)

Multiplies a 2D vector @v1 by scalar @s.

Arguments:
Returns:

math.IVec2()

math.muls3D(v1, s)

Multiplies a 2D vector @v1 by scalar @s.

Arguments:
Returns:

math.IVec3()

math.muls4D(v1, s)

Multiplies a 4D vector @v1 by scalar @s.

Arguments:
Returns:

math.IVec4()

math.normalize2D(v)

Normalizes a vec2 so that its length is 1.

Arguments:
Returns:

math.IVec2()

math.normalize3D(v)

Normalizes a vec3 so that its length is 1.

Arguments:
Returns:

math.IVec3()

math.prodmat3(m1, m2)

returns the product of 2 mat3

Arguments:
Returns:

math.IMat3()

math.projectPointUntoSegment2D(point, segA, segB)

Deprecated.

Arguments:
Returns:

math.IVec2()

math.projectPosition(m, v)

Projects a 3D vector @v using the 4x4 matrix @m.

Arguments:
Returns:

math.IVec3()

math.projectPosition2(m, v)

Projects a 2D vector @v using the 3x3 matrix @m.

Arguments:
Returns:

math.IVec2()

math.projectUnto2D(vector, axis)

Returns the projection point of vector unto axis.

Arguments:
Returns:

math.IVec2()

math.sub2D(v1, v2)

Subtracts @v2 from @v1.

Arguments:
Returns:

math.IVec2()

math.sub3D(v1, v2)

Subtracts @v2 from @v1.

Arguments:
Returns:

math.IVec3()

math.toHTMLColorString(v)

Converts a vec3 into an “rgb(x*255,y*255,z*255)” string, or vec4 into an “rgba(x*255,y*255,z*255,w*255)”. Also accepts structure with {r,g,b,a} elements.

Arguments:
Returns:

undefined | string

math.transposemat3(mat)

transpose a mat3

Arguments:
Returns:

math.IMat3()

math.transposemat4(mat)

Returns a 4x4 matrix transposed.

Arguments:
Returns:

math.IMat4()

math.vec2(x, y)

Returns a 2D vector.

Arguments:
  • xnumber
  • ynumber
Returns:

math.IVec2()

math.vec3(x, y, z)

Returns a 3D vector.

Arguments:
  • xnumber
  • ynumber
  • znumber
Returns:

math.IVec3()

math.vec4(x, y, z, w)

Returns a 4D vector.

Arguments:
  • xnumber
  • ynumber
  • znumber
  • wnumber
Returns:

math.IVec4()