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.

Source:
Example
const { extrudeLinear, extrudeRectangular, extrudeRotate } = require('@jscad/modeling').extrusions

Methods

(static) extrudeFromSlices(options, base) → {geom3}

Source:
See:

Extrude a solid from the slices as returned by the callback function.

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
}
Parameters:
Name Type Description
options Object

options for extrude

Properties
Name Type Attributes Default Description
numberOfSlices Integer <optional>
2

the number of slices to be generated by the callback

capStart Boolean <optional>
true

the solid should have a cap at the start

capEnd Boolean <optional>
true

the solid should have a cap at the end

close Boolean <optional>
false

the solid should have a closing section between start and end

repair Boolean <optional>
true

repair gaps in the geometry

callback function <optional>

the callback function that generates each slice

base Object

the base object which is used to create slices (see the example for callback information)

Returns:

the extruded shape

Type
geom3

(static) extrudeHelical(options, geometry) → {geom3}

Source:

Perform a helical extrude of the geometry, using the given options.

Example
const myshape = extrudeHelical(
 {
     angle: Math.PI * 4,
     pitch: 10,
     segmentsPerRotation: 64
 },
 circle({size: 3, center: [10, 0]})
)
Parameters:
Name Type Description
options Object

options for extrusion

Properties
Name Type Attributes Default Description
angle Number <optional>
TAU

angle of the extrusion (RADIANS) positive for right-hand rotation, negative for left-hand

startAngle Number <optional>
0

start angle of the extrusion (RADIANS)

pitch Number <optional>
10

elevation gain for each turn

height Number <optional>

total height of the helix path. Ignored if pitch is set.

endOffset Number <optional>
0

offset the final radius of the extrusion, allowing for tapered helix, and or spiral

segmentsPerRotation Number <optional>
32

number of segments per full rotation of the extrusion

geometry geom2

the geometry to extrude

Returns:

the extruded geometry

Type
geom3

(static) extrudeLinear(options, …objects) → {Object|Array}

Source:

Extrude the given geometry in an upward linear direction using the given options. Accepts path2 or geom2 objects as input. Paths must be closed.

Example
let myshape = extrudeLinear({height: 10}, rectangle({size: [20, 25]}))
Parameters:
Name Type Attributes Description
options Object

options for extrude

Properties
Name Type Attributes Default Description
height Number <optional>
1

the height of the extrusion

twistAngle Number <optional>
0

the final rotation (RADIANS) about the origin of the shape (if any)

twistSteps Integer <optional>
1

the resolution of the twist about the axis (if any)

objects Object <repeatable>

the geometries to extrude

Returns:

the extruded geometry, or a list of extruded geometry

Type
Object | Array

(static) extrudeRectangular(options, …objects) → {Object|Array}

Source:
See:
  • expand for addition options

Extrude the given geometry by following the outline(s) with a rectangle.

Example
let mywalls = extrudeRectangular({size: 1, height: 3}, square({size: 20}))
let mywalls = extrudeRectangular({size: 1, height: 300, twistAngle: TAU / 2}, square({size: 20}))
Parameters:
Name Type Attributes Description
options Object

options for extrusion, if any

Properties
Name Type Attributes Default Description
size Number <optional>
1

size of the rectangle

height Number <optional>
1

height of the extrusion

objects Object <repeatable>

the geometries to extrude

Returns:

the extruded object, or a list of extruded objects

Type
Object | Array

(static) extrudeRotate(options, geometry) → {geom3}

Source:

Rotate extrude the given geometry using the given options.

Example
const myshape = extrudeRotate({segments: 8, angle: TAU / 2}, circle({size: 3, center: [4, 0]}))
Parameters:
Name Type Description
options Object

options for extrusion

Properties
Name Type Attributes Default Description
angle Number <optional>
TAU

angle of the extrusion (RADIANS)

startAngle Number <optional>
0

start angle of the extrusion (RADIANS)

overflow String <optional>
'cap'

what to do with points outside of bounds (+ / - x) : defaults to capping those points to 0 (only supported behaviour for now)

segments Number <optional>
12

number of segments of the extrusion

geometry geom2

the geometry to extrude

Returns:

the extruded geometry

Type
geom3

(static) project(options, …objects) → {geom2|Array}

Source:

Project the given 3D geometry on to the given plane.

Example
let myshape = project({}, sphere({radius: 20, segments: 5}))
Parameters:
Name Type Attributes Description
options Object

options for project

Properties
Name Type Attributes Default Description
axis Array <optional>
[0,0,1]

the axis of the plane (default is Z axis)

origin Array <optional>
[0,0,0]

the origin of the plane

objects Object <repeatable>

the list of 3D geometry to project

Returns:

the projected 2D geometry, or a list of 2D projected geometry

Type
geom2 | Array