meta data for this page
Quick Reference
The following sections provide quick reference to the JSCAD application programming interface (API), the heart of making designs.
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 |
const myshape = circle({center: [6.5, 6.5], radius: 3.5, startAngle: Math.PI / 2, endAngle: Math.PI, segments: 64}) | User Guide API |
const myshape = ellipse({center: [6.5, 6.5], radius: [7, 9], startAngle: Math.PI / 2, endAngle: Math.PI, segments: 64}) | API |
const mypath = line([ [10, 10], [-10, 10] ]) | API |
const myshape = polygon({ points: [ [10, 11], [0, 11], [5, 20] ], paths: [0, 1, 2]}) | API |
const myshape = rectangle({center: [6.5, 6.5], size: [10, 20]}) | API |
const myshape = roundedRectangle({center: [6.5, 6.5], size: [10, 20], roundRadius: 2, segments: 64}) | API |
const myshape = square({center: [6.5, 6.5], size: 10}) | API |
const myshape = star({vertices: 8, outerRadius: 10}) /* star with 8/2 density */ | API |
const myshape = star({vertices: 12, outerRadius: 40, innerRadius: 20}) /* star with given radius */ | API |
const myshape = triangle({type: 'AAS', values: [degToRad(62), degToRad(35), 7]}) | API |
3D Primitives
Primitive | Notes |
---|---|
const myshape = cube({center: [6.5, 6.5, 6.5], size: 7}) | API |
const myshape = cuboid({center: [6.5, 6.5, 6.5], size: [3, 5, 7]}) | API |
const myshape = cylinder({center: [-5, -5, -5], height: 10, radius: 4, segments: 5}) | API |
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 |
const myshape = ellipsoid({center: [-5, -5, -5], radius: [4, 6, 8], segments: 64}) | API |
const myshape = geodesicSphere({radius: 15, frequency: 18}) | API |
const myshape = polyhedron({points: mypoints, faces: myfaces, orientation: 'inward'}) | API |
const myshape = roundedCuboid({center: [-5, -5, -5], size: [10, 20, 10], roundRadius: 2, segments: 16}) | API |
const myshape = roundedCylinder({center: [-5, -5, -5], height: 10, radius: 2, roundRadius: 0.5, segments: 16}) | API |
const myshape = sphere({center: [-5, -5, -5], radius: 5, }) | API |
const myshape = torus({innerRadius: 10, outerRadius: 100, innerSegments: 32, outerSegments: 8, innerRotation: Math.PI, startAngle: Math.PI}) | API |
Shape Transformations
The 'transforms' are accessed through the modeling API using the following:
const { translate, scale, rotateX } = require('@jscad/modeling').transforms
Transform | Notes |
---|---|
const newshape = align({modes: ['min', 'center', 'none'], relativeTo: [10, null, 10], grouped: true}, oldshape) | API |
const newshape = center({axes: [true, true, false], center: [15, 10, 0]}, oldshape) | API |
const newshape = centerX(oldshape) | API |
const newshape = centerY(oldshape) | API |
const newshape = centerZ(oldshape) | API |
const newshape = mirror({origin: [5, 5, 5], normal: [0, 0, 10]}, oldshape)) | API |
const newshape = mirrorX(oldshape) | API |
const newshape = mirrorY(oldshape) | API |
const newshape = mirrorZ(oldshape) | API |
const newshape = rotate([Math.PI / 4, 0, 0], oldshape) | API |
const newshape = rotateX(oldshape) | API |
const newshape = rotateY(oldshape) | API |
const newshape = rotateZ(oldshape) | API |
const newshape = scale([5, 0, 10], oldshape) | API |
const newshape = scaleX(5, oldshape) | API |
const newshape = scaleY(0.5, oldshape) | API |
const newshape = scaleZ(5, oldshape) | API |
const newshape = transform(mat4.rotateX(Math.PI/4), oldshape) | API |
const newshape = translate([5, 0, 10], oldshape) | API |
const newshape = translateX(5, oldshape) | API |
const newshape = translateY(0.5, oldshape) | API |
const newshape = translateZ(5, oldshape) | API |
Shape Operations
Boolean Operations
The 'booleans' are accessed through the modeling API using the following:
const { union, intersect, scission, subtract } = require('@jscad/modeling').booleans
Hull Operations
Extrusions
The 'extrusions' are accessed through the modeling API using the following:
const { extrudeLinear, extrudeRegtangular, extrudeRotate, project } = require('@jscad/modeling').extrusions
Extrusion of 2D Shapes | Notes |
---|---|
const newshape = extrudeLinear({height: 20, twistAngle: Math.PI, twistSteps: 20}, oldshape)) | API |
const newshape = extrudeRectangular({size: 3, height: 15}, oldshape) | API |
const newshape = extrudeRotate({startAngle: Math.PI, angle: Math.PI / 2, overflow: 'cap', segments: 64}, oldshape) | API |
const newshape = project({axis: [0, 0, 1], origin: [0, 0, 0]}, oldshape) | API |
Expansions
The 'expansions' are accessed through the modeling API using the following:
const { expand, offset } = require('@jscad/modeling').expansions
Text
The 'text' functions are accessed through the modeling API using the following:
const { vectorChar, vectorText } = require('@jscad/modeling').text
General Functions
Colors
The 'colors' are accessed through the modeling API using the following:
const { colorize, hexToRgb } = require('@jscad/modeling').colors
Function | Notes |
---|---|
let newshape = colorize([1, 0, 0], oldshape) | API |
let newshape = colorize(colorNameToRgb('lightblue'), oldshape) | API |
let newshape = colorize(hexToRgb('#000080'), oldshape) | API |
let newshape = colorize(hslToRgb([0.9166666666666666, 1, 0.5]), oldshape) | API |
let newshape = colorize(hsvToRgb([0.9166666666666666, 1, 1]), oldshape) | API |
Utilities
The 'utils' are accessed through the modeling API using the following:
const { radToDeg, degToRad } = require('@jscad/modeling').utils