extrusions
Modules
| Module | Description |
|---|---|
| modeling/extrusions | All 2D shapes (primitives or the results of operations) can be extruded in various ways. In all cases, the function returns the results, and never changes the original shapes. |
| modeling/extrusions/slice | Represents a 3D geometry consisting of a list of edges. |
Typedefs
| Name | Description |
|---|---|
| slice | Represents a 3D geometry consisting of a list of edges. |
modeling/extrusions
All 2D shapes (primitives or the results of operations) can be extruded in various ways. In all cases, the function returns the results, and never changes the original shapes.
Example
const { extrudeHelical, extrudeLinear, extrudeRectangular, extrudeRotate, project, slice } = require('@jscad/modeling').extrusions
modeling/extrusions.extrudeFromSlices(options, base)
Extrude a solid from the slices as returned by the callback function.
Kind: static method of modeling/extrusions
Returns: geom3 - the extruded shape
See: slice
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object | options for extrude | |
| [options.numberOfSlices] | Integer | 2 | the number of slices to be generated by the callback |
| [options.capStart] | Boolean | true | the solid should have a cap at the start |
| [options.capEnd] | Boolean | true | the solid should have a cap at the end |
| [options.close] | Boolean | false | the solid should have a closing section between start and end |
| [options.repair] | Boolean | true | repair gaps in the geometry |
| [options.callback] | function | the callback function that generates each slice | |
| base | Object | the base object which is used to create slices (see the example for callback information) |
Example
// Parameters:
// progress : the percent complete [0..1]
// index : the index of the current slice [0..numberOfSlices - 1]
// base : the base object as given
// Return Value:
// slice or null (to skip)
const callback = (progress, index, base) => {
...
return slice
}
modeling/extrusions.extrudeHelical(options, geometry)
Perform a helical extrude of the geometry, using the given options.
Kind: static method of modeling/extrusions
Returns: geom3 - the extruded geometry
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object | options for extrusion | |
| [options.angle] | Number | TAU | angle of the extrusion (RADIANS); positive for right-hand rotation, negative for left-hand |
| [options.startAngle] | Number | 0 | start angle of the extrusion (RADIANS) |
| [options.pitch] | Number | 10 | elevation gain for each full rotation |
| [options.height] | Number | total height of the helix path. Ignored if pitch is set. | |
| [options.endOffset] | Number | 0 | offset the final radius of the extrusion, allowing for tapered helix, and or spiral |
| [options.segmentsPerRotation] | Number | 32 | number of segments per full rotation of the extrusion |
| geometry | geom2 | the geometry to extrude |
Example
const myshape = circle({size: 3, center: [10, 0]}) // position for extrusion about Z
const mycoil = extrudeHelical({angle: TAU * 2, pitch: 10, segmentsPerRotation: 64}, myshape))
modeling/extrusions.extrudeLinear(options, ...objects)
Extrude the given geometry in an upward linear direction using the given options. Accepts path2 or geom2 objects as input. Paths must be closed.
Kind: static method of modeling/extrusions
Returns: Object ⎮ Array - the extruded geometry, or a list of extruded geometry
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object | options for extrude | |
| [options.height] | Number | 1 | the height of the extrusion |
| [options.twistAngle] | Number | 0 | the final rotation (RADIANS) about the origin of the shape (if any) |
| [options.twistSteps] | Integer | 1 | the resolution of the twist about the axis (if any) |
| ...objects | Object | the geometries to extrude |
Example
let myshape = extrudeLinear({height: 10}, rectangle({size: [20, 25]}))
modeling/extrusions.extrudeRectangular(options, ...objects)
Extrude the given geometry by following the outline(s) with a rectangle.
Kind: static method of modeling/extrusions
Returns: Object ⎮ Array - the extruded object, or a list of extruded objects
See: expand for addition options
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object | options for extrusion, if any | |
| [options.size] | Number | 1 | size of the rectangle |
| [options.height] | Number | 1 | height of the extrusion |
| ...objects | Object | the geometries to extrude |
Example
let mywalls = extrudeRectangular({size: 1, height: 3}, square({size: 20}))
let mywalls = extrudeRectangular({size: 1, height: 300, twistAngle: TAU / 2}, square({size: 20}))
modeling/extrusions.extrudeRotate(options, geometry)
Rotate extrude the given geometry using the given options.
Kind: static method of modeling/extrusions
Returns: geom3 - the extruded geometry
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object | options for extrusion | |
| [options.angle] | Number | TAU | angle of the extrusion (RADIANS) |
| [options.startAngle] | Number | 0 | start angle of the extrusion (RADIANS) |
| [options.overflow] | String | 'cap' | what to do with points outside of bounds (+ / - x) : defaults to capping those points to 0 (only supported behaviour for now) |
| [options.segments] | Number | 12 | number of segments of the extrusion |
| geometry | geom2 | the geometry to extrude |
Example
const myshape = extrudeRotate({segments: 8, angle: TAU / 2}, circle({size: 3, center: [4, 0]}))
modeling/extrusions.project(options, ...objects)
Project the given 3D geometry on to the given plane.
Kind: static method of modeling/extrusions
Returns: geom2 ⎮ Array - the projected 2D geometry, or a list of 2D projected geometry
| Param | Type | Default | Description |
|---|---|---|---|
| options | Object | options for project | |
| [options.axis] | Array | [0,0,1] | the axis of the plane (default is Z axis) |
| [options.origin] | Array | [0,0,0] | the origin of the plane |
| ...objects | Object | the list of 3D geometry to project |
Example
let myshape = project({}, sphere({radius: 20, segments: 5}))
modeling/extrusions/slice
Represents a 3D geometry consisting of a list of edges.
See: slice for data structure information.
modeling/extrusions/slice.calculatePlane(slice)
Calculate the plane of the given slice. NOTE: The slice (and all points) are assumed to be planar from the beginning.
Kind: static method of modeling/extrusions/slice
Returns: plane - the plane of the slice
| Param | Type | Description |
|---|---|---|
| slice | slice | the slice |
Example
let myplane = calculatePlane(slice)
modeling/extrusions/slice.clone([out], slice)
Create a deep clone of the given slice.
Kind: static method of modeling/extrusions/slice
Returns: slice - a new slice
| Param | Type | Description |
|---|---|---|
| [out] | slice | receiving slice |
| slice | slice | slice to clone |
modeling/extrusions/slice.create()
Creates a new empty slice.
Kind: static method of modeling/extrusions/slice
Returns: slice - a new slice
modeling/extrusions/slice.equals(a, b)
Determine if the given slices have the same edges.
Kind: static method of modeling/extrusions/slice
Returns: Boolean - true if the slices are equal
| Param | Type | Description |
|---|---|---|
| a | slice | the first slice to compare |
| b | slice | the second slice to compare |
modeling/extrusions/slice.fromPoints(points)
Create a slice from the given points.
Kind: static method of modeling/extrusions/slice
Returns: slice - a new slice
| Param | Type | Description |
|---|---|---|
| points | Array | list of points, where each point is either 2D or 3D |
Example
const points = [
[0, 0],
[0, 10],
[0, 10]
]
const slice = fromPoints(points)
modeling/extrusions/slice.fromSides(sides)
Create a slice from the given sides (see geom2).
Kind: static method of modeling/extrusions/slice
Returns: slice - a new slice
| Param | Type | Description |
|---|---|---|
| sides | Array | list of sides from geom2 |
Example
const myshape = circle({radius: 10})
const slice = fromSides(geom2.toSides(myshape))
modeling/extrusions/slice.isA(object)
Determine if the given object is a slice.
Kind: static method of modeling/extrusions/slice
Returns: Boolean - true if the object matches a slice
| Param | Type | Description |
|---|---|---|
| object | slice | the object to interrogate |
modeling/extrusions/slice.reverse([out], slice)
Reverse the edges of the given slice.
Kind: static method of modeling/extrusions/slice
Returns: slice - reverse of the slice
| Param | Type | Description |
|---|---|---|
| [out] | slice | receiving slice |
| slice | slice | slice to reverse |
modeling/extrusions/slice.toEdges(slice)
Produces an array of edges from the given slice. The returned array should not be modified as the data is shared with the slice.
Kind: static method of modeling/extrusions/slice
Returns: Array - an array of edges, each edge contains an array of two points (3D)
| Param | Type | Description |
|---|---|---|
| slice | slice | the slice |
Example
let sharededges = toEdges(slice)
modeling/extrusions/slice.toPolygons(slice)
Return a list of polygons which are enclosed by the slice.
Kind: static method of modeling/extrusions/slice
Returns: Array - a list of polygons (3D)
| Param | Type | Description |
|---|---|---|
| slice | slice | the slice |
modeling/extrusions/slice.toString(slice)
Kind: static method of modeling/extrusions/slice
Returns: String - the string representation
| Param | Type | Description |
|---|---|---|
| slice | slice | the slice |
modeling/extrusions/slice.transform(matrix, slice)
Transform the given slice using the given matrix.
Kind: static method of modeling/extrusions/slice
Returns: slice - the transformed slice
| Param | Type | Description |
|---|---|---|
| matrix | mat4 | transform matrix |
| slice | slice | slice to transform |
Example
let matrix = mat4.fromTranslation([1, 2, 3])
let newslice = transform(matrix, oldslice)
slice
Represents a 3D geometry consisting of a list of edges.
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| edges | Array | list of edges, each edge containing two points (3D) |