Skip to content

Low-level geometry types and constructors. Most users interact with these indirectly via jscad.primitives and jscad.booleans; direct access is useful for building custom geometry or inspecting polygon/point data. The path2 namespace provides a full API for constructing open 2D paths incrementally.

See also:

namespace path2

2D open path construction and manipulation.

A Path2 is an ordered sequence of [x, y] points forming an open (or closed) polyline. Paths can be built incrementally by appending points, arcs, or bezier curves, then passed to extrusion functions or used directly as 2D output. Key operations:

  • path2.create(points?) — create empty or seeded path
  • path2.fromPoints(options, points) — create from point array; { closed: true } closes the loop
  • path2.appendPoints(points, path) — append raw points
  • path2.appendArc(options, path) — append an SVG-style elliptical arc
  • path2.appendBezier(options, path) — append a cubic bezier curve
  • path2.close(path) — close an open path
  • path2.concat(...paths) — join multiple paths into one
  • path2.toPoints(path) — extract all points as [[x,y], …]
const { path2 } = jscad.geometries
const { extrudeLinear } = jscad.extrusions
async function main() {
let p = path2.create([[0,0]])
p = path2.appendArc({ endpoint: [10, 0], radius: [5, 5] }, p)
p = path2.appendPoints([[10, 5], [0, 5]], p)
p = path2.close(p)
return extrudeLinear({ height: 3 }, p)
}

See also:

namespace geom2

2D solid geometry type and low-level operations.

A Geom2 represents a closed 2D solid as an ordered set of line segments (sides). Most users work with Geom2 indirectly via jscad.primitives (circle, square, etc.) and jscad.booleans. Direct geom2 manipulation is needed for custom geometry construction or inspection.

Key operations: geom2.create, geom2.fromPoints, geom2.toPoints, geom2.toSides, geom2.clone, geom2.isA, geom2.reverse.

const { geom2 } = jscad.geometries
const g = geom2.fromPoints([[0,0],[5,0],[5,5],[0,5]])
const pts = geom2.toPoints(g)

See also:

namespace geom3

3D solid geometry type and low-level operations.

A Geom3 represents a closed 3D solid as a list of polygons. Most users work with Geom3 indirectly via jscad.primitives and jscad.booleans. Direct geom3 manipulation is needed for custom geometry construction or inspection.

Key operations: geom3.create, geom3.fromPolygons, geom3.toPolygons, geom3.clone, geom3.isA, geom3.toPoints, geom3.isConvex.

const { geom3 } = jscad.geometries
const { sphere } = jscad.primitives
const s = sphere({ radius: 5 })
const polys = geom3.toPolygons(s)
javasculpt.log('polygon count:', polys.length)

See also: