Skip to main content

maths

Modules

ModuleDescription
modeling/mathsMaths are computational units for fundamental Euclidean geometry. All maths operate upon array data structures. Note: Maths data structures are considered immutable, so never change the contents directly.
modeling/maths/line2Represents a unbounded line in 2D space, positioned at a point of origin.
modeling/maths/line3Represents a unbounded line in 3D space, positioned at a point of origin.
modeling/maths/mat4Represents a 4x4 matrix which is column-major (when typed out it looks row-major).
modeling/maths/planeRepresents a plane in 3D coordinate space as determined by a normal (perpendicular to the plane) and distance from 0,0,0.
modeling/maths/utilsUtility functions for maths.
modeling/maths/vec2Represents a two dimensional vector.
modeling/maths/vec3Represents a three dimensional vector.
modeling/maths/vec4Represents a four dimensional vector.

Constants

NameDescription
TAUThe TAU property represents the ratio of the circumference of a circle to its radius. Approximately 6.28318530717958647692

Typedefs

NameDescription
line2Represents a unbounded line in 2D space, positioned at a point of origin. A line is parametrized by a normal vector (perpendicular to the line, rotated 90 degrees counter clockwise) and distance from the origin.
line3Represents a unbounded line in 3D space, positioned at a point of origin. A line is parametrized by a point of origin and a directional vector.
mat4Represents a 4x4 matrix which is column-major (when typed out it looks row-major). See fromValues().
planeRepresents a plane in 3D coordinate space as determined by a normal (perpendicular to the plane) and distance from 0,0,0.
vec2Represents a two dimensional vector. See fromValues().
vec3Represents a three dimensional vector. See fromValues().
vec4Represents a four dimensional vector. See fromValues().

modeling/maths

Maths are computational units for fundamental Euclidean geometry. All maths operate upon array data structures. Note: Maths data structures are considered immutable, so never change the contents directly.

See: Most computations are based upon the glMatrix library (glmatrix.net)
Example

const { constants, line2, line3, mat4, plane, utils, vec2, vec3, vec4 } = require('@jscad/modeling').maths

modeling/maths.spatialResolution

The resolution of space, currently one hundred nanometers. This should be 1 / EPS.

Kind: static constant of modeling/maths
Default: 100000

modeling/maths.EPS

Epsilon used during determination of near zero distances. This should be 1 / spacialResolution.

Kind: static constant of modeling/maths
Default: 0.00001

modeling/maths.NEPS

Smaller epsilon used for measuring near zero distances.

Kind: static constant of modeling/maths
Default: 1e-13

modeling/maths/line2

Represents a unbounded line in 2D space, positioned at a point of origin.

See: line2 for data structure information.

modeling/maths/line2.clone(line)

Create a clone of the given line.

Kind: static method of modeling/maths/line2
Returns: line2 - a new unbounded line

ParamTypeDescription
lineline2line to clone

modeling/maths/line2.closestPoint(line, point)

Determine the closest point on the given line to the given point.

Kind: static method of modeling/maths/line2
Returns: vec2 - closest point

ParamTypeDescription
lineline2line of reference
pointvec2point of reference

modeling/maths/line2.copy(out, line)

Copy the given line to the receiving line.

Kind: static method of modeling/maths/line2
Returns: line2 - out

ParamTypeDescription
outline2receiving line
lineline2line to copy

modeling/maths/line2.create()

Create a line, positioned at 0,0, and running along the X axis.

Kind: static method of modeling/maths/line2
Returns: line2 - a new unbounded line

modeling/maths/line2.direction(line)

Return the direction of the given line.

Kind: static method of modeling/maths/line2
Returns: vec2 - a vector in the direction of the line

ParamTypeDescription
lineline2line of reference

modeling/maths/line2.distanceToPoint(line, point)

Calculate the distance (positive) between the given point and line.

Kind: static method of modeling/maths/line2
Returns: Number - distance between line and point

ParamTypeDescription
lineline2line of reference
pointvec2point of reference

modeling/maths/line2.equals(line1, line2)

Compare the given lines for equality.

Kind: static method of modeling/maths/line2
Returns: Boolean - true if lines are equal

ParamTypeDescription
line1line2first line to compare
line2line2second line to compare

modeling/maths/line2.fromPoints(out, point1, point2)

Create a new line that passes through the given points.

Kind: static method of modeling/maths/line2
Returns: line2 - a new unbounded line

ParamTypeDescription
outline2receiving line
point1vec2start point of the line
point2vec2end point of the line

modeling/maths/line2.fromValues(x, y, d)

Creates a new line initialized with the given values.

Kind: static method of modeling/maths/line2
Returns: line2 - a new unbounded line

ParamTypeDescription
xNumberX coordinate of the unit normal
yNumberY coordinate of the unit normal
dNumberdistance of the line from [0,0]

modeling/maths/line2.intersectPointOfLines(line1, line2)

Return the point of intersection between the given lines.

NOTES: The point will have Infinity values if the lines are parallel. The point will have NaN values if the lines are the same.

Kind: static method of modeling/maths/line2
Returns: vec2 - the point of intersection

ParamTypeDescription
line1line2line of reference
line2line2line of reference

modeling/maths/line2.origin(line)

Return the origin of the given line. The origin is the point on the line which is closest to the origin [0, 0].

Kind: static method of modeling/maths/line2
Returns: vec2 - the origin of the line

ParamTypeDescription
lineline2line of reference

modeling/maths/line2.reverse(out, line)

Create a new line in the opposite direction as the given.

Kind: static method of modeling/maths/line2
Returns: line2 - out

ParamTypeDescription
outline2receiving line
lineline2line to reverse

modeling/maths/line2.toString(line)

Return a string representing the given line.

Kind: static method of modeling/maths/line2
Returns: String - string representation

ParamTypeDescription
lineline2line of reference

modeling/maths/line2.transform(out, line, matrix)

Transforms the given line using the given matrix.

Kind: static method of modeling/maths/line2
Returns: line2 - out

ParamTypeDescription
outline2receiving line
lineline2line to transform
matrixmat4matrix to transform with

modeling/maths/line2.xAtY(line, y)

Determine the X coordinate of the given line at the Y coordinate.

The X coordinate will be Infinity if the line is parallel to the X axis.

Kind: static method of modeling/maths/line2
Returns: Number - the X coordinate on the line

ParamTypeDescription
lineline2line of reference
yNumberY coordinate on the line

modeling/maths/line3

Represents a unbounded line in 3D space, positioned at a point of origin.

See: line3 for data structure information.

modeling/maths/line3.clone(line)

Create a clone of the given line.

Kind: static method of modeling/maths/line3
Returns: line3 - a new unbounded line

ParamTypeDescription
lineline3line to clone

modeling/maths/line3.closestPoint(line, point)

Determine the closest point on the given line to the given point.

Kind: static method of modeling/maths/line3
Returns: vec3 - a point

ParamTypeDescription
lineline3line of reference
pointvec3point of reference

modeling/maths/line3.copy(out, line)

Copy the given line into the receiving line.

Kind: static method of modeling/maths/line3
Returns: line3 - out

ParamTypeDescription
outline3receiving line
lineline3line to copy

modeling/maths/line3.create()

Create a line, positioned at 0,0,0 and lying on the X axis.

Kind: static method of modeling/maths/line3
Returns: line3 - a new unbounded line

modeling/maths/line3.direction(line)

Return the direction of the given line.

Kind: static method of modeling/maths/line3
Returns: vec3 - the relative vector in the direction of the line

ParamTypeDescription
lineline3line for reference

modeling/maths/line3.distanceToPoint(line, point)

Calculate the distance (positive) between the given point and line.

Kind: static method of modeling/maths/line3
Returns: Number - distance between line and point

ParamTypeDescription
lineline3line of reference
pointvec3point of reference

modeling/maths/line3.equals(line1, line2)

Compare the given lines for equality.

Kind: static method of modeling/maths/line3
Returns: Boolean - true if lines are equal

ParamTypeDescription
line1line3first line to compare
line2line3second line to compare

modeling/maths/line3.fromPlanes(out, plane1, plane2)

Create a line the intersection of the given planes.

Kind: static method of modeling/maths/line3
Returns: line3 - out

ParamTypeDescription
outline3receiving line
plane1planefirst plane of reference
plane2planesecond plane of reference

modeling/maths/line3.fromPointAndDirection(out, point, direction)

Create a line from the given point (origin) and direction.

The point can be any random point on the line. The direction must be a vector with positive or negative distance from the point.

See the logic of fromPoints() for appropriate values.

Kind: static method of modeling/maths/line3
Returns: line3 - out

ParamTypeDescription
outline3receiving line
pointvec3start point of the line segment
directionvec3direction of the line segment

modeling/maths/line3.fromPoints(out, point1, point2)

Create a line that passes through the given points.

Kind: static method of modeling/maths/line3
Returns: line3 - out

ParamTypeDescription
outline3receiving line
point1vec3start point of the line segment
point2vec3end point of the line segment

modeling/maths/line3.intersectPointOfLineAndPlane(line, plane)

Determine the closest point on the given plane to the given line.

NOTES: The point of intersection will be invalid if the line is parallel to the plane, e.g. NaN.

Kind: static method of modeling/maths/line3
Returns: vec3 - a point on the line

ParamTypeDescription
lineline3line of reference
planeplaneplane of reference

modeling/maths/line3.origin(line)

Return the origin of the given line.

Kind: static method of modeling/maths/line3
Returns: vec3 - the origin of the line

ParamTypeDescription
lineline3line of reference

modeling/maths/line3.reverse(out, line)

Create a line in the opposite direction as the given.

Kind: static method of modeling/maths/line3
Returns: line3 - out

ParamTypeDescription
outline3receiving line
lineline3line to reverse

modeling/maths/line3.toString(line)

Return a string representing the given line.

