Skip to content

Constructors for 2D and 3D primitive shapes. 3D primitives include cubes, cylinders, spheres, ellipsoids, and tori; 2D primitives include circles, rectangles, polygons, and stars. All accept an options object; all dimensions default to sensible values when omitted.

See also:

type Vec2 = [number, number]

Two-element numeric tuple [x, y].

type Vec3 = [number, number, number]

Three-element numeric tuple [x, y, z].

type Geom2 = object

A closed 2D geometry (filled polygon). Produced by 2D primitives such as circle, rectangle, and polygon.

type Geom3 = object

A 3D solid geometry. Produced by 3D primitives such as cube, sphere, and cylinder.

type Path2 = object

An open 2D path (not filled). Produced by arc and line, and by path2 construction utilities. Can be extruded into a solid via extrudeLinear.

function arc(options?: { center?: Vec2; radius?: number; startAngle?: number; endAngle?: number; segments?: number; makeTangent?: boolean; }): Path2

Construct an open arc path in 2D space.

Produces a Path2, not a filled Geom2. Use extrudeLinear to give it depth, or combine with other paths via path2.concat.

Parameters:

Name Type Description
options — Arc options.
options.center — Centre point [x, y]. Default [0, 0].
options.radius — Radius. Default 1.
options.startAngle — Start angle in radians. Default 0.
options.endAngle — End angle in radians. Default 2π (full circle).
options.segments — Number of line segments. Default 32.
options.makeTangent — Add tangent lines at endpoints. Default false.

Returns: An open Path2 arc.

const { arc } = jscad.primitives
const halfCircle = arc({ radius: 5, endAngle: Math.PI })

See also:

function circle(options?: { center?: Vec2; radius?: number; segments?: number; }): Geom2

Construct a filled circle in 2D space.

Parameters:

Name Type Description
options — Circle options.
options.center — Centre point [x, y]. Default [0, 0].
options.radius — Radius. Default 1.
options.segments — Number of polygon segments. Default 32.

Returns: A filled Geom2 circle.

const { circle } = jscad.primitives
const coin = circle({ radius: 10, segments: 64 })

See also:

function ellipse(options?: { center?: Vec2; radius?: Vec2; segments?: number; }): Geom2

Construct a filled ellipse in 2D space.

Parameters:

Name Type Description
options — Ellipse options.
options.center — Centre point [x, y]. Default [0, 0].
options.radius — [radiusX, radiusY] pair. Default [1, 0.5].
options.segments — Number of polygon segments. Default 32.

Returns: A filled Geom2 ellipse.

const { ellipse } = jscad.primitives
const oval = ellipse({ radius: [8, 4] })

See also:

function line(points: Vec2[]): Path2

Construct an open polyline from an array of 2D points.

Produces a Path2 (not a filled shape). Pass the result to extrudeLinear to give it depth, or to path2.close to make a closed loop.

Parameters:

Name Type Description
points — Array of [x, y] points defining the polyline.

Returns: An open Path2 polyline.

const { line } = jscad.primitives
const zigzag = line([[0,0],[2,2],[4,0],[6,2]])

See also:

function polygon(options: { points: Vec2[]; paths?: number[][]; }): Geom2

Construct a filled polygon from an array of 2D points.

Parameters:

Name Type Description
options — Polygon options.
options.points — Array of [x, y] vertices defining the outer boundary.
options.paths — Optional index arrays to define holes or multiple contours.

Returns: A filled Geom2 polygon.

const { polygon } = jscad.primitives
const triangle = polygon({ points: [[0,0],[4,0],[2,3]] })

See also:

function rectangle(options?: { center?: Vec2; size?: Vec2; }): Geom2

Construct an axis-aligned rectangle in 2D space.

Parameters:

Name Type Description
options — Rectangle options.
options.center — Centre point [x, y]. Default [0, 0].
options.size — [width, height] pair. Default [2, 2].

Returns: A filled Geom2 rectangle.

const { rectangle } = jscad.primitives
const card = rectangle({ size: [85, 54] })

See also:

function roundedRectangle(options?: { center?: Vec2; size?: Vec2; roundRadius?: number; segments?: number; }): Geom2

