meta data for this page
This is an old revision of the document!
Primitive Shapes
The 'primitives' are accessed through the modeling API using the following:
const { cube, ellipse, star } = require('@jscad/modeling').primitives
2D Primitives
Primitive | Notes |
---|---|
const mypath = arc({center: [2, 2], radius: 2, startAngle: Math.PI, endAngle: Math.PI * 2, segments: 64}) | API documentation |
const myshape = circle({center: [6.5, 6.5], radius: 3.5, startAngle: Math.PI / 2, endAngle: Math.PI, segments: 64}) | API User Guide |
const myshape = ellipse({center: [6.5, 6.5], radius: [7, 9], startAngle: Math.PI / 2, endAngle: Math.PI, segments: 64}) | API documentation |
const mypath = line([ [10, 10], [-10, 10] ]) | API documentation |
const myshape = polygon({ points: [ [10, 11], [0, 11], [5, 20] ], paths: [0, 1, 2]}) | API documentation |
const myshape = rectangle({center: [6.5, 6.5], size: [10, 20]}) | API documentation |
const myshape = roundedRectangle({center: [6.5, 6.5], size: [10, 20], roundRadius: 2, segments: 64}) | API documentation |
const myshape = square({center: [6.5, 6.5], size: 10}) | API documentation |
const myshape = star({vertices: 8, outerRadius: 10}) /* star with 8/2 density */ | API documentation |
const myshape = star({vertices: 12, outerRadius: 40, innerRadius: 20}) /* star with given radius */ | API documentation |
3D Primitives
Primitive | Notes |
---|---|
const myshape = cube({center: [6.5, 6.5, 6.5], size: 7}) | API documentation |
const myshape = cuboid({center: [6.5, 6.5, 6.5], size: [3, 5, 7]}) | API documentation |
const myshape = cylinder({center: [-5, -5, -5], height: 10, radius: 4, segments: 5}) | API documentation |
const myshape = cylinderElliptic({center: [-5, -5, -5], height: 10, startRadius: [1, 2], endRadius: [2, 1], startAngle: Math.PI / 2, endAngle: Math.PI * 2 * 0.75, segments: 5}) | API documentation |
const myshape = ellipsoid({center: [-5, -5, -5], radius: [4, 6, 8], segments: 64}) | API documentation |
2D Primitives | 3D Primitives |
---|---|
const rectangle = square(); /* center: [0,0], size: [1,1] */ | const cube1 = cube(); /* center: [0,0,0], size: [1,1,1] */ |
const rectangle = square({center: [1,2], size: [1, 2]}); | const cube1 = cube({center: [1, 2, 3], size: [1, 2, 3]}); |
const rectangle = square({round: true}); /* center: [0,0], radius: [1,1], roundradius: 0.2, resolution: 32 */ | const cube1 = cube({round: true}); /* center: [0,0,0], radius: [1,1,1] roundradius: 0.2, resolution: 12 */ |
const rectangle = square({center: [1,2], radius: [1, 2],rounded: true, fn:32}); | const cube1 = cube({center: [0, 0, 0], radius: 2, round: true, fn: 32}); |
const circle1 = circle(); /* center: [0,0], r: [1,1], resolution: 32 */ | const sphere1 = sphere(); /* center: [0,0,0], r: 1, fn: 12 */ |
const circle1 = circle({center: [1,2], r: 3, resolution: 72}); | const sphere1 = sphere({center: [1, 2, 3], r: 4, fn: 36}); |
const cylinder1 = cylinder(); | |
const cylinder = CSG.cylinder({start: [1, 2, 3], end: [4, 5, 6], radiusStart: 7, radiusEnd: 8, resolution: 72}); | |
const cylinder = CSG.roundedCylinder(); /* start: [0,-1,0], end: [0,1,0], radius: 1, resolution: 12 */ | |
const cylinder = CSG.roundedCylinder({start: [10,11,12], end: [13,14,15], radius: 16, resolution: 6}); | |
const ellipse = CAG.ellipse({center: [5,5], radius: [10,20],resolution: 72}); | const cylinder = cylinder({r1: 10, r2: 20, fn: 16}); |
const cag = CAG.fromPoints([ [0,0],[5,0],[3,5],[0,5] ]); /* polygon with 3+ points */ | const csg = CSG.fromPolygons([polygon, …]); |
const cag = CAG.fromSides([side,…]); /* polygon with 1+ sides */ |