Kind: static method of modeling/maths/line3
Returns: String - string representation

ParamTypeDescription
lineline3line of reference

modeling/maths/line3.transform(out, line, matrix)

Transforms the given line using the given matrix.

Kind: static method of modeling/maths/line3
Returns: line3 - a new unbounded line

ParamTypeDescription
outline3line to update
lineline3line to transform
matrixmat4matrix to transform with

modeling/maths/mat4

Represents a 4x4 matrix which is column-major (when typed out it looks row-major).

See: mat4 for data structure information.

modeling/maths/mat4.add(out, a, b)

Adds the two matrices (A+B).

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
amat4first operand
bmat4second operand

modeling/maths/mat4.clone(matrix)

Creates a clone of the given matrix.

Kind: static method of modeling/maths/mat4
Returns: mat4 - a new matrix

ParamTypeDescription
matrixmat4matrix to clone

modeling/maths/mat4.copy(out, matrix)

Creates a copy of the given matrix.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
matrixmat4matrix to copy

modeling/maths/mat4.create()

Creates a new identity matrix.

Kind: static method of modeling/maths/mat4
Returns: mat4 - a new matrix

modeling/maths/mat4.equals(a, b)

Returns whether or not the matrices have exactly the same elements in the same position.

Kind: static method of modeling/maths/mat4
Returns: Boolean - true if the matrices are equal

ParamTypeDescription
amat4first matrix
bmat4second matrix

modeling/maths/mat4.fromRotation(out, rad, axis)

Creates a matrix from a given angle around a given axis This is equivalent to (but much faster than):

mat4.identity(dest) mat4.rotate(dest, dest, rad, axis)

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
radNumberangle to rotate the matrix by
axisvec3axis of which to rotate around

Example

let matrix = fromRotation(create(), TAU / 4, [0, 0, 3])

modeling/maths/mat4.fromScaling(out, vector)

Creates a matrix from a vector scaling. This is equivalent to (but much faster than):

mat4.identity(dest) mat4.scale(dest, dest, vec)

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
vectorvec3X, Y, Z factors by which to scale

Example

let matrix = fromScaling([1, 2, 0.5])

modeling/maths/mat4.fromTaitBryanRotation(out, yaw, pitch, roll)

Creates a matrix from the given Tait–Bryan angles.

Tait-Bryan Euler angle convention using active, intrinsic rotations around the axes in the order z-y-x.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out
See: https://en.wikipedia.org/wiki/Euler_angles

ParamTypeDescription
outmat4receiving matrix
yawNumberZ rotation in radians
pitchNumberY rotation in radians
rollNumberX rotation in radians

Example

let matrix = fromTaitBryanRotation(create(), TAU / 4, 0, TAU / 2)

modeling/maths/mat4.fromTranslation(out, vector)

Creates a matrix from a vector translation. This is equivalent to (but much faster than):

mat4.identity(dest) mat4.translate(dest, dest, vec)

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
vectorvec3offset (vector) of translation

Example

let matrix = fromTranslation(create(), [1, 2, 3])

modeling/maths/mat4.fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)

Create a matrix with the given values.

Kind: static method of modeling/maths/mat4
Returns: mat4 - a new matrix

ParamTypeDescription
m00NumberComponent in column 0, row 0 position (index 0)
m01NumberComponent in column 0, row 1 position (index 1)
m02NumberComponent in column 0, row 2 position (index 2)
m03NumberComponent in column 0, row 3 position (index 3)
m10NumberComponent in column 1, row 0 position (index 4)
m11NumberComponent in column 1, row 1 position (index 5)
m12NumberComponent in column 1, row 2 position (index 6)
m13NumberComponent in column 1, row 3 position (index 7)
m20NumberComponent in column 2, row 0 position (index 8)
m21NumberComponent in column 2, row 1 position (index 9)
m22NumberComponent in column 2, row 2 position (index 10)
m23NumberComponent in column 2, row 3 position (index 11)
m30NumberComponent in column 3, row 0 position (index 12)
m31NumberComponent in column 3, row 1 position (index 13)
m32NumberComponent in column 3, row 2 position (index 14)
m33NumberComponent in column 3, row 3 position (index 15)

Example

let matrix = fromValues(
1, 0, 0, 1,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
)

modeling/maths/mat4.fromVectorRotation(out, source, target)

Create a matrix that rotates the given source to the given target vector.

Each vector must be a directional vector with a length greater than zero.

Kind: static method of modeling/maths/mat4
Returns: mat4 - a new matrix
See: https://gist.github.com/kevinmoran/b45980723e53edeb8a5a43c49f134724

ParamTypeDescription
outmat4receiving matrix
sourcevec3source vector
targetvec3target vector

Example

let matrix = fromVectorRotation(mat4.create(), [1, 2, 2], [-3, 3, 12])

modeling/maths/mat4.fromXRotation(out, radians)

Creates a matrix from the given angle around the X axis. This is equivalent to (but much faster than):

mat4.identity(dest) mat4.rotateX(dest, dest, radians)

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
radiansNumberangle to rotate the matrix by

Example

let matrix = fromXRotation(create(), TAU / 4)

modeling/maths/mat4.fromYRotation(out, radians)

Creates a matrix from the given angle around the Y axis. This is equivalent to (but much faster than):

mat4.identity(dest) mat4.rotateY(dest, dest, radians)

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
radiansNumberangle to rotate the matrix by

Example

let matrix = fromYRotation(create(), TAU / 4)

modeling/maths/mat4.fromZRotation(out, radians)

Creates a matrix from the given angle around the Z axis. This is equivalent to (but much faster than):

mat4.identity(dest) mat4.rotateZ(dest, dest, radians)

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
radiansNumberangle to rotate the matrix by

Example

let matrix = fromZRotation(create(), TAU / 4)

modeling/maths/mat4.identity(out)

Set a matrix to the identity transform.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix

modeling/maths/mat4.invert(out, matrix)

Creates a invert copy of the given matrix.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out
Author: Julian Lloyd code from https://github.com/jlmakes/rematrix/blob/master/src/index.js

ParamTypeDescription
outmat4receiving matrix
matrixmat4matrix to invert

modeling/maths/mat4.isIdentity(matrix)

Determine whether the given matrix is the identity transform. This is equivalent to (but much faster than):

mat4.equals(mat4.create(), matrix)

Kind: static method of modeling/maths/mat4
Returns: Boolean - true if matrix is the identity transform

ParamTypeDescription
matrixmat4the matrix

Example

if (mat4.isIdentity(mymatrix)) ...

modeling/maths/mat4.isMirroring(matrix)

Determine whether the given matrix is a mirroring transformation.

Kind: static method of modeling/maths/mat4
Returns: Boolean - true if matrix is a mirroring transformation

ParamTypeDescription
matrixmat4matrix of reference

modeling/maths/mat4.isOnlyTransformScale(matrix)

Determine whether the given matrix is only translate and/or scale. This code returns true for TAU / 2 rotation as it can be interpreted as scale.

Kind: static method of modeling/maths/mat4
Returns: Boolean - true if matrix is for translate and/or scale

ParamTypeDescription
matrixmat4the matrix

modeling/maths/mat4.mirrorByPlane(out, plane)

Create a matrix for mirroring about the given plane.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
planevec4plane of which to mirror the matrix

modeling/maths/mat4.multiply(out, a, b)

Multiplies the two matrices.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
amat4first operand
bmat4second operand

modeling/maths/mat4.rightMultiplyVec2(vector, matrix)

Multiply a 2D vector by a matrix (interpreted as 2 row, 1 column).

Calculation: result = v*M, where the fourth element is set to 1.

Kind: static method of modeling/maths/mat4
Returns: vec2 - a new vector

ParamTypeDescription
vectorvec2input vector
matrixmat4input matrix

modeling/maths/mat4.rightMultiplyVec3(vector, matrix)

Multiply a 3D vector by a matrix (interpreted as 3 row, 1 column)

Calculation: result = v*M, where the fourth element is set to 1.

Kind: static method of modeling/maths/mat4
Returns: vec3 - a new vector

ParamTypeDescription
vectorvec3input vector
matrixmat4input matrix

modeling/maths/mat4.rotate(out, matrix, radians, axis)

Rotates a matrix by the given angle about the given axis.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
matrixmat4matrix to rotate
radiansNumberangle to rotate the matrix by
axisvec3axis to rotate around

modeling/maths/mat4.rotateX(out, matrix, radians)

Rotates a matrix by the given angle around the X axis.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
matrixmat4matrix to rotate
radiansNumberangle to rotate the matrix by

modeling/maths/mat4.rotateY(out, matrix, radians)

Rotates a matrix by the given angle around the Y axis.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
matrixmat4matrix to rotate
radiansNumberangle to rotate the matrix by

modeling/maths/mat4.rotateZ(out, matrix, radians)

Rotates a matrix by the given angle around the Z axis.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
matrixmat4matrix to rotate
radiansNumberangle to rotate the matrix by

modeling/maths/mat4.scale(out, matrix, dimensions)

Scales the matrix by the given dimensions.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
matrixmat4matrix to scale
dimensionsvec3dimensions to scale the matrix by

modeling/maths/mat4.subtract(out, a, b)

Subtracts matrix b from matrix a. (A-B)

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
amat4first operand
bmat4second operand

modeling/maths/mat4.toString(mat)

Return a string representing the given matrix.

Kind: static method of modeling/maths/mat4
Returns: String - string representation

ParamTypeDescription
matmat4matrix of reference

modeling/maths/mat4.translate(out, matrix, offsets)

Translate the matrix by the given offset vector.

Kind: static method of modeling/maths/mat4
Returns: mat4 - out

ParamTypeDescription
outmat4receiving matrix
matrixmat4matrix to translate
offsetsvec3offset vector to translate by

modeling/maths/plane

Represents a plane in 3D coordinate space as determined by a normal (perpendicular to the plane) and distance from 0,0,0.

See: plane for data structure information.

modeling/maths/plane.flip(out, plane)

Flip the given plane.

Kind: static method of modeling/maths/plane
Returns: plane - out

ParamTypeDescription
outplanereceiving plane
planeplaneplane to flip

modeling/maths/plane.fromNoisyPoints(out, ...vertices)

Create a best-fit plane from the given noisy vertices.

NOTE: There are two possible orientations for every plane. This function always produces positive orientations.

See http://www.ilikebigbits.com for the original discussion

Kind: static method of modeling/maths/plane
Returns: Plane - out

ParamTypeDescription
outPlanereceiving plane
...verticesArraylist of vertices in any order or position

modeling/maths/plane.fromNormalAndPoint(out, normal, point)

Create a new plane from the given normal and point values.

Kind: static method of modeling/maths/plane
Returns: plane - out

ParamTypeDescription
outplanereceiving plane
normalvec3directional vector
pointvec3origin of plane

modeling/maths/plane.fromPoints(out, ...vertices)

Create a plane from the given points.

Kind: static method of modeling/maths/plane
Returns: plane - out

ParamTypeDescription
outplanereceiving plane
...verticesArraypoints on the plane

modeling/maths/plane.fromPointsRandom(out, a, b, c)

Create a new plane from the given points like fromPoints, but allow the vectors to be on one point or one line. In such a case, a random plane through the given points is constructed.

Kind: static method of modeling/maths/plane
Returns: plane - out

ParamTypeDescription
outplanereceiving plane
avec33D point
bvec33D point
cvec33D point

modeling/maths/plane.projectionOfPoint(plane, point)

Project the given point on to the given plane.

Kind: static method of modeling/maths/plane
Returns: vec3 - projected point on plane

ParamTypeDescription
planeplaneplane of reference
pointvec3point of reference

modeling/maths/plane.signedDistanceToPoint(plane, point)

Calculate the distance to the given point.

Kind: static method of modeling/maths/plane
Returns: Number - signed distance to point

ParamTypeDescription
planeplaneplane of reference
pointvec3point of reference

modeling/maths/plane.transform(out, plane, matrix)

Transform the given plane using the given matrix

Kind: static method of modeling/maths/plane
Returns: plane - out

ParamTypeDescription
outplanereceiving plane
planeplaneplane to transform
matrixmat4matrix to transform with

modeling/maths/plane~clone()

Kind: inner method of modeling/maths/plane
See: vec4.clone()

modeling/maths/plane~copy()

Kind: inner method of modeling/maths/plane
See: vec4.copy()

modeling/maths/plane~create()

Kind: inner method of modeling/maths/plane
See: vec4.create()

modeling/maths/plane~equals()

Kind: inner method of modeling/maths/plane
See: vec4.equals()

modeling/maths/plane~fromValues()

Kind: inner method of modeling/maths/plane
See: vec4.fromValues()

modeling/maths/plane~toString()

Kind: inner method of modeling/maths/plane
See: vec4.toString()

modeling/maths/utils

Utility functions for maths.

Example

const { area, solve2Linear } = require('@jscad/maths').utils

modeling/maths/utils.aboutEqualNormals(a, b)

Compare two normals (unit vectors) for near equality.

Kind: static method of modeling/maths/utils
Returns: Boolean - true if a and b are nearly equal

ParamTypeDescription
avec3normal a
bvec3normal b

modeling/maths/utils.area(points)

Calculate the area under the given points.

Kind: static method of modeling/maths/utils
Returns: Number - area under the given points

ParamTypeDescription
pointsArraylist of 2D points

modeling/maths/utils.interpolateBetween2DPointsForY(point1, point2, y)

Get the X coordinate of a point with a certain Y coordinate, interpolated between two points. Interpolation is robust even if the points have the same Y coordinate

Kind: static method of modeling/maths/utils
Returns: Array - X and Y of interpolated point

ParamType
point1vec2
point2vec2
yNumber

modeling/maths/utils.intersect(p1, p2, p3, p4)

Calculate the intersect point of the two line segments (p1-p2 and p3-p4), end points included. Note: If the line segments do NOT intersect then undefined is returned.

Kind: static method of modeling/maths/utils
Returns: vec2 - intersection point of the two line segments, or undefined
See: http://paulbourke.net/geometry/pointlineplane/

ParamTypeDescription
p1vec2first point of first line segment
p2vec2second point of first line segment
p3vec2first point of second line segment
p4vec2second point of second line segment

modeling/maths/vec2

Represents a two dimensional vector.

modeling/maths/vec2.abs(out, vector)

Calculates the absolute coordinates of the given vector.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
vectorvec2vector of reference

modeling/maths/vec2.add(out, a, b)

Adds the coordinates of two vectors (A+B).

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
avec2first operand
bvec2second operand

modeling/maths/vec2.angleDegrees(vector)

Calculate the angle of the given vector.

Kind: static method of modeling/maths/vec2
Returns: Number - angle in degrees

ParamTypeDescription
vectorvec2vector of reference

modeling/maths/vec2.angleRadians(vector)

Calculate the angle of the given vector.

Kind: static method of modeling/maths/vec2
Returns: Number - angle in radians

ParamTypeDescription
vectorvec2vector of reference

modeling/maths/vec2.clone(vector)

Create a clone of the given vector.

Kind: static method of modeling/maths/vec2
Returns: vec2 - a new vector

ParamTypeDescription
vectorvec2vector to clone

modeling/maths/vec2.copy(out, vector)

Create a copy of the given vector.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
vectorvec2source vector

modeling/maths/vec2.create()

Creates a new vector, initialized to [0,0].

Kind: static method of modeling/maths/vec2
Returns: vec2 - a new vector

modeling/maths/vec2.cross(out, a, b)

Computes the cross product (3D) of two vectors.

Kind: static method of modeling/maths/vec2
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector (3D)
avec2first operand
bvec2second operand

modeling/maths/vec2.distance(a, b)

Calculates the distance between two vectors.

Kind: static method of modeling/maths/vec2
Returns: Number - distance

ParamTypeDescription
avec2first operand
bvec2second operand

modeling/maths/vec2.divide(out, a, b)

Divides the coordinates of two vectors (A/B).

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
avec2first operand
bvec2second operand

modeling/maths/vec2.dot(a, b)

Calculates the dot product of two vectors.

Kind: static method of modeling/maths/vec2
Returns: Number - dot product

ParamTypeDescription
avec2first operand
bvec2second operand

modeling/maths/vec2.equals(a, b)

Compare the given vectors for equality.

Kind: static method of modeling/maths/vec2
Returns: Boolean - true if a and b are equal

ParamTypeDescription
avec2first operand
bvec2second operand

modeling/maths/vec2.fromAngleDegrees(out, degrees)

Create a new vector in the direction of the given angle.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
degreesNumberangle in degrees

modeling/maths/vec2.fromAngleRadians(out, radians)

Create a new vector in the direction of the given angle.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
radiansNumberangle in radians

modeling/maths/vec2.fromScalar(out, scalar)

Create a vector from a single scalar value.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
scalarNumberthe scalar value

modeling/maths/vec2.fromValues(x, y)

Creates a new vector initialized with the given values.

Kind: static method of modeling/maths/vec2
Returns: vec2 - a new vector

ParamTypeDescription
xNumberX coordinate
yNumberY coordinate

modeling/maths/vec2.length(vector)

Calculates the length of the given vector.

Kind: static method of modeling/maths/vec2
Returns: Number - length

ParamTypeDescription
vectorvec2vector of reference

modeling/maths/vec2.lerp(out, a, b, t)

Performs a linear interpolation between two vectors.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
avec2first operand
bvec2second operand
tNumberinterpolation amount between the two vectors

modeling/maths/vec2.max(out, a, b)

Returns the maximum coordinates of two vectors.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
avec2first operand
bvec2second operand

modeling/maths/vec2.min(out, a, b)

Returns the minimum coordinates of two vectors.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
avec2first operand
bvec2second operand

modeling/maths/vec2.multiply(out, a, b)

Multiplies the coordinates of two vectors (A*B).

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
avec2first operand
bvec2second operand

modeling/maths/vec2.negate(out, vector)

Negates the coordinates of the given vector.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
vectorvec2vector to negate

modeling/maths/vec2.normal(out, vector)

Calculates the normal of the given vector. The normal value is the given vector rotated 90 degrees.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
vectorvec2given value

modeling/maths/vec2.normalize(out, vector)

Normalize the given vector.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
vectorvec2vector to normalize

modeling/maths/vec2.rotate(out, vector, origin, radians)

Rotates the given vector by the given angle.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
vectorvec2vector to rotate
originvec2origin of the rotation
radiansNumberangle of rotation (radians)

modeling/maths/vec2.scale(out, vector, amount)

Scales the coordinates of the given vector.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
vectorvec2vector to scale
amountNumberamount to scale

modeling/maths/vec2.snap(out, vector, epsilon)

Snaps the coordinates of the given vector to the given epsilon.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
vectorvec2vector to snap
epsilonNumberepsilon of precision, less than 0

modeling/maths/vec2.squaredDistance(a, b)

Calculates the squared distance between the given vectors.

Kind: static method of modeling/maths/vec2
Returns: Number - squared distance

ParamTypeDescription
avec2first operand
bvec2second operand

modeling/maths/vec2.squaredLength(vector)

Calculates the squared length of the given vector.

Kind: static method of modeling/maths/vec2
Returns: Number - squared length

ParamTypeDescription
vectorvec2vector of reference

modeling/maths/vec2.subtract(out, a, b)

Subtracts the coordinates of two vectors (A-B).

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
avec2first operand
bvec2second operand

modeling/maths/vec2.toString(vector)

Convert the given vector to a representative string.

Kind: static method of modeling/maths/vec2
Returns: String - string representation

ParamTypeDescription
vectorvec2vector of reference

modeling/maths/vec2.transform(out, vector, matrix)

Transforms the given vector using the given matrix.

Kind: static method of modeling/maths/vec2
Returns: vec2 - out

ParamTypeDescription
outvec2receiving vector
vectorvec2vector to transform
matrixmat4matrix to transform with

modeling/maths/vec3

Represents a three dimensional vector.

See: vec3 for data structure information.

modeling/maths/vec3.abs(out, vector)

Calculates the absolute coordinates of the give vector.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector of reference

modeling/maths/vec3.add(out, a, b)

Adds the coordinates of two vectors (A+B).

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
avec3first operand
bvec3second operand

modeling/maths/vec3.angle(a, b)

Calculate the angle between two vectors.

Kind: static method of modeling/maths/vec3
Returns: Number - angle (radians)

ParamTypeDescription
avec3first operand
bvec3second operand

modeling/maths/vec3.clone(vector)

Create a clone of the given vector.

Kind: static method of modeling/maths/vec3
Returns: vec3 - a new vector

ParamTypeDescription
vectorvec3vector to clone

modeling/maths/vec3.copy(out, vector)

Create a copy of the given vector.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector to copy

modeling/maths/vec3.create()

Creates a new vector initialized to [0,0,0].

Kind: static method of modeling/maths/vec3
Returns: vec3 - a new vector

modeling/maths/vec3.cross(out, a, b)

Computes the cross product of the given vectors (AxB).

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
avec3first operand
bvec3second operand

modeling/maths/vec3.distance(a, b)

Calculates the Euclidian distance between the given vectors.

Kind: static method of modeling/maths/vec3
Returns: Number - distance

ParamTypeDescription
avec3first operand
bvec3second operand

modeling/maths/vec3.divide(out, a, b)

Divides the coordinates of two vectors (A/B).

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
avec3dividend vector
bvec3divisor vector

modeling/maths/vec3.dot(a, b)

Calculates the dot product of two vectors.

Kind: static method of modeling/maths/vec3
Returns: Number - dot product

ParamTypeDescription
avec3first operand
bvec3second operand

modeling/maths/vec3.equals(a, b)

Compare the given vectors for equality.

Kind: static method of modeling/maths/vec3
Returns: Boolean - true if a and b are equal

ParamTypeDescription
avec3first operand
bvec3second operand

modeling/maths/vec3.fromScalar(out, scalar)

Creates a vector from a single scalar value. All components of the resulting vector have the given value.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
scalarNumber

modeling/maths/vec3.fromValues(x, y, z)

Creates a new vector initialized with the given values.

Kind: static method of modeling/maths/vec3
Returns: vec3 - a new vector

ParamTypeDescription
xNumberX component
yNumberY component
zNumberZ component

modeling/maths/vec3.fromVec2(out, vector, [z])

Create a new vector by extending a 2D vector with a Z value.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDefaultDescription
outvec3receiving vector
vectorArray2D vector of values
[z]Number0Z value

modeling/maths/vec3.length(vector)

Calculates the length of a vector.

Kind: static method of modeling/maths/vec3
Returns: Number - length

ParamTypeDescription
vectorvec3vector to calculate length of

modeling/maths/vec3.lerp(out, a, b, t)

Performs a linear interpolation between two vectors.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
avec3first operand
bvec3second operand
tNumberinterpolant (0.0 to 1.0) applied between the two inputs

modeling/maths/vec3.max(out, a, b)

Returns the maximum coordinates of the given vectors.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
avec3first operand
bvec3second operand

modeling/maths/vec3.min(out, a, b)

Returns the minimum coordinates of the given vectors.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
avec3first operand
bvec3second operand

modeling/maths/vec3.multiply(out, a, b)

Multiply the coordinates of the given vectors (A*B).

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
avec3first operand
bvec3second operand

modeling/maths/vec3.negate(out, vector)

Negates the coordinates of the given vector.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector to negate

modeling/maths/vec3.normalize(out, vector)

Normalize the given vector.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector to normalize

modeling/maths/vec3.orthogonal(out, vector)

Create a new vector that is orthogonal to the given vector.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector of reference

modeling/maths/vec3.rotateX(out, vector, origin, radians)

Rotate the given vector around the given origin, X axis only.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector to rotate
originvec3origin of the rotation
radiansNumberangle of rotation

modeling/maths/vec3.rotateY(out, vector, origin, radians)

Rotate the given vector around the given origin, Y axis only.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector to rotate
originvec3origin of the rotation
radiansNumberangle of rotation

modeling/maths/vec3.rotateZ(out, vector, origin, radians)

Rotate the given vector around the given origin, Z axis only.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector to rotate
originvec3origin of the rotation
radiansNumberangle of rotation in radians

modeling/maths/vec3.scale(out, vector, amount)

Scales the coordinates of the given vector by a scalar number.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector to scale
amountNumberamount to scale the vector by