Construct a rectangle with rounded corners in 2D space.

Parameters:

Name Type Description
options — Rounded rectangle options.
options.center — Centre point [x, y]. Default [0, 0].
options.size — [width, height] pair. Default [2, 2].
options.roundRadius — Corner radius. Default 0.2.
options.segments — Segments per corner arc. Default 32.

Returns: A filled Geom2 with rounded corners.

const { roundedRectangle } = jscad.primitives
const btn = roundedRectangle({ size: [40, 15], roundRadius: 3 })

See also:

function square(options?: { center?: Vec2; size?: number; }): Geom2

Construct a square in 2D space.

Parameters:

Name Type Description
options — Square options.
options.center — Centre point [x, y]. Default [0, 0].
options.size — Side length. Default 2.

Returns: A filled Geom2 square.

const { square } = jscad.primitives
const tile = square({ size: 10 })

See also:

function star(options?: { center?: Vec2; vertices?: number; outerRadius?: number; innerRadius?: number; density?: number; startAngle?: number; }): Geom2

Construct a star shape in 2D space.

Parameters:

Name Type Description
options — Star options.
options.center — Centre point [x, y]. Default [0, 0].
options.vertices — Number of points on the star. Default 5.
options.outerRadius — Radius of the outer points. Default 1.
options.innerRadius — Radius of the inner valleys. Default 0.5. Set to 0 to auto-calculate.
options.density — Density factor for connecting points (2 = regular star). Default 2.
options.startAngle — Rotation offset in radians. Default 0.

Returns: A filled Geom2 star.

const { star } = jscad.primitives
const badge = star({ vertices: 6, outerRadius: 10, innerRadius: 5 })

See also:

function cube(options?: { center?: Vec3; size?: number; }): Geom3

Construct an axis-aligned cube in 3D space.

Parameters:

Name Type Description
options — Cube options.
options.center — Centre point [x, y, z]. Default [0, 0, 0].
options.size — Side length (equal on all axes). Default 2.

Returns: A Geom3 cube.

const { cube } = jscad.primitives
const block = cube({ size: 10 })

See also:

function cuboid(options?: { center?: Vec3; size?: Vec3; }): Geom3

Construct an axis-aligned rectangular cuboid in 3D space.

Parameters:

Name Type Description
options — Cuboid options.
options.center — Centre point [x, y, z]. Default [0, 0, 0].
options.size — [width, depth, height] dimensions. Default [2, 2, 2].

Returns: A Geom3 cuboid.

const { cuboid } = jscad.primitives
const plank = cuboid({ size: [30, 4, 2] })

See also:

function cylinder(options?: { center?: Vec3; height?: number; radius?: number; segments?: number; }): Geom3

Construct a cylinder aligned along the Z axis in 3D space.

Parameters:

Name Type Description
options — Cylinder options.
options.center — Centre point [x, y, z]. Default [0, 0, 0].
options.height — Height along Z. Default 2.
options.radius — Radius. Default 1.
options.segments — Number of sides. Default 32.

Returns: A Geom3 cylinder.

const { cylinder } = jscad.primitives
const rod = cylinder({ height: 20, radius: 2, segments: 16 })

See also:

function cylinderElliptic(options?: { center?: Vec3; height?: number; startRadius?: Vec2; endRadius?: Vec2; startAngle?: number; endAngle?: number; segments?: number; }): Geom3

Construct an elliptic cylinder or tapered frustum in 3D space.

Start and end radii can differ to produce a cone-like shape.

Parameters:

Name Type Description
options — Elliptic cylinder options.
options.center — Centre point [x, y, z]. Default [0, 0, 0].
options.height — Height along Z. Default 2.
options.startRadius — [rx, ry] at the bottom face. Default [1, 1].
options.endRadius — [rx, ry] at the top face. Default [0.5, 0.5].
options.startAngle — Start angle in radians. Default 0.
options.endAngle — End angle in radians. Default 2π.
options.segments — Number of sides. Default 32.

Returns: A Geom3 elliptic cylinder.

const { cylinderElliptic } = jscad.primitives
const cone = cylinderElliptic({ height: 10, startRadius: [3, 3], endRadius: [0, 0] })

