Primitives
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 = objectA closed 2D geometry (filled polygon). Produced by 2D primitives such as circle, rectangle, and polygon.
type Geom3 = objectA 3D solid geometry. Produced by 3D primitives such as cube, sphere, and cylinder.
type Path2 = objectAn 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; }): Path2Construct 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.primitivesconst halfCircle = arc({ radius: 5, endAngle: Math.PI })See also:
circle
Section titled “circle”function circle(options?: { center?: Vec2; radius?: number; segments?: number; }): Geom2Construct 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.primitivesconst coin = circle({ radius: 10, segments: 64 })See also:
ellipse
Section titled “ellipse”function ellipse(options?: { center?: Vec2; radius?: Vec2; segments?: number; }): Geom2Construct 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.primitivesconst oval = ellipse({ radius: [8, 4] })See also:
function line(points: Vec2[]): Path2Construct 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.primitivesconst zigzag = line([[0,0],[2,2],[4,0],[6,2]])See also:
polygon
Section titled “polygon”function polygon(options: { points: Vec2[]; paths?: number[][]; }): Geom2Construct 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.primitivesconst triangle = polygon({ points: [[0,0],[4,0],[2,3]] })See also:
rectangle
Section titled “rectangle”function rectangle(options?: { center?: Vec2; size?: Vec2; }): Geom2Construct 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.primitivesconst card = rectangle({ size: [85, 54] })See also:
roundedRectangle
Section titled “roundedRectangle”function roundedRectangle(options?: { center?: Vec2; size?: Vec2; roundRadius?: number; segments?: number; }): Geom2Construct 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.primitivesconst btn = roundedRectangle({ size: [40, 15], roundRadius: 3 })See also:
square
Section titled “square”function square(options?: { center?: Vec2; size?: number; }): Geom2Construct 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.primitivesconst tile = square({ size: 10 })See also:
function star(options?: { center?: Vec2; vertices?: number; outerRadius?: number; innerRadius?: number; density?: number; startAngle?: number; }): Geom2Construct 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.primitivesconst badge = star({ vertices: 6, outerRadius: 10, innerRadius: 5 })See also:
function cube(options?: { center?: Vec3; size?: number; }): Geom3Construct 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.primitivesconst block = cube({ size: 10 })See also:
cuboid
Section titled “cuboid”function cuboid(options?: { center?: Vec3; size?: Vec3; }): Geom3Construct 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.primitivesconst plank = cuboid({ size: [30, 4, 2] })See also:
cylinder
Section titled “cylinder”function cylinder(options?: { center?: Vec3; height?: number; radius?: number; segments?: number; }): Geom3Construct 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.primitivesconst rod = cylinder({ height: 20, radius: 2, segments: 16 })See also:
cylinderElliptic
Section titled “cylinderElliptic”function cylinderElliptic(options?: { center?: Vec3; height?: number; startRadius?: Vec2; endRadius?: Vec2; startAngle?: number; endAngle?: number; segments?: number; }): Geom3Construct 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.primitivesconst cone = cylinderElliptic({ height: 10, startRadius: [3, 3], endRadius: [0, 0] })See also:
ellipsoid
Section titled “ellipsoid”function ellipsoid(options?: { center?: Vec3; radius?: Vec3; segments?: number; }): Geom3Construct 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.primitivesconst egg = ellipsoid({ radius: [2, 2, 3] })See also:
geodesicSphere
Section titled “geodesicSphere”function geodesicSphere(options?: { radius?: number; frequency?: number; }): Geom3Construct 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.primitivesconst ball = geodesicSphere({ radius: 5, frequency: 12 })See also:
roundedCuboid
Section titled “roundedCuboid”function roundedCuboid(options?: { center?: Vec3; size?: Vec3; roundRadius?: number; segments?: number; }): Geom3Construct 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.primitivesconst puck = roundedCuboid({ size: [10, 10, 4], roundRadius: 1 })See also:
roundedCylinder
Section titled “roundedCylinder”function roundedCylinder(options?: { center?: Vec3; height?: number; radius?: number; roundRadius?: number; segments?: number; }): Geom3Construct 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.primitivesconst capsule = roundedCylinder({ height: 8, radius: 2, roundRadius: 2 })See also:
sphere
Section titled “sphere”function sphere(options?: { center?: Vec3; radius?: number; segments?: number; }): Geom3Construct 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.primitivesconst ball = sphere({ radius: 5 })See also:
function torus(options?: { innerRadius?: number; outerRadius?: number; innerSegments?: number; outerSegments?: number; innerRotation?: number; startAngle?: number; outerRotation?: number; }): Geom3Construct 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.primitivesconst ring = torus({ innerRadius: 1, outerRadius: 5 })See also: