math¶
Interfaces
Functions
-
math.
add2D
(v1, v2)¶ Adds @v1 to @v2.
Arguments: - v1 –
math.IVec2()
- v2 –
math.IVec2()
Returns: - v1 –
-
math.
add3D
(v1, v2)¶ Adds @v1 to @v2.
Arguments: - v1 –
math.IVec3()
- v2 –
math.IVec3()
Returns: - v1 –
-
math.
clamp
(v, min, max)¶ Clamps value @x to fall between @min and @max.
Arguments: - v – number
- min – number
- max – number
Returns: number
-
math.
dot2D
(v1, v2)¶ Returns the inner product (i.e. dot product) of two 2D vectors.
Arguments: - v1 –
math.IVec2()
- v2 –
math.IVec2()
Returns: number
- v1 –
-
math.
dot3D
(v1, v2)¶ Returns the inner product (i.e. dot product) of two 3D vectors.
Arguments: - v1 –
math.IVec3()
- v2 –
math.IVec3()
Returns: number
- v1 –
-
math.
dot4D
(v1, v2)¶ Returns the inner product (i.e. dot product) of two 4D vectors.
Arguments: - v1 –
math.IVec4()
- v2 –
math.IVec4()
Returns: number
- v1 –
-
math.
equal
(v0, v1, threshold)¶ Return true if v0 and v1 are within threshold of one another.
Arguments: - v0 – number
- v1 – number
- threshold – number
Returns: boolean
-
math.
equal2D
(v0, v1, threshold)¶ Returns true if all components of v0 are within threshold of v1.
Arguments: - v0 –
math.IVec2()
- v1 –
math.IVec2()
- threshold – number
Returns: boolean
- v0 –
-
math.
equal3D
(v0, v1, threshold)¶ Returns true if all components of v0 are within threshold of v1.
Arguments: - v0 –
math.IVec3()
- v1 –
math.IVec3()
- threshold – number
Returns: boolean
- v0 –
-
math.
equal4D
(v0, v1, threshold)¶ Returns true if all components of v0 are within threshold of v1.
Arguments: - v0 –
math.IVec4()
- v1 –
math.IVec4()
- threshold – number
Returns: boolean
- v0 –
-
math.
evalLine2D
(origin, direction, t)¶ Evaluates a parametric line: origin + direction*t.
Arguments: - origin –
math.IVec2()
- direction –
math.IVec2()
- t – number
Returns: - origin –
-
math.
getDistanceToSegment2D
(pt, segA, segB)¶ Returns the squared distance of point @pt to segment @segA-@segB.
Arguments: - pt –
math.IVec2()
- segA –
math.IVec2()
- segB –
math.IVec2()
Returns: number
- pt –
-
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: - point –
math.IVec2()
- segOrigin –
math.IVec2()
- segDirection –
math.IVec2()
Returns: number
- point –
-
math.
getProjectionFactor2D
(vector, axis)¶ Returns the parametric coordinate t of the projection point of vector unto axis.
Arguments: - vector –
math.IVec2()
- axis –
math.IVec2()
Returns: number
- vector –
-
math.
getSquaredDistanceToSegment2D
(point, segA, segB)¶ Returns the squared distance of point @pt to segment @segA-@segB.
Arguments: - point –
math.IVec2()
- segA –
math.IVec2()
- segB –
math.IVec2()
Returns: number
- point –
-
math.
homogenize3D
(v)¶ Makes a vec3 homogenous, i.e. that the last component is 1.
Arguments: - v –
math.IVec3()
Returns: - v –
-
math.
homogenize4D
(v)¶ Makes a vec4 homogenous, i.e. that the last component is 1.
Arguments: - v –
math.IVec4()
Returns: - v –
-
math.
length2D
(v)¶ Returns the norm of a 2D vector.
Arguments: - v –
math.IVec2()
Returns: number
- v –
-
math.
length3D
(v)¶ Returns the norm of a 2D vector.
Arguments: - v –
math.IVec3()
Returns: number
- v –
-
math.
lengthSq2D
(v)¶ Returns the squared norm of a 2D vector.
Arguments: - v –
math.IVec2()
Returns: number
- v –
-
math.
lengthSq3D
(v)¶ Returns the squared norm of a 3D vector.
Arguments: - v –
math.IVec3()
Returns: number
- v –
-
math.
mad2D
(v1, v2, v3)¶ Multiplies @v1 and @v2, then adds @v3 to the result.
Arguments: - v1 –
math.IVec2()
- v2 –
math.IVec2()
- v3 –
math.IVec2()
Returns: - v1 –
-
math.
mad3D
(v1, v2, v3)¶ Multiplies @v1 and @v2, then adds @v3 to the result.
Arguments: - v1 –
math.IVec3()
- v2 –
math.IVec3()
- v3 –
math.IVec3()
Returns: - v1 –
-
math.
mat3
(row0, row1, row2)¶ Returns a 3x3 matrix composed of 3 rows.
Arguments: - row0 –
math.IVec3()
- row1 –
math.IVec3()
- row2 –
math.IVec3()
Returns: - row0 –
-
math.
mat3FromArray
(rawNumbers)¶ Builds up a mat3 by feeding it with an array of 9 numbers (column logic)
Arguments: - rawNumbers – number []
Returns:
-
math.
mat3Identity
()¶ mat3 identity
Returns: math.IMat3()
-
math.
mat3ToArray
(mat)¶ Builds up a mat3 by feeding it with an array of 9 numbers
Arguments: - mat –
math.IMat3()
Returns: number []
- mat –
-
math.
mat4
(row0, row1, row2, row3)¶ Returns a 4x4 matrix composed of 4 rows.
Arguments: - row0 –
math.IVec4()
- row1 –
math.IVec4()
- row2 –
math.IVec4()
- row3 –
math.IVec4()
Returns: - row0 –
-
math.
mix
(v1, v2, t)¶ Linear interpolation between @v1 and @v2 using @t as a parameter.
Arguments: - v1 – number
- v2 – number
- t – number
Returns: number
-
math.
mul2D
(v1, v2)¶ Multiplies 2D vectors @v1 and @v2 together.
Arguments: - v1 –
math.IVec2()
- v2 –
math.IVec2()
Returns: - v1 –
-
math.
mul3D
(v1, v2)¶ Multiplies 2D vectors @v1 and @v2 together.
Arguments: - v1 –
math.IVec3()
- v2 –
math.IVec3()
Returns: - v1 –
-
math.
mulmat3
(m, v)¶ Transforms a vec3 by a mat3.
Arguments: - m –
math.IMat3()
- v –
math.IVec3()
Returns: - m –
-
math.
mulmat4
(m, v)¶ Transforms a vec4 by a mat4.
Arguments: - m –
math.IMat4()
- v –
math.IVec4()
Returns: - m –
-
math.
muls2D
(v1, s)¶ Multiplies a 2D vector @v1 by scalar @s.
Arguments: - v1 –
math.IVec2()
- s – number
Returns: - v1 –
-
math.
muls3D
(v1, s)¶ Multiplies a 2D vector @v1 by scalar @s.
Arguments: - v1 –
math.IVec3()
- s – number
Returns: - v1 –
-
math.
muls4D
(v1, s)¶ Multiplies a 4D vector @v1 by scalar @s.
Arguments: - v1 –
math.IVec4()
- s – number
Returns: - v1 –
-
math.
normalize2D
(v)¶ Normalizes a vec2 so that its length is 1.
Arguments: - v –
math.IVec2()
Returns: - v –
-
math.
normalize3D
(v)¶ Normalizes a vec3 so that its length is 1.
Arguments: - v –
math.IVec3()
Returns: - v –
-
math.
prodmat3
(m1, m2)¶ returns the product of 2 mat3
Arguments: - m1 –
math.IMat3()
- m2 –
math.IMat3()
Returns: - m1 –
-
math.
projectPointUntoSegment2D
(point, segA, segB)¶ Deprecated.
Arguments: - point –
math.IVec2()
- segA –
math.IVec2()
- segB –
math.IVec2()
Returns: - point –
-
math.
projectPosition
(m, v)¶ Projects a 3D vector @v using the 4x4 matrix @m.
Arguments: - m –
math.IMat4()
- v –
math.IVec3()
Returns: - m –
-
math.
projectPosition2
(m, v)¶ Projects a 2D vector @v using the 3x3 matrix @m.
Arguments: - m –
math.IMat3()
- v –
math.IVec2()
Returns: - m –
-
math.
projectUnto2D
(vector, axis)¶ Returns the projection point of vector unto axis.
Arguments: - vector –
math.IVec2()
- axis –
math.IVec2()
Returns: - vector –
-
math.
sub2D
(v1, v2)¶ Subtracts @v2 from @v1.
Arguments: - v1 –
math.IVec2()
- v2 –
math.IVec2()
Returns: - v1 –
-
math.
sub3D
(v1, v2)¶ Subtracts @v2 from @v1.
Arguments: - v1 –
math.IVec3()
- v2 –
math.IVec3()
Returns: - v1 –
-
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: - v –
math.IVec3()
|math.IVec4()
|math.IColor3()
|math.IColor4()
Returns: undefined | string
- v –
-
math.
transposemat3
(mat)¶ transpose a mat3
Arguments: - mat –
math.IMat3()
Returns: - mat –
-
math.
transposemat4
(mat)¶ Returns a 4x4 matrix transposed.
Arguments: - mat –
math.IMat4()
Returns: - mat –
-
math.
vec2
(x, y)¶ Returns a 2D vector.
Arguments: - x – number
- y – number
Returns:
-
math.
vec3
(x, y, z)¶ Returns a 3D vector.
Arguments: - x – number
- y – number
- z – number
Returns:
-
math.
vec4
(x, y, z, w)¶ Returns a 4D vector.
Arguments: - x – number
- y – number
- z – number
- w – number
Returns: