Skip to main content

extrusions

Modules

ModuleDescription
modeling/extrusions所有二维图形(基本图形或运算结果)都可以通过多种方式进行拉伸(挤出)。在所有情况下,函数均返回运算结果,不会修改原始图形。
modeling/extrusions/slice表示一个由边列表构成的三维几何体。

Typedefs

NameDescription
slice表示一个由边列表组成的三维几何体。

modeling/extrusions

所有二维图形(基本图形或运算结果)均可通过多种方式进行拉伸(挤出)。在任何情况下,该函数均返回运算结果,且不会修改原始图形。

Example

const { extrudeHelical, extrudeLinear, extrudeRectangular, extrudeRotate, project, slice } = require('@jscad/modeling').extrusions

modeling/extrusions.extrudeFromSlices(options, base)

根据回调函数返回的切片,拉伸生成一个实体。

Kind: static method of modeling/extrusions
Returns: geom3 - the extruded shape
See: slice

ParamTypeDefaultDescription
optionsObjectoptions for extrude
[options.numberOfSlices]Integer2the number of slices to be generated by the callback
[options.capStart]Booleantruethe solid should have a cap at the start
[options.capEnd]Booleantruethe solid should have a cap at the end
[options.close]Booleanfalsethe solid should have a closing section between start and end
[options.repair]Booleantruerepair gaps in the geometry
[options.callback]functionthe callback function that generates each slice
baseObjectthe 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

ParamTypeDefaultDescription
optionsObjectoptions for extrusion
[options.angle]NumberTAUangle of the extrusion (RADIANS); positive for right-hand rotation, negative for left-hand
[options.startAngle]Number0start angle of the extrusion (RADIANS)
[options.pitch]Number10elevation gain for each full rotation
[options.height]Numbertotal height of the helix path. Ignored if pitch is set.
[options.endOffset]Number0offset the final radius of the extrusion, allowing for tapered helix, and or spiral
[options.segmentsPerRotation]Number32number of segments per full rotation of the extrusion
geometrygeom2the 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: ObjectArray - the extruded geometry, or a list of extruded geometry

ParamTypeDefaultDescription
optionsObjectoptions for extrude
[options.height]Number1the height of the extrusion
[options.twistAngle]Number0the final rotation (RADIANS) about the origin of the shape (if any)
[options.twistSteps]Integer1the resolution of the twist about the axis (if any)
...objectsObjectthe 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: ObjectArray - the extruded object, or a list of extruded objects
See: expand for addition options

ParamTypeDefaultDescription
optionsObjectoptions for extrusion, if any
[options.size]Number1size of the rectangle
[options.height]Number1height of the extrusion
...objectsObjectthe 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

ParamTypeDefaultDescription
optionsObjectoptions for extrusion
[options.angle]NumberTAUangle of the extrusion (RADIANS)
[options.startAngle]Number0start 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]Number12number of segments of the extrusion
geometrygeom2the 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: geom2Array - the projected 2D geometry, or a list of 2D projected geometry

ParamTypeDefaultDescription
optionsObjectoptions 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
...objectsObjectthe 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

ParamTypeDescription
sliceslicethe 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

ParamTypeDescription
[out]slicereceiving slice
slicesliceslice 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

ParamTypeDescription
aslicethe first slice to compare
bslicethe 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

ParamTypeDescription
pointsArraylist 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

ParamTypeDescription
sidesArraylist 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

ParamTypeDescription
objectslicethe 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

ParamTypeDescription
[out]slicereceiving slice
slicesliceslice 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)

ParamTypeDescription
sliceslicethe 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)

ParamTypeDescription
sliceslicethe slice

modeling/extrusions/slice.toString(slice)

Kind: static method of modeling/extrusions/slice
Returns: String - the string representation

ParamTypeDescription
sliceslicethe 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

ParamTypeDescription
matrixmat4transform matrix
slicesliceslice 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

NameTypeDescription
edgesArraylist of edges, each edge containing two points (3D)