- spatialResolution
The resolution of space, currently one hundred nanometers. This should be 1 / EPS.
- EPS
Epsilon used during determination of near zero distances. This should be 1 / spacialResolution.
- color(color, objects) ⇒
Object
|Array
Apply the given color to the given objects.
- colorNameToRgb(String) ⇒
Converts a CSS color name to RGB color.
- hexToRgb(notation) ⇒
Array
Converts CSS color notations (string of hex values) to RGB values.
- hslToRgb(values) ⇒
Array
Converts HSL color values to RGB color values.
- hsvToRgb(values) ⇒
Array
Converts HSV color values to RGB color values.
- hueToColorComponent(p, q, t)
convert hue values to a color component (ie one of r, g, b)
- rgbToHex(values) ⇒
String
Convert the given RGB color values to CSS color notation (string)
- rgbToHsl(values) ⇒
Converts an RGB color value to HSL.
- rgbToHsv(values) ⇒
Converts an RGB color value to HSV.
- create()
Create a new connector. A connector allows two objects to be connected at predefined positions.
For example a servo motor and a servo horn can both have a connector called 'shaft'. The horn can be moved and rotated to any position, and then the servo horn is attached to the servo motor at the proper position, such that the two connectors match. Connectors are children of the solid, transform-wise, so transformations are applied to both solid and connector(s). (parent => child relationship)
- extend(distance, connector) ⇒
Connector
Creates a new Connector, with the connection point moved in the direction of the axis
- fromPointAxisNormal(point, axis, normal) ⇒
connector
Create a connector from the given point, axis and normal.
- normalize(connector) ⇒
Connector
Normalize the given connector, calculating new axis and normal
- toString(connector) ⇒
string
Return a string representing the given connector.
- transform(matrix, connector) ⇒
connector
Transform the give connector using the given matrix.
- transformationBetween(options, from, to) ⇒
mat4
Get the transformation matrix that connects the given connectors.
- applyTransforms(geometry) ⇒
geom2
Apply the transforms of the given geometry. NOTE: This function must be called BEFORE exposing any data. See toSides.
- clone() ⇒
geom2
Performs a deep clone of the given geometry.
- create([sides]) ⇒
geom2
Create a new 2D geometry composed of unordered sides (two connected points).
- fromPoints(points) ⇒
geom2
Create a new 2D geometry from the given points. The direction (rotation) of the points is not relevant, as the points can define a convex or a concave polygon. The geometry must not self intersect, i.e. the sides cannot cross.
- isA() ⇒
true
Determin if the given object is a 2D geometry.
- reverse(geometry) ⇒
geom2
Reverses the given geometry so that the sides are flipped and in the opposite order. This swaps the left (interior) and right (exterior) edges.
- toOutlines(geometry) ⇒
Array
Create the outline(s) of the given geometry.
- toPoints(geometry) ⇒
Array
Produces an array of points from the given geometry. NOTE: The points returned do NOT define an order. Use toOutlines() for ordered points.
- toSides(geometry) ⇒
Array
Produces an array of sides from the given geometry. The returned array should not be modified as the data is shared with the geometry.
- toString() ⇒
String
Create a string representing the contents of the given geometry.
- transform(matrix, geometry) ⇒
geom2
Transform the given geometry using the given matrix. This is a lazy transform of the sides, as this function only adjusts the transforms. The transforms are applied when accessing the sides via toSides().
- applyTransforms(geometry) ⇒
geom3
Apply the transforms of the given geometry. NOTE: This function must be called BEFORE exposing any data. See toPolygons.
- clone() ⇒
geom3
Performs a deep clone of the given geometry.
- create() ⇒
geom3
Create a new 3D geometry composed of polygons.
- fromPoints(listofpoints) ⇒
geom2
Construct a new 3D geometry from a list of points. The list of points should contain sub-arrays, each defining a single polygon of points. In addition, the points should follow the right-hand rule for rotation in order to define an external facing polygon. The opposite is true for internal facing polygon.
- isA() ⇒
true
Determin if the given object is a 3D geometry.
- toString() ⇒
String
Create a string representing the contents of the given geometry.
- transform(matrix, geometry) ⇒
geom3
Transform the given geometry using the given matrix. This is a lazy transform of the polygons, as this function only adjusts the transforms. See applyTransforms() for the actual application of the transforms to the polygons.
- appendArc(options, geometry) ⇒
path2
Append an arc to the end of the given geometry. This implementation follows the SVG arc specifications.
- appendBezier(options, geometry) ⇒
path2
Append a Bezier curve to the end of the given geometry, using the control points to transition the curve through start and end points.
The Bézier curve starts at the last point in the path, and ends at the last given control point. Other control points are intermediate control points.
The first control point may be null to ensure a smooth transition occurs. In this case, the second to last control point of the path is mirrored into the control points of the Bezier curve. In other words, the trailing gradient of the path matches the new gradient of the curve.- appendPoints(geometry) ⇒
path2
Append the given list of points to the end of the given geometry.
- applyTransforms(geometry) ⇒
path
Apply the transforms of the given geometry. NOTE: This function must be called BEFORE exposing any data. See toPoints.
- clone() ⇒
path2
Performs a deep clone of the give path.
- close() ⇒
path
Close the given geometry.
- concat(...paths) ⇒
path2
Produces a path by concatenating the given paths. A concatenation of zero paths is an empty, open path. A concatenation of one closed path to a series of open paths produces a closed path. A concatenation of a path to a closed path is an error.
- create() ⇒
path
Produces an empty, open path.
- eachPoint(path, thunk)
Calls a function for each point in the path in order.
- equals(a, b) ⇒
boolean
Determine if the given paths are equal. For closed paths, this includes equality under point order rotation.
- fromPoints(points) ⇒
path
Create a new path from the given points. The points must be provided an array of points, where each point is an array of two numbers.
- isA() ⇒
true
Determin if the given object is a path2 geometry.
- reverse(path) ⇒
path2
Reverses the path so that the points are in the opposite order. This swaps the left (interior) and right (exterior) edges. Reversal of path segments with options may be non-trivial.
- toPoints(geometry) ⇒
Array
Produces a new array containing the path's point data. The returned array should not be modified as the data is shared with the geometry.
- toString() ⇒
String
Create a string representing the contents of the given path.
- transform(matrix, geometry) ⇒
path2
A lazy transform of all of the points in the path.
- arePointsInside(points, polygon) ⇒
Integer
Determine if the given points are inside the given polygon.
- create([vertices]) ⇒
poly2
Creates a new poly2 (polygon) with initial values.
- flip(polygon) ⇒
poly2
Flip the give polygon to rotate the opposite direction.
- clone([out], poly3) ⇒
vec3
Create a deep clone of the given polygon
- create() ⇒
poly3
Creates a new poly3 (polygon) with initial values
- flip(polygon) ⇒
poly3
Flip the give polygon to face the opposite direction.
- fromPoints(points)
Create a polygon from the given points.
- fromPointsAndPlane(vertices, [plane])
- isA() ⇒
true
Determin if the given object is a poly3.
- isConvex() ⇒
boolean
Check whether the polygon is convex. (it should be, otherwise we will get unexpected results)
- measureBoundingSphere(the) ⇒
Measure the bounding sphere of the given poly3
- OrthoNormalBasis(plane, rightvector)
class OrthoNormalBasis Reprojects points on a 3D plane onto a 2D plane or from a 2D plane back onto the 3D plane
- clone([out], line) ⇒
line2
Create a clone of the given 2D line.
- closestPoint(point, line) ⇒
vec2
Determine the closest point on the given line to the given point. Thanks to @khrismuc
- create() ⇒
line2
Create a unbounded 2D line, positioned at 0,0, and running along the X axis.
- direction() ⇒
vec2
Return the direction of the given line.
- distanceToPoint(point, line) ⇒
Number
Calculate the distance (positive) between the given point and line
- doLinesIntersect(p0start, p0end, p1start, p1end)
- equals() ⇒
boolean
Compare the given 2D lines for equality
- fromPoints(p1, p2) ⇒
line2
Create a new 2D line that passes through the given points
- fromValues(x, y, w) ⇒
line2
Creates a new unbounded 2D line initialized with the given values.
- intersectToLine(line1, line2) ⇒
vec2
Return the point of intersection between the given lines.
The point will have Infinity values if the lines are paralell. The point will have NaN values if the lines are the same.
- origin(line) ⇒
vec2
Return the origin of the given line.
- reverse([out], line) ⇒
line2
Create a new line in the opposite direction as the given.
- toString(line) ⇒
string
Return a string representing the given line.
- transform([out], matrix, line) ⇒
line2
Transforms the given 2D line using the given matrix.
- xAtY(y, line) ⇒
Number
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.
- clone([out], line) ⇒
line3
Create a clone of the given 3D line.
- closestPoint(point, line) ⇒
vec3
Determine the closest point on the given line to the given point.
- create() ⇒
line3
Create an unbounded 3D line, positioned at 0,0,0 and lying on the X axis.
- direction() ⇒
vec3
Return the direction of the given line.
- distanceToPoint(point, line) ⇒
Number
Calculate the distance (positive) between the given point and line
- equals() ⇒
boolean
Compare the given 3D lines for equality
- fromPointAndDirection(point, direction) ⇒
line3
Create a line in 3D space from the given data.
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.
- fromPoints(p1, p2) ⇒
line3
Creates a new 3D line that passes through the given points.
- intersectToPlane(plane, line) ⇒
vec3
Determine the closest point on the given plane to the given line.
The point of intersection will be invalid if parallel to the plane, e.g. NaN.
- origin(line) ⇒
vec3
Return the origin of the given line.
- reverse([out], line) ⇒
line3
Create a new line in the opposite direction as the given.
- toString(line) ⇒
string
Return a string representing the given line.
- transform(matrix, line) ⇒
line3
Transforms the given 3D line using the given matrix.
- add(out, a, b) ⇒
mat4
Adds two mat4's
- clone([out], matrix) ⇒
mat4
Creates a clone of the given matrix
- create() ⇒
mat4
Creates a new identity mat4
- equals(a, b) ⇒
Boolean
Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
- fromRotation(out, rad, axis) ⇒
mat4
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);
- fromScaling(out, v) ⇒
mat4
Creates a matrix from a vector scaling This is equivalent to (but much faster than):
mat4.identity(dest); mat4.scale(dest, dest, vec);
- fromTaitBryanRotation(yaw, pitch, roll) ⇒
mat4
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.
- fromTranslation(out, v) ⇒
mat4
Creates a matrix from a vector translation This is equivalent to (but much faster than):
mat4.identity(dest); mat4.translate(dest, dest, vec);
- fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) ⇒
mat4
Create a new mat4 with the given values
- fromXRotation(out, rad) ⇒
mat4
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, rad);
- fromYRotation(out, rad) ⇒
mat4
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, rad);
- fromZRotation(out, rad) ⇒
mat4
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, rad);
- identity(out) ⇒
mat4
Set a mat4 to the identity matrix
- isMirroring(mat) ⇒
boolean
determine whether the input matrix is a mirroring transformation
- leftMultiplyVec2(vector, matrix) ⇒
vec2
Multiply the input matrix by a Vector2 (interpreted as 2 column, 1 row) (result = v*M) Fourth element is set to 1
- lefttMultiplyVec3(vector, matrix) ⇒
vec3
Multiply the input matrix by a Vector3 (interpreted as 3 column, 1 row) (result = v*M) Fourth element is set to 1
- mirror(out, v, a) ⇒
mat4
m the mat4 by the dimensions in the given vec3 create an affine matrix for mirroring into an arbitrary plane:
- mirrorByPlane([out], plane) ⇒
mat4
Create an affine matrix for mirroring onto an arbitrary plane
- multiply(out, a, b) ⇒
mat4
Multiplies two mat4's
- rightMultiplyVec2(vector, matrix) ⇒
vec2
Multiply the input matrix by a Vector2 (interpreted as 2 row, 1 column) (result = M*v) Fourth element is set to 1
- rightMultiplyVec3(vector, matrix) ⇒
vec3
Multiply the input matrix by a Vector3 (interpreted as 3 row, 1 column) (result = M*v) Fourth element is set to 1
- rotate(out, rad, axis, matrix) ⇒
mat4
Rotates a mat4 by the given angle
- rotateX(out, angle, matrix) ⇒
mat4
Rotates a matrix by the given angle around the X axis
- rotateY(out, angle, matrix) ⇒
mat4
Rotates a matrix by the given angle around the Y axis
- rotateZ(out, angle, matrix) ⇒
mat4
Rotates a matrix by the given angle around the Y axis
- scale(out, vector, matrix) ⇒
mat4
Scales the mat4 by the dimensions in the given vec3
- subtract(out, a, b) ⇒
mat4
Subtracts matrix b from matrix a
- translate(out, vector, matrix) ⇒
mat4
Translate matrix mat4 by the given vector
- equals() ⇒
boolean
Compare the given planes for equality
- flip([out], vec) ⇒
vec4
Flip the given plane (vec4)
- fromNormalAndPoint(normal, point-) ⇒
Array
Create a new plane from the given normal and point values
- fromObject()
Create a new plane from an untyped object with identical properties
- fromPoints(a, b, c) ⇒
Vec4
Create a new plane from the given points
- fromPointsRandom(a, b, c) ⇒
Vec4
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
- signedDistanceToPoint() ⇒
Number
Calculate the distance to the given point
- splitLineSegmentByPlane() ⇒
vec3
Split the given line by the given plane. Robust splitting, even if the line is parallel to the plane
- transform() ⇒
Array
Transform the given plane using the given matrix
- abs([out], vec) ⇒
vec2
Calculates the absolute value of the give vector
- add(out, a, b) ⇒
vec2
Adds two vec2's
- clone([out], vec) ⇒
vec2
Creates a new vec2 initialized with values from an existing vector
- create() ⇒
vec2
Creates a new, empty vec2
- cross(out, a, b) ⇒
vec3
Computes the cross product (3D) of two vectors
- distance(a, b) ⇒
Number
Calculates the euclidian distance between two vec2's
- divide(out, a, b) ⇒
vec2
Divides two vec2's
- dot(a, b) ⇒
Number
Calculates the dot product of two vec2's
- fromArray(data) ⇒
vec2
Creates a new vec2 initialized with the values in the given array any value at an index > 1 is ignored !
- fromScalar(scalar) ⇒
Vec2
Create a vec2 from a single scalar value
- fromValues(x, y) ⇒
vec2
Creates a new vec2 initialized with the given values
- fromVarious()
- length(a) ⇒
Number
Calculates the length of a vec2
- lerp(out, t, a, b) ⇒
vec2
Performs a linear interpolation between two vec2's
- max(out, a, b) ⇒
vec2
Returns the maximum of two vec2's
- min(out, a, b) ⇒
vec2
Returns the minimum of two vec2's
- multiply(out, a, b) ⇒
vec2
Multiplies two vec2's
- negate(out, a) ⇒
vec2
Negates the components of a vec2
- normal([out], vec) ⇒
vec2
Calculates the normal value of the give vector The normal value is the given vector rotated 90 degress.
- normalize(out, a) ⇒
vec2
Normalize the given vector.
- rotate(out, angle, vector) ⇒
vec2
Rotates a vec2 by an angle
- scale(out, amount, vector) ⇒
vec2
Scales a vec2 by a scalar number
- squaredDistance(a, b) ⇒
Number
Calculates the squared euclidian distance between two vec2's
- squaredLength(a) ⇒
Number
Calculates the squared length of a vec2
- subtract(out, a, b) ⇒
vec2
Subtracts vector b from vector a
- transform(out, matrix, vector) ⇒
vec2
Transforms the vec2 with a mat4 3rd vector component is implicitly '0' 4th vector component is implicitly '1'
- abs([out], vec) ⇒
vec3
Calculates the absolute value of the give vector
- add(out, a, b) ⇒
vec3
Adds two vec3's
- angle(a, b) ⇒
Number
Get the angle between two 3D vectors
- clone([out], vec) ⇒
vec3
Create a clone of the given vector
- create() ⇒
vec3
Creates a new, empty vec3
- cross(out, a, b) ⇒
vec3
Computes the cross product of two vec3's
- distance(a, b) ⇒
Number
Calculates the euclidian distance between two vec3's
- divide(out, a, b) ⇒
vec3
Divides two vec3's
- dot(a, b) ⇒
Number
Calculates the dot product of two vec3's
- fromArray(data) ⇒
vec3
Creates a new vec3 initialized with the values in the given array
- fromScalar(scalar) ⇒
Vec3
create a vec3 from a single scalar value all components of the resulting vec3 have the value of the input scalar
- fromValues(x, y, z) ⇒
vec3
Creates a new vec3 initialized with the given values
- fromVarious()
Represents a 3D vector with X, Y, Z coordinates.
- length(a) ⇒
Number
Calculates the length of a vec3
- lerp(out, t, a, b) ⇒
vec3
Performs a linear interpolation between two vec3's
- max(out, a, b) ⇒
vec3
Returns the maximum of two vec3's
- min(out, a, b) ⇒
vec3
Returns the minimum of two vec3's
- multiply(out, a, b) ⇒
vec3
Multiplies two vec3's
- negate(out, a) ⇒
vec3
Negates the components of a vec3
- normalize(out, a) ⇒
vec3
Normalize a vec3
- rotate(out, vector) ⇒
vec3
Rotate vector 3D vector around the all 3 axes in the order x-axis , yaxis, z axis
- rotateX(out, angle, origin, vector) ⇒
vec3
Rotate vector 3D vector around the x-axis
- rotateY(out, angle, origin, vector) ⇒
vec3
Rotate vector 3D vector around the y-axis
- rotateZ(out, angle, origin, vector) ⇒
vec3
Rotate vector 3D vector around the z-axis
- scale(out, amount, vector) ⇒
vec3
Scales a vec3 by a scalar number
- squaredDistance(a, b) ⇒
Number
Calculates the squared euclidian distance between two vec3's
- squaredLength(a) ⇒
Number
Calculates the squared length of a vec3
- subtract(out, a, b) ⇒
vec3
Subtracts vector b from vector a
- transform([params[0]], params[1, params[2) ⇒
vec3
Transforms the given vec3 with the given mat4. 4th vector component is implicitly '1'
- unit([out], vector) ⇒
vec3
Calculates the unit vector of the given vector
- clone([out], vector) ⇒
vec4
Create a clone of the given vector
- create() ⇒
vec4
Creates a new vec4 initialized to zero
- dot(a, b) ⇒
Number
Calculates the dot product of two vec4's
- fromScalar(scalar) ⇒
vec4
Create a new vec4 from the given scalar value (single)
- fromValues(x, y, z, w) ⇒
vec4
Creates a new vec4 initialized with the given values
- toString(a) ⇒
String
Convert the given vec4 to a representative string
- transform(out, matrix, vector) ⇒
vec4
Transform the given vec4 using the given mat4
- fromFakePolygons()
Convert the given polygons to a list of sides. The polygons must have only z coordinates +1 and -1, as constructed by to3DWalls().
- intersect(...geometries) ⇒
geom2
|geom3
Return a new geometry representing space in both the first geometry and all subsequent geometries. Note: None of the given geometries are modified.
- intersect(...geometries) ⇒
geom3
Return a new 3D geometry representing space in both the first geometry and in the subsequent geometries. None of the given geometries are modified.
- intersectGeom3Sub(geometry1, geometry2) ⇒
geom3
Return a new 3D geometry representing the space in both the first geometry and the second geometry. None of the given geometries are modified.
- mayOverlap(geometry1, geometry2) ⇒
boolean
Determine if the given geometries overlap by comparing min and max bounds. NOTE: This is used in union for performace gains.
- reTesselateCoplanarPolygons(sourcepolygons) ⇒
Array.<poly3>
Retesselation for a set of COPLANAR polygons.
- subtract(...geometries) ⇒
geom2
|geom3
Return a new geometry representing space in the first geometry but not in all subsequent geometries. Note: None of the given geometries are modified.
- subtract(...geometries) ⇒
geom3
Return a new 3D geometry representing space in this geometry but not in the given geometries. Neither this geometry nor the given geometries are modified.
- subtractGeom3Sub(geometry1, geometry2) ⇒
geom3
Return a new 3D geometry representing the space in the first geometry but not in the second geometry. None of the given geometries are modified.
- to3DWalls(options, geometry) ⇒
geom3
Create a 3D geometry with walls, as constructed from the given options and geometry.
- union(...geometries) ⇒
geom2
|geom3
Return a new geometry representing the total space in the given geometries. NOTE: None of the given geometries are modified.
- union(...geometries) ⇒
geom3
Return a new 3D geometry representing the space in the given 3D geometries.
- unionSub(geometry1, geometry2) ⇒
goem3
Return a new 3D geometry representing the space in the given geometries.
- expand(options, objects) ⇒
Object
|Array
Expand the given object(s) using the given options (if any)
- expandGeom2(options, geometry) ⇒
geom2
Expand the given geometry (geom2) using the given options (if any).
- expandGeom3(options, geometry) ⇒
geom3
Expand the given geometry (geom3) using the given options (if any).
- expandPath2(options, geometry) ⇒
geom2
Expand the given geometry (path2) using the given options (if any).
- expandShell(delta, segments)
Create the expanded shell of the solid: All faces are extruded to 2 times delta Cylinders are constructed around every side Spheres are placed on every vertex the result is a true expansion of the solid
- offset(options, objects) ⇒
Object
|Array
Create offset geometry(s) from the given object(s) using the given options (if any).
- offsetFromPoints(options, points) ⇒
Array
Create a set of offset points from the given points using the given options (if any).
- hull(...geometries) ⇒
geometry
Create a convex hull of the given geometries.
- hullChain(...geometries) ⇒
geometry
Create a chain of hulled geometries from the given gemetries. Essentially hull A+B, B+C, C+D, etc., then union the results.
- hullPoints2(uniquepoints) ⇒
Array
Create a convex hull of the given set of points, where each point is an array of [x,y].
- measureArea(...geometries) ⇒
Number
|Array.<Number>
Measure the area of the given geometry(s).
- measureBounds(...geometries) ⇒
Array.<Array>
Measure the min and max bounds of the given geometry(s), where min and max bounds are an array of [x,y,z]
- measureVolume(...geometries) ⇒
Number
|Array.<Number>
Measure the volume of the given geometry(s).
- center([options], geometries) ⇒
Object
|Array
Center the given object(s) using the given options (if any)
- mirror(options, objects) ⇒
Object
|Array
Mirror the given object(s) using the given options (if any) Note: The normal should be given as 90 degrees from the plane origin.
- rotate(angles, objects) ⇒
Object
|Array
Rotate the given object(s) using the given options (if any)
- scale(factors, objects) ⇒
Object
|Array
Scale the given object(s) using the given options (if any)
- transform(matrix, objects) ⇒
Object
|Array
Transform the given object(s) using the given matrix
- translate(offsets, objects) ⇒
Object
|Array
Translate the given object(s) using the given options (if any)
- arc(options) ⇒
path
Construct an arc.
- cuboid([options]) ⇒
geom3
Construct an axis-aligned solid cuboid.
- cube([options]) ⇒
geom3
Construct an axis-aligned solid cube with six square faces.
- cylinderElliptic([options]) ⇒
geom3
Construct an elliptic cylinder.
- cylinder([options]) ⇒
geom3
Construct a solid cylinder.
- ellipse([options]) ⇒
geom2
Construct an ellispe.
- circle([options]) ⇒
geom2
Construct a circle where are points are at the same distance from the center.
- ellipsoid([options]) ⇒
geom3
Construct an ellipsoid.
- sphere([options]) ⇒
geom3
Construct a sphere where are points are at the same distance from the center.
- geodesicSphere([options]) ⇒
geom3
Construct a geodesic sphere based on icosahedron symmetry.
- line(points) ⇒
path2
Create a new line (path) from the given points. The points must be provided as an array, where each element is an array of two numbers.
- polygon(options) ⇒
geom2
Construct a polygon from a list of points, or list of points and paths. NOTE: The ordering of points is VERY IMPORTANT.
- polyhedron(options) ⇒
geom3
Create a polyhedron from the given set of points and faces. The faces can define outward or inward facing polygons (orientation). However, each face must define a counter clockwise rotation of points which follows the right hand rule.
- rectangle([options]) ⇒
geom2
Construct an axis-aligned rectangle with four sides and four 90-degree angles.
- square([options]) ⇒
geom2
Construct an axis-aligned square with four equal sides and four 90-degree angles.
- roundedCuboid([options]) ⇒
geom3
Construct an axis-aligned solid rounded cuboid.
- roundedCylinder([options]) ⇒
geom3
Construct a cylinder with rounded ends.
- roundedRectangle([options]) ⇒
geom2
Construct a rounded rectangle.
- star([options])
Construct a star from the given options.
- torus([options]) ⇒
geom3
Construct a torus by revolving a small circle (inner) about the circumference of a large (outer) circle.
- vectorChar([options], [char]) ⇒
VectorCharObject
Construct a VectorCharObject from a ascii character whose code is between 31 and 127, if the character is not supported it is replaced by a question mark.
- vectorText([options], [text]) ⇒
Array
Construct an array of character segments from a ascii string whose characters code is between 31 and 127, if one character is not supported it is replaced by a question mark.
- VectorCharObject :
Object
Represents a character as segments
- VectorCharObject :
Object
Represents a character as segments
The resolution of space, currently one hundred nanometers. This should be 1 / EPS.
Kind: global constant
Default: 100000
Epsilon used during determination of near zero distances. This should be 1 / spacialResolution.
Kind: global constant
Default: 0.00001
Apply the given color to the given objects.
Kind: global function
Returns: Object
| Array
- the same objects with an additional attribute 'color'
Param | Type | Description |
---|---|---|
color | Array |
color values, where each value is between 0 and 1.0 |
objects | Object | Array |
the objects of which to color |
Example
let redSphere = color([1,0,0], sphere()) // red
let greenCircle = color([0,1,0], circle()) // green
let blueArc = color([0,0,1], arc()) // blue
Converts a CSS color name to RGB color.
Kind: global function
Returns: Array - the RGB color, or undefined if not found
Param | Description |
---|---|
String | s - the CSS color name |
Example
let mysphere = color(colorNameToRgb('lightblue'), sphere())
Converts CSS color notations (string of hex values) to RGB values.
Kind: global function
Returns: Array
- RGB color values
See: https://www.w3.org/TR/css-color-3/
Param | Type | Description |
---|---|---|
notation | String |
color notation |
Example
let mysphere = color(hexToRgb('#000080'), sphere()) // navy blue
Converts HSL color values to RGB color values.
Kind: global function
Returns: Array
- RGB color values
See: http://en.wikipedia.org/wiki/HSL_color_space.
Param | Type | Description |
---|---|---|
values | Array |
HSL color values |
Example
let mysphere = color(hslToRgb([0.9166666666666666, 1, 0.5]), sphere())
Converts HSV color values to RGB color values.
Kind: global function
Returns: Array
- RGB color values
See: http://en.wikipedia.org/wiki/HSV_color_space.
Param | Type | Description |
---|---|---|
values | Array |
HSV color values |
Example
let mysphere = color(hsvToRgb([0.9166666666666666, 1, 1]), sphere())
convert hue values to a color component (ie one of r, g, b)
Kind: global function
Param |
---|
p |
q |
t |
Convert the given RGB color values to CSS color notation (string)
Kind: global function
Returns: String
- CSS color notation
See: https://www.w3.org/TR/css-color-3/
Param | Type | Description |
---|---|---|
values | Array |
RGB color values |
Converts an RGB color value to HSL.
Kind: global function
Returns: Array HSL color values
See
- http://en.wikipedia.org/wiki/HSL_color_space.
- http://axonflux.com/handy-rgb-to-hsl-and-rgb-to-hsv-color-model-c
Param | Type | Description |
---|---|---|
values | Array |
RGB color values |
Converts an RGB color value to HSV.
Kind: global function
Returns: Array HSV color values
See: http://en.wikipedia.org/wiki/HSV_color_space.
Param | Type | Description |
---|---|---|
values | Array |
RGB color values |
Create a new connector. A connector allows two objects to be connected at predefined positions.
For example a servo motor and a servo horn can both have a connector called 'shaft'. The horn can be moved and rotated to any position, and then the servo horn is attached to the servo motor at the proper position, such that the two connectors match. Connectors are children of the solid, transform-wise, so transformations are applied to both solid and connector(s). (parent => child relationship)
Kind: global function
Properties
Name | Type | Description |
---|---|---|
point | vec3 |
the position of the connector (relative to its parent) |
axis | vec3 |
the direction (unit vector) of the connector |
normal | vec3 |
the direction (unit vector) perpendicular to axis, that defines the "12 o'clock" orientation of the connector |
Example
let myconnector = create()
Creates a new Connector, with the connection point moved in the direction of the axis
Kind: global function
Returns: Connector
- a normalized connector
Param | Type | Description |
---|---|---|
distance | Number |
the distance to extend the connector to |
connector | Connector |
the connector to extend |
Create a connector from the given point, axis and normal.
Kind: global function
Returns: connector
- a new connector
Param | Type | Description |
---|---|---|
point | vec3 |
the point of the connector, relative to the parent geometry |
axis | vec3 |
the axis (directional vector) of the connector |
normal | vec3 |
the normal (directional vector) of the connector, perpendicular to the axis |
Normalize the given connector, calculating new axis and normal
Kind: global function
Returns: Connector
- a new connector
Param | Type | Description |
---|---|---|
connector | Connector |
the connector to normalize |
Return a string representing the given connector.
Kind: global function
Returns: string
- string representation
Param | Type | Description |
---|---|---|
connector | connector |
the connector of reference |
Transform the give connector using the given matrix.
Kind: global function
Returns: connector
- a new connector
Param | Type | Description |
---|---|---|
matrix | mat4 |
a transform matrix |
connector | connector |
the connector to transform |
Get the transformation matrix that connects the given connectors.
Kind: global function
Returns: mat4
- - the matrix that transforms (connects) one connector to another
Param | Type | Default | Description |
---|---|---|---|
options | Object |
||
options.mirror | Boolean |
false |
the 'axis' vectors should point in the same direction true: the 'axis' vectors should point in opposite direction |
options.normalRotation | Number |
0 |
: the angle (RADIANS) of rotation between the 'normal' vectors |
from | connector |
connector from which to connect | |
to | connector |
connector to which to connected |
Apply the transforms of the given geometry. NOTE: This function must be called BEFORE exposing any data. See toSides.
Kind: global function
Returns: geom2
- the given geometry
Param | Type | Description |
---|---|---|
geometry | geom2 |
the geometry to transform |
Example
geometry = applyTransforms(geometry)
Performs a deep clone of the given geometry.
Kind: global function
Returns: geom2
- new geometry
Params: geom2
geometry - the geometry to clone
Create a new 2D geometry composed of unordered sides (two connected points).
Kind: global function
Returns: geom2
- a new empty geometry
Param | Type | Description |
---|---|---|
[sides] | Array |
list of sides where each side is an array of two points |
Create a new 2D geometry from the given points. The direction (rotation) of the points is not relevant, as the points can define a convex or a concave polygon. The geometry must not self intersect, i.e. the sides cannot cross.
Kind: global function
Returns: geom2
- a new geometry
Param | Type | Description |
---|---|---|
points | Array |
list of points in 2D space where each point is an array of two values |
Determin if the given object is a 2D geometry.
Kind: global function
Returns: true
- if the object matches a geom2 based object
Params: geom2
object - the object to interogate
Reverses the given geometry so that the sides are flipped and in the opposite order. This swaps the left (interior) and right (exterior) edges.
Kind: global function
Returns: geom2
- the new reversed geometry
Param | Type | Description |
---|---|---|
geometry | geom2 |
the geometry to reverse |
Example
let newgeometry = reverse(geometry)
Create the outline(s) of the given geometry.
Kind: global function
Returns: Array
- an array of outlines, where each outline is an array of ordered points
Param | Type |
---|---|
geometry | geom2 |
Example
let geometry = subtract(rectangle({size: [5, 5]}), rectangle({size: [3, 3]}))
let outlines = toOutlines(geometry) // returns two outlines
Produces an array of points from the given geometry. NOTE: The points returned do NOT define an order. Use toOutlines() for ordered points.
Kind: global function
Returns: Array
- an array of points, each point contains an array of two numbers
Param | Type | Description |
---|---|---|
geometry | geom2 |
the geometry |
Example
let sharedpoints = toPoints(geometry)
Produces an array of sides from the given geometry. The returned array should not be modified as the data is shared with the geometry.
Kind: global function
Returns: Array
- an array of sides, each side contains an array of two points
Param | Type | Description |
---|---|---|
geometry | geom2 |
the geometry |
Example
let sharedsides = toSides(geometry)
Create a string representing the contents of the given geometry.
Kind: global function
Returns: String
- a representive string
Example
console.out(toString(geometry))
Transform the given geometry using the given matrix. This is a lazy transform of the sides, as this function only adjusts the transforms. The transforms are applied when accessing the sides via toSides().
Kind: global function
Returns: geom2
- - the transformed geometry
Param | Type | Description |
---|---|---|
matrix | mat4 |
the matrix to transform with |
geometry | geom2 |
the geometry to transform |
Example
let newgeometry = transform(fromZRotation(degToRad(90)), geometry)
Apply the transforms of the given geometry. NOTE: This function must be called BEFORE exposing any data. See toPolygons.
Kind: global function
Returns: geom3
- the given geometry
Param | Type | Description |
---|---|---|
geometry | geom3 |
the geometry to transform |
Example
geometry = applyTransforms(geometry)
Performs a deep clone of the given geometry.
Kind: global function
Returns: geom3
- a new geometry
Params: geom3
geometry - the geometry to clone
Create a new 3D geometry composed of polygons.
Kind: global function
Returns: geom3
- - a new geometry
Construct a new 3D geometry from a list of points. The list of points should contain sub-arrays, each defining a single polygon of points. In addition, the points should follow the right-hand rule for rotation in order to define an external facing polygon. The opposite is true for internal facing polygon.
Kind: global function
Returns: geom2
- a new geometry
Param | Type | Description |
---|---|---|
listofpoints | Array.<Array> |
list of points in 3D space |
Determin if the given object is a 3D geometry.
Kind: global function
Returns: true
- if the object matches a geom3 based object
Params: object
object - the object to interogate
Create a string representing the contents of the given geometry.
Kind: global function
Returns: String
- a representive string
Example
console.out(toString(geometry))
Transform the given geometry using the given matrix. This is a lazy transform of the polygons, as this function only adjusts the transforms. See applyTransforms() for the actual application of the transforms to the polygons.
Kind: global function
Returns: geom3
- - the transformed geometry
Param | Type | Description |
---|---|---|
matrix | Matrix4x4 |
the matrix to transform with |
geometry | geom3 |
the geometry to transform |
Example
let newgeometry = transform(fromXRotation(degToRad(90)), geometry)
Append an arc to the end of the given geometry. This implementation follows the SVG arc specifications.
Kind: global function
Returns: path2
- new geometry with appended arc
See: http://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands
Param | Type | Default | Description |
---|---|---|---|
options | Object |
options for construction | |
options.endpoint | vec2 |
end point of arc REQUIRED | |
[options.radius] | vec2 |
[0,0] |
radius of arc (X and Y) |
[options.xaxisrotation] | Number |
0 |
rotation (RADIANS) of the X axis of the arc with respect to the X axis of the coordinate system |
[options.clockwise] | Boolean |
false |
draw an arc clockwise with respect to the center point |
[options.large] | Boolean |
false |
draw an arc longer than 180 degrees |
[options.segments] | Number |
16 |
number of segments per 360 rotation |
geometry | path2 |
the path of which to append the arc |
Example
let p1 = path2.fromPoints({}, [[27.5,-22.96875]]);
p1 = path2.appendPoints([[27.5,-3.28125]], p1);
p1 = path2.appendArc({endpoint: [12.5, -22.96875], radius: [15, -19.6875]}, p1);
Append a Bezier curve to the end of the given geometry, using the control points to transition the curve through start and end points.
The Bézier curve starts at the last point in the path,
and ends at the last given control point. Other control points are intermediate control points.
The first control point may be null to ensure a smooth transition occurs. In this case,
the second to last control point of the path is mirrored into the control points of the Bezier curve.
In other words, the trailing gradient of the path matches the new gradient of the curve.
Kind: global function
Returns: path2
- a new geometry with the appended curves
Param | Type | Default | Description |
---|---|---|---|
options | Object |
options for construction | |
options.controlPoints | Array.<vec2> |
list of control points for the bezier curve | |
[options.segment] | Number |
16 |
number of segments per 360 rotation |
geometry | path2 |
the path of which to append the curves |
Example
let p5 = path2.create({}, [[10,-20]])
p5 = path2.appendBezier({controlPoints: [[10,-10],[25,-10],[25,-20]]}, p5);
p5 = path2.appendBezier({controlPoints: [null, [25,-30],[40,-30],[40,-20]]}, p5)
Append the given list of points to the end of the given geometry.
Kind: global function
Returns: path2
- new path
Param | Type | Description |
---|---|---|
geometry | path2 |
the path to concatenate |
Example
let newpath = concat(fromPoints({}, [[1, 2]]), fromPoints({}, [[3, 4]]))
Apply the transforms of the given geometry. NOTE: This function must be called BEFORE exposing any data. See toPoints.
Kind: global function
Returns: path
- the given geometry
Param | Type | Description |
---|---|---|
geometry | path |
the geometry to transform |
Example
geometry = applyTransforms(geometry)
Performs a deep clone of the give path.
Kind: global function
Returns: path2
- new path
Params: path2
geometry - the geometry to clone
Close the given geometry.
Kind: global function
Returns: path
- the closed path
Params: geometry
the path to close
Produces a path by concatenating the given paths. A concatenation of zero paths is an empty, open path. A concatenation of one closed path to a series of open paths produces a closed path. A concatenation of a path to a closed path is an error.
Kind: global function
Returns: path2
- new path
Param | Type | Description |
---|---|---|
...paths | path |
the paths to concatenate |
Example
let newpath = concat(fromPoints({}, [[1, 2]]), fromPoints({}, [[3, 4]]))
Produces an empty, open path.
Kind: global function
Returns: path
- a new empty, open path
Example
let newpath = create()
Calls a function for each point in the path in order.
Kind: global function
Param | Type | Description |
---|---|---|
path | path2 |
the path to traverse |
thunk | function |
the function to call |
Example
eachPoint(path, accumulate)
Determine if the given paths are equal. For closed paths, this includes equality under point order rotation.
Kind: global function
Param | Type | Description |
---|---|---|
a | path |
the first path to compare |
b | path |
the second path to compare |
Create a new path from the given points. The points must be provided an array of points, where each point is an array of two numbers.
Kind: global function
Returns: path
- new path
Example:: my newpath = fromPoints({closed: true}, [[10, 10], [-10, 10]])
Param | Type | Description |
---|---|---|
points | Array |
array of points from which to create the path |
[options.closed] | boolean |
if the path should be open or closed |
Determin if the given object is a path2 geometry.
Kind: global function
Returns: true
- if the object matches a path2 object
Params: object
object - the object to interogate
Reverses the path so that the points are in the opposite order. This swaps the left (interior) and right (exterior) edges. Reversal of path segments with options may be non-trivial.
Kind: global function
Returns: path2
- the reversed path.
Param | Type | Description |
---|---|---|
path | path2 |
the path to reverse. |
Example
reverse(path)
Produces a new array containing the path's point data. The returned array should not be modified as the data is shared with the geometry.
Kind: global function
Returns: Array
- an array of points, each point contains an array of two numbers
Param | Type | Description |
---|---|---|
geometry | path2 |
the path |
Example
let sharedpoints = toPoints(path)
Create a string representing the contents of the given path.
Kind: global function
Returns: String
- a representive string
Example
console.out(toString(path))
A lazy transform of all of the points in the path.
Kind: global function
Returns: path2
- - the transformed path
Param | Type | Description |
---|---|---|
matrix | mat4 |
the matrix to transform with |
geometry | path2 |
the path to transform |
Example
transform(fromZRotation(degToRad(90)), path)
Determine if the given points are inside the given polygon.
Kind: global function
Returns: Integer
- 1 if all points are inside, 0 if some or none are inside
Param | Type | Description |
---|---|---|
points | Array |
a list of points, where each point is an array with X and Y values |
polygon | poly2 |
a 2D polygon |
Creates a new poly2 (polygon) with initial values.
Kind: global function
Returns: poly2
- a new poly2
Param | Type | Description |
---|---|---|
[vertices] | Array.<Array> |
list of vertices |
Example
let polygon = create()
Flip the give polygon to rotate the opposite direction.
Kind: global function
Returns: poly2
- a new poly2
Param | Type | Description |
---|---|---|
polygon | poly2 |
the polygon to flip |
Create a deep clone of the given polygon
Kind: global function
Returns: vec3
- clone of the polygon
Param | Type | Description |
---|---|---|
[out] | vec3 |
receiving polygon |
poly3 | vec3 |
polygon to clone |
Creates a new poly3 (polygon) with initial values
Kind: global function
Returns: poly3
- a new poly3
Flip the give polygon to face the opposite direction.
Kind: global function
Returns: poly3
- a new poly3
Param | Type | Description |
---|---|---|
polygon | poly3 |
the polygon to flip |
Create a polygon from the given points.
Kind: global function
Param | Type | Description |
---|---|---|
points | Array.<Array> |
list of points |
Example
const points = [
[0, 0, 0],
[0, 10, 0],
[0, 10, 10]
]
const polygon = fromPoints(points)
Kind: global function
Param | Type | Description |
---|---|---|
vertices | Array.<Array> |
list of vertices |
[plane] | plane |
plane of the polygon |
Determin if the given object is a poly3.
Kind: global function
Returns: true
- if the object matches a poly3 based object
Params: poly3
object - the object to interogate
Check whether the polygon is convex. (it should be, otherwise we will get unexpected results)
Measure the bounding sphere of the given poly3
Kind: global function
Returns: computed bounding sphere; center (vec3) and radius
Param | Type | Description |
---|---|---|
the | poly3 |
poly3 to measure |
class OrthoNormalBasis Reprojects points on a 3D plane onto a 2D plane or from a 2D plane back onto the 3D plane
Kind: global function
Param | Type |
---|---|
plane | Plane |
rightvector | Vector3D | Vector2D |
Create a clone of the given 2D line.
Kind: global function
Returns: line2
- clone of the line
Param | Type | Description |
---|---|---|
[out] | line2 |
receiving line |
line | line2 |
line to clone |
Determine the closest point on the given line to the given point. Thanks to @khrismuc
Kind: global function
Returns: vec2
- a new point
Param | Type | Description |
---|---|---|
point | vec2 |
the point of reference |
line | line2 |
the 2D line for calculations |
Create a unbounded 2D line, positioned at 0,0, and running along the X axis.
Kind: global function
Returns: line2
- a new unbounded 2D line
Return the direction of the given line.
Kind: global function
Returns: vec2
- a new relative vector in the direction of the line
Calculate the distance (positive) between the given point and line
Kind: global function
Returns: Number
- distance between line and point
Param | Type | Description |
---|---|---|
point | vec2 |
the point of reference |
line | line2 |
the 2D line of reference |
Kind: global function
Param | Type |
---|---|
p0start | vec |
p0end | vec |
p1start | vec |
p1end | vec |
Compare the given 2D lines for equality
Kind: global function
Returns: boolean
- true if lines are equal
Create a new 2D line that passes through the given points
Kind: global function
Returns: line2
- a new unbounded 2D line
Param | Type | Description |
---|---|---|
p1 | vec2 |
start point of the 2D line |
p2 | vec2 |
end point of the 2D line |
Creates a new unbounded 2D line initialized with the given values.
Kind: global function
Returns: line2
- a new unbounded 2D line
Param | Type | Description |
---|---|---|
x | Number |
X coordinate of the unit normal |
y | Number |
Y coordinate of the unit normal |
w | Number |
length (positive) of the normal segment |
Return the point of intersection between the given lines.
The point will have Infinity values if the lines are paralell. The point will have NaN values if the lines are the same.
Kind: global function
Returns: vec2
- the point of intersection
Param | Type | Description |
---|---|---|
line1 | line2 |
a 2D line for reference |
line2 | line2 |
a 2D line for reference |
Return the origin of the given line.
Kind: global function
Returns: vec2
- the origin of the line
Param | Type | Description |
---|---|---|
line | line2 |
the 2D line of reference |
Create a new line in the opposite direction as the given.
Kind: global function
Returns: line2
- a new unbounded 2D line
Param | Type | Description |
---|---|---|
[out] | line2 |
receiving line |
line | line2 |
the 2D line to reverse |
Return a string representing the given line.
Kind: global function
Returns: string
- string representation
Param | Type | Description |
---|---|---|
line | line2 |
the 2D line of reference |
Transforms the given 2D line using the given matrix.
Kind: global function
Returns: line2
- a new unbounded 2D line
Param | Type | Description |
---|---|---|
[out] | line2 |
receiving line |
matrix | mat4 |
matrix to transform with |
line | line2 |
the 2D line to transform |
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: global function
Returns: Number
- the X coordinate on the line
Param | Type | Description |
---|---|---|
y | Number |
the Y coordinate on the line |
line | line2 |
the 2D line of reference |
Create a clone of the given 3D line.
Kind: global function
Returns: line3
- clone of the line
Param | Type | Description |
---|---|---|
[out] | line3 |
receiving line |
line | line3 |
line to clone |
Determine the closest point on the given line to the given point.
Kind: global function
Returns: vec3
- a new point
Param | Type | Description |
---|---|---|
point | vec3 |
the point of reference |
line | line3 |
the 3D line for calculations |
Create an unbounded 3D line, positioned at 0,0,0 and lying on the X axis.
Kind: global function
Returns: line3
- a new unbounded 3D line
Return the direction of the given line.
Kind: global function
Returns: vec3
- the relative vector in the direction of the line
Calculate the distance (positive) between the given point and line
Kind: global function
Returns: Number
- distance between line and point
Param | Type | Description |
---|---|---|
point | vec3 |
the point of reference |
line | line3 |
the 3D line of reference |
Compare the given 3D lines for equality
Kind: global function
Returns: boolean
- true if lines are equal
Create a line in 3D space from the given data.
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: global function
Returns: line3
- a new unbounded 3D line
Param | Type | Description |
---|---|---|
point | vec3 |
start point of the line segment |
direction | vec3 |
direction of the line segment |
Creates a new 3D line that passes through the given points.
Kind: global function
Returns: line3
- a new unbounded 3D line
Param | Type | Description |
---|---|---|
p1 | vec3 |
start point of the line segment |
p2 | vec3 |
end point of the line segment |
Determine the closest point on the given plane to the given line.
The point of intersection will be invalid if parallel to the plane, e.g. NaN.
Kind: global function
Returns: vec3
- a new point
Param | Type | Description |
---|---|---|
plane | plane |
the plane of reference |
line | line3 |
the 3D line of reference |
Return the origin of the given line.
Kind: global function
Returns: vec3
- the origin of the line
Param | Type | Description |
---|---|---|
line | line3 |
the 3D line of reference |
Create a new line in the opposite direction as the given.
Kind: global function
Returns: line3
- a new unbounded 3D line
Param | Type | Description |
---|---|---|
[out] | line3 |
receiving line |
line | line3 |
the 3D line to reverse |
Return a string representing the given line.
Kind: global function
Returns: string
- string representation
Param | Type | Description |
---|---|---|
line | line3 |
the 3D line of reference |
Transforms the given 3D line using the given matrix.
Kind: global function
Returns: line3
- a new unbounded 3D line
Param | Type | Description |
---|---|---|
matrix | mat4 |
matrix to transform with |
line | line3 |
the 3D line to transform |
Adds two mat4's
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix |
a | mat4 |
the first operand |
b | mat4 |
the second operand |
Creates a clone of the given matrix
Kind: global function
Returns: mat4
- clone of the given matrix
Param | Type | Description |
---|---|---|
[out] | mat4 |
receiving matrix |
matrix | mat4 |
matrix to clone |
Creates a new identity mat4
Kind: global function
Returns: mat4
- a new 4x4 matrix
Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
Kind: global function
Returns: Boolean
- True if the matrices are equal, false otherwise.
Param | Type | Description |
---|---|---|
a | mat4 |
The first matrix. |
b | mat4 |
The second matrix. |
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: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
mat4 receiving operation result |
rad | Number |
the angle to rotate the matrix by |
axis | vec3 |
the axis to rotate around |
Creates a matrix from a vector scaling This is equivalent to (but much faster than):
mat4.identity(dest);
mat4.scale(dest, dest, vec);
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
mat4 receiving operation result |
v | vec3 |
Scaling vector |
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: global function
Returns: mat4
- a new matrix
See: https://en.wikipedia.org/wiki/Euler_angles
Param | Type | Description |
---|---|---|
yaw | Number |
Z rotation in radians |
pitch | Number |
Y rotation in radians |
roll | Number |
X rotation in radians |
Creates a matrix from a vector translation This is equivalent to (but much faster than):
mat4.identity(dest);
mat4.translate(dest, dest, vec);
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
mat4 receiving operation result |
v | vec3 |
Translation vector |
Create a new mat4 with the given values
Kind: global function
Returns: mat4
- A new mat4
Param | Type | Description |
---|---|---|
m00 | Number |
Component in column 0, row 0 position (index 0) |
m01 | Number |
Component in column 0, row 1 position (index 1) |
m02 | Number |
Component in column 0, row 2 position (index 2) |
m03 | Number |
Component in column 0, row 3 position (index 3) |
m10 | Number |
Component in column 1, row 0 position (index 4) |
m11 | Number |
Component in column 1, row 1 position (index 5) |
m12 | Number |
Component in column 1, row 2 position (index 6) |
m13 | Number |
Component in column 1, row 3 position (index 7) |
m20 | Number |
Component in column 2, row 0 position (index 8) |
m21 | Number |
Component in column 2, row 1 position (index 9) |
m22 | Number |
Component in column 2, row 2 position (index 10) |
m23 | Number |
Component in column 2, row 3 position (index 11) |
m30 | Number |
Component in column 3, row 0 position (index 12) |
m31 | Number |
Component in column 3, row 1 position (index 13) |
m32 | Number |
Component in column 3, row 2 position (index 14) |
m33 | Number |
Component in column 3, row 3 position (index 15) |
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, rad);
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
mat4 receiving operation result |
rad | Number |
the angle to rotate the matrix by |
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, rad);
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
mat4 receiving operation result |
rad | Number |
the angle to rotate the matrix by |
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, rad);
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
mat4 receiving operation result |
rad | Number |
the angle to rotate the matrix by |
Set a mat4 to the identity matrix
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix |
determine whether the input matrix is a mirroring transformation
Kind: global function
Returns: boolean
- output
Param | Type | Description |
---|---|---|
mat | mat4 |
the input matrix |
Multiply the input matrix by a Vector2 (interpreted as 2 column, 1 row) (result = v*M) Fourth element is set to 1
Kind: global function
Returns: vec2
- output
Param | Type | Description |
---|---|---|
vector | vec2 |
the input vector |
matrix | mat4 |
the input matrix |
Multiply the input matrix by a Vector3 (interpreted as 3 column, 1 row) (result = v*M) Fourth element is set to 1
Kind: global function
Returns: vec3
- output
Param | Type | Description |
---|---|---|
vector | vec3 |
the input vector |
matrix | mat4 |
the input matrix |
m the mat4 by the dimensions in the given vec3 create an affine matrix for mirroring into an arbitrary plane:
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix (optional) |
v | vec3 |
the vec3 to mirror the matrix by |
a | mat4 |
the matrix to mirror |
Create an affine matrix for mirroring onto an arbitrary plane
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
[out] | mat4 |
receiving matrix |
plane | vec4 |
to mirror the matrix by |
Multiplies two mat4's
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix |
a | mat4 |
the first operand |
b | mat4 |
the second operand |
Multiply the input matrix by a Vector2 (interpreted as 2 row, 1 column) (result = M*v) Fourth element is set to 1
Kind: global function
Returns: vec2
- output
Param | Type | Description |
---|---|---|
vector | vec2 |
the input vector |
matrix | mat4 |
the input matrix |
Multiply the input matrix by a Vector3 (interpreted as 3 row, 1 column) (result = M*v) Fourth element is set to 1
Kind: global function
Returns: vec3
- output
Param | Type | Description |
---|---|---|
vector | vec3 |
the input vector |
matrix | mat4 |
the input matrix |
Rotates a mat4 by the given angle
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix |
rad | Number |
the angle to rotate the matrix by |
axis | vec3 |
the axis to rotate around |
matrix | mat4 |
the matrix to rotate |
Rotates a matrix by the given angle around the X axis
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix |
angle | Number |
the angle to rotate the matrix by (in radian) |
matrix | mat4 |
the matrix to rotate |
Rotates a matrix by the given angle around the Y axis
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix |
angle | Number |
the angle to rotate the matrix by (in radian) |
matrix | mat4 |
the matrix to rotate |
Rotates a matrix by the given angle around the Y axis
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix |
angle | Number |
the angle to rotate the matrix by (in radian) |
matrix | mat4 |
the matrix to rotate |
Scales the mat4 by the dimensions in the given vec3
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix |
vector | vec3 |
the vec3 to scale the matrix by |
matrix | mat4 |
the matrix to scale |
Subtracts matrix b from matrix a
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix |
a | mat4 |
the first operand |
b | mat4 |
the second operand |
Translate matrix mat4 by the given vector
Kind: global function
Returns: mat4
- out
Param | Type | Description |
---|---|---|
out | mat4 |
the receiving matrix |
vector | vec3 |
vector to translate by |
matrix | mat4 |
the matrix to translate |
Compare the given planes for equality
Kind: global function
Returns: boolean
- true if planes are equal
Flip the given plane (vec4)
Kind: global function
Returns: vec4
- flipped plane
Param | Type | Description |
---|---|---|
[out] | vec4 |
receiving plane |
vec | vec4 |
plane to flip |
Create a new plane from the given normal and point values
Kind: global function
Returns: Array
- a new plane with properly typed values
Param | Type | Description |
---|---|---|
normal | Vec3 |
vector 3D |
point- | Vec3 |
vector 3D |
Create a new plane from an untyped object with identical properties
Create a new plane from the given points
Kind: global function
Returns: Vec4
- a new plane with properly typed values
Param | Type | Description |
---|---|---|
a | Vec3 |
3D point |
b | Vec3 |
3D point |
c | Vec3 |
3D point |
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: global function
Returns: Vec4
- a new plane with properly typed values
Param | Type | Description |
---|---|---|
a | Vec3 |
3D point |
b | Vec3 |
3D point |
c | Vec3 |
3D point |
Calculate the distance to the given point
Kind: global function
Returns: Number
- signed distance to point
Split the given line by the given plane. Robust splitting, even if the line is parallel to the plane
Kind: global function
Returns: vec3
- a new point
Transform the given plane using the given matrix
Kind: global function
Returns: Array
- a new plane with properly typed values
Calculates the absolute value of the give vector
Kind: global function
Returns: vec2
- absolute value of the vector
Param | Type | Description |
---|---|---|
[out] | vec2 |
receiving vector |
vec | vec2 |
given value |
Adds two vec2's
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector |
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Creates a new vec2 initialized with values from an existing vector
Kind: global function
Returns: vec2
- clone of the vector
Param | Type | Description |
---|---|---|
[out] | vec2 |
receiving vector |
vec | vec2 |
given vector to clone |
Creates a new, empty vec2
Kind: global function
Returns: vec2
- a new 2D vector
Computes the cross product (3D) of two vectors
Kind: global function
Returns: vec3
- cross product
Param | Type | Description |
---|---|---|
out | vec3 |
: the receiving vec3 (IMPORTANT) |
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Calculates the euclidian distance between two vec2's
Kind: global function
Returns: Number
- distance between a and b
Param | Type | Description |
---|---|---|
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Divides two vec2's
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector |
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Calculates the dot product of two vec2's
Kind: global function
Returns: Number
- dot product of a and b
Param | Type | Description |
---|---|---|
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Creates a new vec2 initialized with the values in the given array any value at an index > 1 is ignored !
Kind: global function
Returns: vec2
- a new 2D vector
Param | Type | Description |
---|---|---|
data | Array |
array of numerical values |
Create a vec2 from a single scalar value
Kind: global function
Returns: Vec2
- a new vec2
Param | Type |
---|---|
scalar | Float |
Creates a new vec2 initialized with the given values
Kind: global function
Returns: vec2
- a new 2D vector
Param | Type | Description |
---|---|---|
x | Number |
X component |
y | Number |
Y component |
Kind: global function
Example
new CSG.Vector2D(1, 2);
new CSG.Vector2D([1, 2]);
new CSG.Vector2D({ x: 1, y: 2});
Calculates the length of a vec2
Kind: global function
Returns: Number
- length of a
Param | Type | Description |
---|---|---|
a | vec2 |
vector to calculate length of |
Performs a linear interpolation between two vec2's
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector |
t | Number |
interpolation amount between the two inputs |
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Returns the maximum of two vec2's
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector (optional) |
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Returns the minimum of two vec2's
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector (optional) |
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Multiplies two vec2's
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector |
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Negates the components of a vec2
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector (optional) |
a | vec2 |
vector to negate |
Calculates the normal value of the give vector The normal value is the given vector rotated 90 degress.
Kind: global function
Returns: vec2
- normal value of the vector
Param | Type | Description |
---|---|---|
[out] | vec2 |
receiving vector |
vec | vec2 |
given value |
Normalize the given vector.
Kind: global function
Returns: vec2
- normalized (unit) vector
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector |
a | vec2 |
vector to normalize |
Rotates a vec2 by an angle
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector |
angle | Number |
the angle of rotation (in radians) |
vector | vec2 |
the vector to rotate |
Scales a vec2 by a scalar number
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector |
amount | Number |
amount to scale the vector by |
vector | vec2 |
the vector to scale |
Calculates the squared euclidian distance between two vec2's
Kind: global function
Returns: Number
- squared distance between a and b
Param | Type | Description |
---|---|---|
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Calculates the squared length of a vec2
Kind: global function
Returns: Number
- squared length of a
Param | Type | Description |
---|---|---|
a | vec2 |
vector to calculate squared length of |
Subtracts vector b from vector a
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector |
a | vec2 |
the first operand |
b | vec2 |
the second operand |
Transforms the vec2 with a mat4 3rd vector component is implicitly '0' 4th vector component is implicitly '1'
Kind: global function
Returns: vec2
- out
Param | Type | Description |
---|---|---|
out | vec2 |
the receiving vector |
matrix | mat4 |
matrix to transform with |
vector | vec2 |
the vector to transform |
Calculates the absolute value of the give vector
Kind: global function
Returns: vec3
- absolute value of the vector
Param | Type | Description |
---|---|---|
[out] | vec3 |
receiving vector |
vec | vec3 |
given value |
Adds two vec3's
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector |
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Get the angle between two 3D vectors
Kind: global function
Returns: Number
- The angle in radians
Param | Type | Description |
---|---|---|
a | vec3 |
The first operand |
b | vec3 |
The second operand |
Create a clone of the given vector
Kind: global function
Returns: vec3
- clone of the vector
Param | Type | Description |
---|---|---|
[out] | vec3 |
receiving vector |
vec | vec3 |
vector to clone |
Creates a new, empty vec3
Kind: global function
Returns: vec3
- a new 3D vector
Computes the cross product of two vec3's
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector |
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Calculates the euclidian distance between two vec3's
Kind: global function
Returns: Number
- distance between a and b
Param | Type | Description |
---|---|---|
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Divides two vec3's
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector |
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Calculates the dot product of two vec3's
Kind: global function
Returns: Number
- dot product of a and b
Param | Type | Description |
---|---|---|
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Creates a new vec3 initialized with the values in the given array
Kind: global function
Returns: vec3
- a new 3D vector
Param | Type | Description |
---|---|---|
data | Array |
array of numerical values |
create a vec3 from a single scalar value all components of the resulting vec3 have the value of the input scalar
Kind: global function
Param | Type |
---|---|
scalar | Float |
Creates a new vec3 initialized with the given values
Kind: global function
Returns: vec3
- a new 3D vector
Param | Type | Description |
---|---|---|
x | Number |
X component |
y | Number |
Y component |
z | Number |
Z component |
Represents a 3D vector with X, Y, Z coordinates.
Kind: global function
Example
fromVarious(1, 2, 3);
fromVarious([1, 2, 3]);
fromVarious({ x: 1, y: 2, z: 3 });
fromVarious(1, 2); // assumes z=0
fromVarious([1, 2]); // assumes z=0
Calculates the length of a vec3
Kind: global function
Returns: Number
- length of a
Param | Type | Description |
---|---|---|
a | vec3 |
vector to calculate length of |
Performs a linear interpolation between two vec3's
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector |
t | Number |
interpolant (0.0 to 1.0) applied between the two inputs |
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Returns the maximum of two vec3's
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector (optional) |
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Returns the minimum of two vec3's
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector (optional) |
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Multiplies two vec3's
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector |
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Negates the components of a vec3
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector (optional) |
a | vec3 |
vector to negate |
Normalize a vec3
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector (optional) |
a | vec3 |
vector to normalize |
Rotate vector 3D vector around the all 3 axes in the order x-axis , yaxis, z axis
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
The receiving vec3 (optional) |
vector | vec3 |
The vec3 point to rotate |
Rotate vector 3D vector around the x-axis
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
The receiving vec3 (optional) |
angle | Number |
The angle of rotation |
origin | vec3 |
The origin of the rotation |
vector | vec3 |
The vec3 point to rotate |
Rotate vector 3D vector around the y-axis
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
The receiving vec3 (optional) |
angle | Number |
The angle of rotation |
origin | vec3 |
The origin of the rotation |
vector | vec3 |
The vec3 point to rotate |
Rotate vector 3D vector around the z-axis
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
The receiving vec3 (optional) |
angle | Number |
The angle of rotation in radians |
origin | vec3 |
The origin of the rotation |
vector | vec3 |
The vec3 point to rotate |
Scales a vec3 by a scalar number
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector |
amount | Number |
amount to scale the vector by |
vector | vec3 |
the vector to scale |
Calculates the squared euclidian distance between two vec3's
Kind: global function
Returns: Number
- squared distance between a and b
Param | Type | Description |
---|---|---|
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Calculates the squared length of a vec3
Kind: global function
Returns: Number
- squared length of a
Param | Type | Description |
---|---|---|
a | vec3 |
vector to calculate squared length of |
Subtracts vector b from vector a
Kind: global function
Returns: vec3
- out
Param | Type | Description |
---|---|---|
out | vec3 |
the receiving vector |
a | vec3 |
the first operand |
b | vec3 |
the second operand |
Transforms the given vec3 with the given mat4. 4th vector component is implicitly '1'
Kind: global function
Returns: vec3
- the transformed vector
Param | Type | Description |
---|---|---|
[params[0]] | vec3 |
the receiving vector (optional) |
params[1 | mat4 |
the transform matrix |
params[2 | vec3 |
the vector to transform |
Calculates the unit vector of the given vector
Kind: global function
Returns: vec3
- unit vector of the given vector
Param | Type | Description |
---|---|---|
[out] | vec3 |
the optional receiving vector |
vector | vec3 |
the base vector for calculations |
Create a clone of the given vector
Kind: global function
Returns: vec4
- clone of vector
Param | Type | Description |
---|---|---|
[out] | vec4 |
receiving vector |
vector | vec4 |
vector to clone |
Creates a new vec4 initialized to zero
Kind: global function
Returns: vec4
- a new vector
Calculates the dot product of two vec4's
Kind: global function
Returns: Number
- dot product of a and b
Param | Type | Description |
---|---|---|
a | vec4 |
the first vec4 |
b | vec4 |
the second vec4 |
Create a new vec4 from the given scalar value (single)
Kind: global function
Returns: vec4
- a new vector
Param | Type |
---|---|
scalar | Number |
Creates a new vec4 initialized with the given values
Kind: global function
Returns: vec4
- a new vector
Param | Type | Description |
---|---|---|
x | Number |
X component |
y | Number |
Y component |
z | Number |
Z component |
w | Number |
W component |
Convert the given vec4 to a representative string
Kind: global function
Returns: String
- representative string
Param | Type | Description |
---|---|---|
a | vec4 |
vector to convert |
Transform the given vec4 using the given mat4
Kind: global function
Returns: vec4
- a new vector or the receiving vector
Param | Type | Description |
---|---|---|
out | vec4 |
the receiving vector (optional) |
matrix | mat4 |
matrix to transform with |
vector | vec4 |
the vector to transform |
Convert the given polygons to a list of sides. The polygons must have only z coordinates +1 and -1, as constructed by to3DWalls().
Return a new geometry representing space in both the first geometry and all subsequent geometries. Note: None of the given geometries are modified.
Kind: global function
Returns: geom2
| geom3
- a new geometry
Param | Type | Description |
---|---|---|
...geometries | geometries |
list of geometries |
Example
let myshape = intersect(cube({size: [5,5,5]}), cube({size: [5,5,5], center: [5,5,5]}))
Example
+-------+
| |
| A |
| +--+----+ = +--+
+----+--+ | +--+
| B |
| |
+-------+
Return a new 3D geometry representing space in both the first geometry and in the subsequent geometries. None of the given geometries are modified.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Description |
---|---|---|
...geometries | geom3 |
list of 3D geometries |
Return a new 3D geometry representing the space in both the first geometry and the second geometry. None of the given geometries are modified.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Description |
---|---|---|
geometry1 | geom3 |
a geometry |
geometry2 | geom3 |
a geometry |
Determine if the given geometries overlap by comparing min and max bounds. NOTE: This is used in union for performace gains.
Kind: global function
Returns: boolean
- true if the geometries overlap
Param | Type | Description |
---|---|---|
geometry1 | geom3 |
geometry for comparision |
geometry2 | geom3 |
geometry for comparision |
Retesselation for a set of COPLANAR polygons.
Kind: global function
Returns: Array.<poly3>
- new set of polygons
Param | Type | Description |
---|---|---|
sourcepolygons | Array.<poly3> |
list of polygons |
Return a new geometry representing space in the first geometry but not in all subsequent geometries. Note: None of the given geometries are modified.
Kind: global function
Returns: geom2
| geom3
- a new geometry
Param | Type | Description |
---|---|---|
...geometries | geometries |
list of geometries |
Example
let myshape = subtract(cubiod({size: [5,5,5]}), cubiod({size: [5,5,5], center: [5,5,5]}))
Example
+-------+ +-------+
| | | |
| A | | |
| +--+----+ = | +--+
+----+--+ | +----+
| B |
| |
+-------+
Return a new 3D geometry representing space in this geometry but not in the given geometries. Neither this geometry nor the given geometries are modified.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Description |
---|---|---|
...geometries | geom3 |
list of geometries |
Return a new 3D geometry representing the space in the first geometry but not in the second geometry. None of the given geometries are modified.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Description |
---|---|---|
geometry1 | geom3 |
a geometry |
geometry2 | geom3 |
a geometry |
Create a 3D geometry with walls, as constructed from the given options and geometry.
Kind: global function
Returns: geom3
- the new geometry
Param | Type | Description |
---|---|---|
options | Object |
options with Z offsets |
geometry | geom2 |
geometry used as base of walls |
Return a new geometry representing the total space in the given geometries. NOTE: None of the given geometries are modified.
Kind: global function
Returns: geom2
| geom3
- a new geometry
Param | Type | Description |
---|---|---|
...geometries | geometry |
list of geometries to union |
Example
let myshape = union(cube({size: [5,5,5]}), cube({size: [5,5,5], center: [5,5,5]}))
Example
+-------+ +-------+
| | | |
| A | | |
| +--+----+ = | +----+
+----+--+ | +----+ |
| B | | |
| | | |
+-------+ +-------+
Return a new 3D geometry representing the space in the given 3D geometries.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Description |
---|---|---|
...geometries | objects |
list of geometries to union |
Return a new 3D geometry representing the space in the given geometries.
Kind: global function
Returns: goem3
- new 3D geometry
Param | Type | Description |
---|---|---|
geometry1 | geom3 |
geometry to union |
geometry2 | geom3 |
geometry to union |
Expand the given object(s) using the given options (if any)
Kind: global function
Returns: Object
| Array
- the expanded object(s)
Param | Type | Default | Description |
---|---|---|---|
options | Object |
options for expand | |
[options.delta] | Number |
1 |
delta (+/-) of expansion |
[options.corners] | String |
'edge' |
type corner to create during of expansion; edge, chamfer, round |
[options.segments] | Integer |
number of segments when creating rounded corners | |
objects | Object | Array |
the object(s) to expand |
Example
let newsphere = expand({delta: 2}, cube({center: [0,0,15], size: [20, 25, 5]}))
Expand the given geometry (geom2) using the given options (if any).
Kind: global function
Returns: geom2
- expanded geometry
Param | Type | Default | Description |
---|---|---|---|
options | Object |
options for expand | |
[options.delta] | Number |
1 |
delta (+/-) of expansion |
[options.corners] | String |
'edge' |
type corner to create during of expansion; edge, chamfer, round |
[options.segments] | Integer |
16 |
number of segments when creating round corners |
geometry | geom2 |
the geometry to expand |
Expand the given geometry (geom3) using the given options (if any).
Kind: global function
Returns: geom3
- expanded geometry
Param | Type | Default | Description |
---|---|---|---|
options | Object |
options for expand | |
[options.delta] | Number |
1 |
delta (+/-) of expansion |
[options.corners] | String |
'round' |
type corner to create during of expansion; round |
[options.segments] | Integer |
12 |
number of segments when creating round corners |
geometry | geom3 |
the geometry to expand |
Expand the given geometry (path2) using the given options (if any).
Kind: global function
Returns: geom2
- expanded geometry
Param | Type | Default | Description |
---|---|---|---|
options | Object |
options for expand | |
[options.delta] | Number |
1 |
delta (+) of expansion |
[options.corners] | String |
'edge' |
type corner to create during of expansion; edge, chamfer, round |
[options.segments] | Integer |
16 |
number of segments when creating round corners |
geometry | path2 |
the geometry to expand |
Create the expanded shell of the solid: All faces are extruded to 2 times delta Cylinders are constructed around every side Spheres are placed on every vertex the result is a true expansion of the solid
Kind: global function
Param | Type |
---|---|
delta | Number |
segments | Integer |
Create offset geometry(s) from the given object(s) using the given options (if any).
Kind: global function
Returns: Object
| Array
- the offset objects(s)
Param | Type | Default | Description |
---|---|---|---|
options | Object |
options for offset | |
[options.delta] | Float |
1 |
delta of offset (+ to exterior, - from interior) |
[options.corners] | String |
'edge' |
type corner to create during of expansion; edge, chamfer, round |
[options.segments] | Integer |
16 |
number of segments when creating round corners |
objects | Object | Array |
object(s) to offset |
Create a set of offset points from the given points using the given options (if any).
Kind: global function
Returns: Array
- new set of offset points, plus points for each rounded corner
Param | Type | Default | Description |
---|---|---|---|
options | Object |
options for offset | |
[options.delta] | Float |
1 |
delta of offset (+ to exterior, - from interior) |
[options.corners] | String |
'edge' |
type corner to create during of expansion; edge, chamfer, round |
[options.segments] | Integer |
16 |
number of segments when creating round corners |
points | Array |
array of 2D points |
Create a convex hull of the given geometries.
Kind: global function
Returns: geometry
- new geometry
Example:: let myshape = hull(rectangle({center: [-5,-5]}), ellipse({center: [5,5]}))
Param | Type | Description |
---|---|---|
...geometries | geometries |
list of geometries from which to create a hull |
Example
+-------+ +-------+
| | | \
| A | | \
| | | \
+-------+ + \
= \ \
+-------+ \ +
| | \ |
| B | \ |
| | \ |
+-------+ +-------+
Create a chain of hulled geometries from the given gemetries. Essentially hull A+B, B+C, C+D, etc., then union the results.
Kind: global function
Returns: geometry
- new geometry
Example:: let newshape = hullChain(rectangle({center: [-5,-5]}), circle({center: [0,0]}), rectangle({center: [5,5]}))
Param | Type | Description |
---|---|---|
...geometries | geometries |
list of geometries from which to create hulls |
Create a convex hull of the given set of points, where each point is an array of [x,y].
Kind: global function
Returns: Array
- a list of points that form the hull
Param | Type | Description |
---|---|---|
uniquepoints | Array |
list of UNIQUE points from which to create a hull |
Measure the area of the given geometry(s).
Kind: global function
Returns: Number
| Array.<Number>
- the area for each geometry
Param | Type | Description |
---|---|---|
...geometries | geometries |
the geometry(s) to measure |
Example
let area = measureArea(sphere())
Measure the min and max bounds of the given geometry(s), where min and max bounds are an array of [x,y,z]
Kind: global function
Returns: Array.<Array>
- the min and max bounds for each geometry
Param | Type | Description |
---|---|---|
...geometries | geometries |
the geometry(s) to measure |
Example
let bounds = measureBounds(sphere())
Measure the volume of the given geometry(s).
Kind: global function
Returns: Number
| Array.<Number>
- the volume for each geometry
Param | Type | Description |
---|---|---|
...geometries | geometries |
the geometry(s) to measure |
Example
let volume = measureVolume(sphere())
Center the given object(s) using the given options (if any)
Kind: global function
Returns: Object
| Array
- the centered geometries
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for centering | |
[options.axes] | Array |
[true,true,true] |
axis of which to center, true or false |
[options.center] | Array |
[0,0,0] |
point of which to center the object upon |
geometries | Object | Array |
the geometries to center |
Example
let myshape = center({axes: [true,false,false]}, sphere()) // center about the X axis
Mirror the given object(s) using the given options (if any) Note: The normal should be given as 90 degrees from the plane origin.
Kind: global function
Returns: Object
| Array
- the mirrored object(s)
Param | Type | Default | Description |
---|---|---|---|
options | Object |
options for mirror | |
options.origin | Array |
[0,0,0 |
the origin of the plane |
options.normal | Array |
[0,0,1 |
the normal vector of the plane |
objects | Object | Array |
the objects(s) to mirror |
Example
const newsphere = mirror({normal: [0,0,10]}, cube({center: [0,0,15], radius: [20, 25, 5]}))
Rotate the given object(s) using the given options (if any)
Kind: global function
Returns: Object
| Array
- the rotated object(s)
Param | Type | Description |
---|---|---|
angles | Array.<Number> |
angle (RADIANS) of rotations about X, Y, and X axis |
objects | Object | Array |
the objects(s) to rotate |
Example
const newsphere = rotate([45,0,0], sphere())
Scale the given object(s) using the given options (if any)
Kind: global function
Returns: Object
| Array
- the scaled object(s)
Param | Type | Description |
---|---|---|
factors | Array |
factors by which to scale the object |
objects | Object | Array |
the objects(s) to scale |
Example
const newsphere = scale([5, 0, 10], sphere())
Transform the given object(s) using the given matrix
Kind: global function
Returns: Object
| Array
- the transform object(s)
Param | Type | Description |
---|---|---|
matrix | Matrix4x4 |
a transformation matrix, see Matrix4x4 |
objects | Object | Array |
the objects(s) to transform |
Example
const newsphere = transform(Matrix4x4.rotateX(45), sphere())
Translate the given object(s) using the given options (if any)
Kind: global function
Returns: Object
| Array
- the translated object(s)
Param | Type | Description |
---|---|---|
offsets | Array |
offsets of which to translate the object |
objects | Object | Array |
the objects(s) to translate |
Example
const newsphere = translate({offsets: [5, 0, 10]}, sphere())
Construct an arc.
Kind: global function
Returns: path
- new path (not closed)
Param | Type | Description |
---|---|---|
options | Object |
options for construction |
options.center | Array |
center of arc |
options.radius | Number |
radius of arc |
options.startAngle | Number |
starting angle of the arc, in radians |
options.endAngle | Number |
ending angle of the arc, in radians |
options.segments | Number |
number of segments to create per 360 rotation |
options.makeTangent | Boolean |
adds line segments at both ends of the arc to ensure that the gradients at the edges are tangent |
Construct an axis-aligned solid cuboid.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Array |
[0,0,0] |
center of cuboid |
[options.size] | Array |
[1,1,1] |
size of cuboid |
Example
let myshape = cuboid({center: [5, 5, 5], size: [5, 10, 5]})
Construct an axis-aligned solid cube with six square faces.
Kind: global function
Returns: geom3
- new 3D geometry
See: cuboid for more options, as this is an alias to cuboid
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Array |
[0,0,0] |
center of cube |
options.size | Number |
1 |
size of cube |
Example
let mycube = cube({center: [5, 5, 5], size: 5})
Construct an elliptic cylinder.
Kind: global function
Returns: geom3
- new geometry
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.height] | Vector3 |
2 |
height of cylinder |
[options.startRadius] | Vector2D |
[1,1] |
radius of rounded start, must be two dimensional array |
[options.startAngle] | Number |
0 |
start angle of cylinder, in radians |
[options.endRadius] | Vector2D |
[1,1] |
radius of rounded end, must be two dimensional array |
[options.endAngle] | Number |
(Math.PI * 2) |
end angle of cylinder, in radians |
[options.segments] | Number |
12 |
number of segments to create per full rotation |
Example
let cylinder = cylinderElliptic({
height: 2,
startRadius: [10,5],
endRadius: [8,3]
});
Construct a solid cylinder.
Kind: global function
Returns: geom3
- new geometry
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.height] | Array |
2 |
height of cylinder |
[options.startRadisu] | Number |
1 |
radius of cylinder at the start |
[options.startAngle] | Number |
0 |
start angle of cylinder |
[options.endRadius] | Number |
1 |
radius of cylinder at the end |
[options.endAngle] | Number |
(Math.PI * 2) |
end angle of cylinder |
[options.segments] | Number |
12 |
number of segments to create per full rotation |
Example
let cylinder = cylinder({
height: 2,
startRadis: 10,
endRadis: 5,
segments: 16
})
Construct an ellispe.
Kind: global function
Returns: geom2
- new 2D geometry
See: https://en.wikipedia.org/wiki/Ellipse
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Array |
[0,0] |
center of ellipse |
[options.radius] | Array |
[1,1] |
radius of ellipse, along X and Y |
[options.segments] | Number |
16 |
number of segments to create per 360 rotation |
Construct a circle where are points are at the same distance from the center.
Kind: global function
Returns: geom2
- new 2D geometry
See: ellipse for additional options, as this is an alias for ellipse
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Array |
[0,0] |
center of circle |
[options.radius] | Number |
1 |
radius of circle |
[options.segments] | Number |
16 |
number of segments to create per 360 rotation |
Construct an ellipsoid.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Array |
[0,0,0] |
center of ellipsoid |
[options.radius] | Array |
[1,1,1] |
radius of ellipsoid, along X, Y and Z |
[options.segments] | Number |
12 |
number of segements to create per 360 rotation |
[options.axes] | Array |
an array with three vectors for the x, y and z base vectors |
Example
let myshape = ellipsoid({center: [5, 5, 5], radius: [5, 10, 20]})
Construct a sphere where are points are at the same distance from the center.
Kind: global function
Returns: geom3
- new 3D geometry
See: ellipsoid for additional options, as this is an alias for ellipsoid
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Array |
[0,0,0] |
center of sphere |
[options.radius] | Number |
1 |
radius of sphere |
[options.segments] | Number |
12 |
number of segments to create per 360 rotation |
[options.axes] | Array |
an array with three vectors for the x, y and z base vectors |
Construct a geodesic sphere based on icosahedron symmetry.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.radius] | Number |
1 |
target radius of sphere |
[options.frequency] | Number |
1 |
subdivision frequency per face, multiples of 6 |
Create a new line (path) from the given points. The points must be provided as an array, where each element is an array of two numbers.
Kind: global function
Returns: path2
- new path
Example:: my newpath = line([[10, 10], [-10, 10]])
Param | Type | Description |
---|---|---|
points | Array |
array of points from which to create the path |
Construct a polygon from a list of points, or list of points and paths. NOTE: The ordering of points is VERY IMPORTANT.
Kind: global function
Returns: geom2
- new 2D geometry
Param | Type | Description |
---|---|---|
options | Object |
options for construction |
options.points | Array |
points of the polygon : either flat or nested array of points |
[options.paths] | Array |
paths of the polygon : either flat or nested array of points index |
Example
let roof = [[10,11], [0,11], [5,20]]
let wall = [[0,0], [10,0], [10,10], [0,10]]
let poly = polygon({ points: roof })
or
let poly = polygon({ points: [roof, wall] })
or
let poly = polygon({ points: roof, paths: [0, 1, 2] })
or
let poly = polygon({ points: [roof, wall], paths: [[0, 1, 2], [3, 4, 5, 6]] })
Create a polyhedron from the given set of points and faces. The faces can define outward or inward facing polygons (orientation). However, each face must define a counter clockwise rotation of points which follows the right hand rule.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Default | Description |
---|---|---|---|
options | Object |
options for construction | |
options.points | Array |
[ |
list of points in 3D space |
options.faces | Array |
[ |
list of faces, where each face is a set of indexes into the points |
[options.orientation] | Array |
'outward' |
orientation of faces |
Example
let mypoints = [ [10, 10, 0], [10, -10, 0], [-10, -10, 0], [-10, 10, 0], [0, 0, 10] ]
let myfaces = [ [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [1, 0, 3], [2, 1, 3] ]
let myshape = polyhedron({points: mypoint, faces: myfaces, orientation: 'inward'})
Construct an axis-aligned rectangle with four sides and four 90-degree angles.
Kind: global function
Returns: geom2
- new 2D geometry
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Array |
[0,0] |
center of rectangle |
[options.size] | Array |
[1,1] |
size of rectangle, width and height |
Example
let myshape = rectangle({center: [5, 5, 5], size: [5, 10]})
Construct an axis-aligned square with four equal sides and four 90-degree angles.
Kind: global function
Returns: geom2
- new 2D geometry
See: rectangle for additional options, as this is an alias fo rectangle
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Array |
[0,0] |
center of square |
[options.size] | Number |
1 |
size of square |
Example
let myshape = square({center: [5, 5], size: 5})
Construct an axis-aligned solid rounded cuboid.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Vector3 |
[0,0,0] |
center of rounded cube |
[options.size] | Vector3 |
[1,1,1] |
size of rounded cube, single scalar is possible |
[options.roundRadius] | Number |
0.2 |
radius of rounded edges |
[options.segments] | Number |
12 |
number of segments to create per 360 rotation |
Example
let mycube = roundedCuboid({
center: [2, 0, 2],
size: 15,
roundRadius: 2,
segments: 36,
});
Construct a cylinder with rounded ends.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
options.height | Array |
2 |
height of cylinder |
[options.radius] | Number |
1 |
radius of cylinder |
[options.roundRadius] | Number |
0.2 |
radius of rounded edges |
[options.segments] | Number |
12 |
number of segments to create per 360 rotation |
Example
let mycylinder = roundedCylinder({
height: 10,
radius: 2,
roundRadius: 0.5
})
Construct a rounded rectangle.
Kind: global function
Returns: geom2
- new 2D geometry
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Array |
[0,0] |
center of rounded rectangle |
[options.size] | Array |
[1,1] |
size of rounded rectangle, width and height |
[options.roundRadius] | Number |
0.2 |
round radius of corners |
[options.segments] | Number |
16 |
number of segments to create per 360 rotation |
Example
let myrectangle = roundedRectangle({size: [5, 10], roundRadius: 2})
Construct a star from the given options.
Kind: global function
See: https://en.wikipedia.org/wiki/Star_polygon
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.center] | Array |
[0,0] |
center of star |
[options.vertices] | Number |
5 |
number of vertices (P) on the star |
[options.density] | Number |
2 |
density (Q) of star |
[options.outerRadius] | Number |
1 |
outer radius of vertices |
[options.innerRadius] | Number |
0 |
inner radius of vertices, or zero to calculate |
[options.startAngle] | Number |
0 |
starting angle for first vertice, in radians |
Example
let star1 = star({vertices: 8, outerRadius: 10}) // star with 8/2 density
let star2 = star({vertices: 12, outerRadius: 40, innerRadius: 20}) // star with given radius
Construct a torus by revolving a small circle (inner) about the circumference of a large (outer) circle.
Kind: global function
Returns: geom3
- new 3D geometry
Param | Type | Default | Description |
---|---|---|---|
[options] | Object |
options for construction | |
[options.innerRadius] | Float |
1 |
radius of small (inner) circle |
[options.outerRadius] | Float |
4 |
radius of large (outer) circle |
[options.innerSegments] | Integer |
16 |
number of segments to create per 360 rotation |
[options.outerSegments] | Integer |
12 |
number of segments to create per 360 rotation |
[options.innerRotation] | Integer |
0 |
rotation of small (inner) circle in radians |
Example
let torus1 = torus({
innerRadius: 10
})
vectorChar([options], [char]) ⇒ VectorCharObject
Construct a VectorCharObject from a ascii character whose code is between 31 and 127, if the character is not supported it is replaced by a question mark.
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
[options] | Object | String |
options for construction or ascii character | |
[options.xOffset] | Float |
0 |
x offset |
[options.yOffset] | Float |
0 |
y offset |
[options.height] | Float |
21 |
font size (uppercase height) |
[options.extrudeOffset] | Float |
0 |
width of the extrusion that will be applied (manually) after the creation of the character |
[options.input] | String |
'?' |
ascii character (ignored/overwrited if provided as seconds parameter) |
[char] | String |
'?' |
ascii character |
Example
let vectorCharObject = vectorChar()
or
let vectorCharObject = vectorChar('A')
or
let vectorCharObject = vectorChar({ xOffset: 57 }, 'C')
or
let vectorCharObject = vectorChar({ xOffset: 78, input: '!' })
Construct an array of character segments from a ascii string whose characters code is between 31 and 127, if one character is not supported it is replaced by a question mark.
Kind: global function
Returns: Array
- characters segments [[[x, y], ...], ...]
Param | Type | Default | Description |
---|---|---|---|
[options] | Object | String |
options for construction or ascii string | |
[options.xOffset] | Float |
0 |
x offset |
[options.yOffset] | Float |
0 |
y offset |
[options.height] | Float |
21 |
font size (uppercase height) |
[options.lineSpacing] | Float |
1.4 |
line spacing expressed as a percentage of font size |
[options.letterSpacing] | Float |
1 |
extra letter spacing expressed as a percentage of font size |
[options.align] | String |
'left' |
multi-line text alignement: left, center or right |
[options.extrudeOffset] | Float |
0 |
width of the extrusion that will be applied (manually) after the creation of the character |
[options.input] | String |
'?' |
ascii string (ignored/overwrited if provided as seconds parameter) |
[text] | String |
'?' |
ascii string |
Example
let textSegments = vectorText()
or
let textSegments = vectorText('OpenJSCAD')
or
let textSegments = vectorText({ yOffset: -50 }, 'OpenJSCAD')
or
let textSegments = vectorText({ yOffset: -80, input: 'OpenJSCAD' })
Represents a character as segments
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
width | Float |
character width |
height | Float |
character height (uppercase) |
segments | Array |
character segments [[[x, y], ...], ...] |
Represents a character as segments
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
width | Float |
character width |
height | Float |
character height (uppercase) |
segments | Array |
character segments [[[x, y], ...], ...] |