modeling/maths/vec3.snap(out, vector, epsilon)

Snaps the coordinates of the given vector to the given epsilon.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector to snap
epsilonNumberepsilon of precision, less than 0

modeling/maths/vec3.squaredDistance(a, b)

Calculates the squared distance between two vectors.

Kind: static method of modeling/maths/vec3
Returns: Number - squared distance

ParamTypeDescription
avec3first operand
bvec3second operand

modeling/maths/vec3.squaredLength(vector)

Calculates the squared length of the given vector.

Kind: static method of modeling/maths/vec3
Returns: Number - squared length

ParamTypeDescription
vectorvec3vector to calculate squared length of

modeling/maths/vec3.subtract(out, a, b)

Subtracts the coordinates of two vectors (A-B).

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
avec3minuend vector
bvec3subtrahend vector

modeling/maths/vec3.toString(vec)

Convert the given vector to a representative string.

Kind: static method of modeling/maths/vec3
Returns: String - string representation

ParamTypeDescription
vecvec3vector of reference

modeling/maths/vec3.transform(out, vector, matrix)

Transforms the given vector using the given matrix.

Kind: static method of modeling/maths/vec3
Returns: vec3 - out

ParamTypeDescription
outvec3receiving vector
vectorvec3vector to transform
matrixmat4transform matrix

modeling/maths/vec4

Represents a four dimensional vector.

See: vec4 for data structure information.

modeling/maths/vec4.clone(vector)

Create a clone of the given vector.

Kind: static method of modeling/maths/vec4
Returns: vec4 - a new vector

ParamTypeDescription
vectorvec4source vector

modeling/maths/vec4.copy(out, vector)

Create a copy of the given vector.

Kind: static method of modeling/maths/vec4
Returns: vec4 - out

ParamTypeDescription
outvec4receiving vector
vectorvec4source vector

modeling/maths/vec4.create()

Creates a new vector initialized to [0,0,0,0].

Kind: static method of modeling/maths/vec4
Returns: vec4 - a new vector

modeling/maths/vec4.dot(a, b)

Calculates the dot product of the given vectors.

Kind: static method of modeling/maths/vec4
Returns: Number - dot product

ParamTypeDescription
avec4first vector
bvec4second vector

modeling/maths/vec4.equals(a, b)

Compare the given vectors for equality.

Kind: static method of modeling/maths/vec4
Returns: Boolean - true if vectors are equal

ParamTypeDescription
avec4first vector
bvec4second vector

modeling/maths/vec4.fromScalar(out, scalar)

Create a new vector from the given scalar value.

Kind: static method of modeling/maths/vec4
Returns: vec4 - out

ParamTypeDescription
outvec4receiving vector
scalarNumber

modeling/maths/vec4.fromValues(x, y, z, w)

Creates a new vector with the given values.

Kind: static method of modeling/maths/vec4
Returns: vec4 - a new vector

ParamTypeDescription
xNumberX component
yNumberY component
zNumberZ component
wNumberW component

modeling/maths/vec4.toString(vec)

Convert the given vector to a representative string.

Kind: static method of modeling/maths/vec4
Returns: String - representative string

ParamTypeDescription
vecvec4vector to convert

modeling/maths/vec4.transform(out, vector, matrix)

Transform the given vector using the given matrix.

Kind: static method of modeling/maths/vec4
Returns: vec4 - out

ParamTypeDescription
outvec4receiving vector
vectorvec4vector to transform
matrixmat4matrix to transform with

TAU

The TAU property represents the ratio of the circumference of a circle to its radius. Approximately 6.28318530717958647692

Kind: global constant
Example

const { TAU } = require('@jscad/modeling').maths.constants

line2

Represents a unbounded line in 2D space, positioned at a point of origin. A line is parametrized by a normal vector (perpendicular to the line, rotated 90 degrees counter clockwise) and distance from the origin.

Equation: A Point (P) is on Line (L) if dot(L.normal, P) == L.distance

The contents of the array are a normal [0,1] and a distance 2.

Kind: global typedef

line3

Represents a unbounded line in 3D space, positioned at a point of origin. A line is parametrized by a point of origin and a directional vector.

The array contents are two 3D vectors; origin [0,0,0] and directional vector [0,0,1].

Kind: global typedef
See: https://en.wikipedia.org/wiki/Hesse_normal_form

mat4

Represents a 4x4 matrix which is column-major (when typed out it looks row-major). See fromValues().

Kind: global typedef

plane

Represents a plane in 3D coordinate space as determined by a normal (perpendicular to the plane) and distance from 0,0,0.

The contents of the array are a normal [0,1,2] and a distance 3.

Kind: global typedef
See: https://en.wikipedia.org/wiki/Hesse_normal_form

vec2

Represents a two dimensional vector. See fromValues().

Kind: global typedef

vec3

Represents a three dimensional vector. See fromValues().

Kind: global typedef

vec4

Represents a four dimensional vector. See fromValues().

Kind: global typedef