See also:

function ellipsoid(options?: { center?: Vec3; radius?: Vec3; segments?: number; }): Geom3

Construct an ellipsoid (stretched sphere) in 3D space.

Parameters:

Name Type Description
options — Ellipsoid options.
options.center — Centre point [x, y, z]. Default [0, 0, 0].
options.radius — [rx, ry, rz] semi-axes. Default [1, 0.75, 0.5].
options.segments — Tessellation resolution. Default 32.

Returns: A Geom3 ellipsoid.

const { ellipsoid } = jscad.primitives
const egg = ellipsoid({ radius: [2, 2, 3] })

See also:

function geodesicSphere(options?: { radius?: number; frequency?: number; }): Geom3

Construct a geodesic sphere in 3D space.

Triangular facets give a more uniform polygon distribution than a standard UV sphere, which is useful for organic shapes and lighting.

Parameters:

Name Type Description
options — Geodesic sphere options.
options.radius — Radius. Default 1.
options.frequency — Subdivision frequency (must be ≥ 6). Default 6.

Returns: A Geom3 geodesic sphere.

const { geodesicSphere } = jscad.primitives
const ball = geodesicSphere({ radius: 5, frequency: 12 })

See also:

function roundedCuboid(options?: { center?: Vec3; size?: Vec3; roundRadius?: number; segments?: number; }): Geom3

Construct a cuboid with rounded edges and corners in 3D space.

Parameters:

Name Type Description
options — Rounded cuboid options.
options.center — Centre point [x, y, z]. Default [0, 0, 0].
options.size — [width, depth, height] dimensions. Default [2, 2, 2].
options.roundRadius — Edge/corner radius. Default 0.2.
options.segments — Segments per rounded edge. Default 32.

Returns: A Geom3 cuboid with rounded edges.

const { roundedCuboid } = jscad.primitives
const puck = roundedCuboid({ size: [10, 10, 4], roundRadius: 1 })

See also:

function roundedCylinder(options?: { center?: Vec3; height?: number; radius?: number; roundRadius?: number; segments?: number; }): Geom3

Construct a cylinder with rounded (hemispherical) ends in 3D space.

Parameters:

Name Type Description
options — Rounded cylinder options.
options.center — Centre point [x, y, z]. Default [0, 0, 0].
options.height — Total height including the end caps. Default 2.
options.radius — Body radius. Default 1.
options.roundRadius — Cap radius (must be ≤ radius). Default 0.2.
options.segments — Segments per cap. Default 32.

Returns: A Geom3 capsule-shaped cylinder.

const { roundedCylinder } = jscad.primitives
const capsule = roundedCylinder({ height: 8, radius: 2, roundRadius: 2 })

See also:

function sphere(options?: { center?: Vec3; radius?: number; segments?: number; }): Geom3

Construct a UV sphere in 3D space.

Parameters:

Name Type Description
options — Sphere options.
options.center — Centre point [x, y, z]. Default [0, 0, 0].
options.radius — Radius. Default 1.
options.segments — Tessellation resolution (vertical and horizontal). Default 32.

Returns: A Geom3 sphere.

const { sphere } = jscad.primitives
const ball = sphere({ radius: 5 })

See also:

function torus(options?: { innerRadius?: number; outerRadius?: number; innerSegments?: number; outerSegments?: number; innerRotation?: number; startAngle?: number; outerRotation?: number; }): Geom3

Construct a torus (donut shape) in 3D space.

The torus lies in the XY plane with the hole along the Z axis.

Parameters:

Name Type Description
options — Torus options.
options.innerRadius — Radius of the tube cross-section. Default 0.5.
options.outerRadius — Distance from the centre to the tube centre. Default 2.
options.innerSegments — Segments around the tube cross-section. Default 32.
options.outerSegments — Segments around the full ring. Default 32.
options.startAngle — Start angle of the sweep in radians. Default 0.
options.outerRotation — End angle of the sweep in radians. Default 2π.

Returns: A Geom3 torus.

const { torus } = jscad.primitives
const ring = torus({ innerRadius: 1, outerRadius: 5 })

See also: