Primitives provide the building blocks for complex parts. Each primitive is a geometrical object that can be described mathematically, and therefore precise. Primitives can be logically combined, transformed, extruded, etc.
- Source:
Example
const { cube, ellipse, star } = require('@jscad/modeling').primitives
Methods
(static) arc(optionsopt) → {path2}
- Source:
Construct an arc in two dimensional space where all points are at the same distance from the center.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 2D path
- Type
- path2
(static) circle(optionsopt) → {geom2}
- Source:
- See:
-
ellipse for more options
Construct a circle in two dimensional space where all points are at the same distance from the center.
Example
let myshape = circle({radius: 10})
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 2D geometry
- Type
- geom2
(static) cube(optionsopt) → {geom3}
- Source:
- See:
-
cuboid for more options
Construct an axis-aligned solid cube in three dimensional space with six square faces.
Example
let myshape = cube({size: 10})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 3D geometry
- Type
- geom3
(static) cuboid(optionsopt) → {geom3}
- Source:
Construct an axis-aligned solid cuboid in three dimensional space.
Example
let myshape = cuboid({size: [5, 10, 5]})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 3D geometry
- Type
- geom3
(static) cylinder(optionsopt) → {geom3}
- Source:
- See:
-
cylinderElliptic for more options
Construct a Z axis-aligned cylinder in three dimensional space.
Example
let myshape = cylinder({height: 2, radius: 10})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new geometry
- Type
- geom3
(static) cylinderElliptic(optionsopt) → {geom3}
Construct a Z axis-aligned elliptic cylinder in three dimensional space.
Example
let myshape = cylinderElliptic({height: 2, startRadius: [10,5], endRadius: [8,3]})
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new geometry
- Type
- geom3
(static) ellipse(optionsopt) → {geom2}
Construct an axis-aligned ellipse in two dimensional space.
Example
let myshape = ellipse({radius: [5,10]})
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 2D geometry
- Type
- geom2
(static) ellipsoid(optionsopt) → {geom3}
Construct an axis-aligned ellipsoid in three dimensional space.
Example
let myshape = ellipsoid({radius: [5, 10, 20]})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 3D geometry
- Type
- geom3
(static) geodesicSphere(optionsopt) → {geom3}
Construct a geodesic sphere based on icosahedron symmetry.
Example
let myshape = geodesicSphere({radius: 15, frequency: 18})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 3D geometry
- Type
- geom3
(static) line(points) → {path2}
- Source:
Construct a new line in two dimensional space from the given points. The points must be provided as an array, where each element is a 2D point.
Example
let myshape = line([[10, 10], [-10, 10]])
Parameters:
Name | Type | Description |
---|---|---|
points |
Array | array of points from which to create the path |
Returns:
new 2D path
- Type
- path2
(static) polygon(options) → {geom2}
Construct a polygon in two dimensional space from a list of points, or a list of points and paths.
NOTE: The ordering of points is important, and must define a counter clockwise rotation of points.
Example
let roof = [[10,11], [0,11], [5,20]]
let wall = [[0,0], [10,0], [10,10], [0,10]]
let poly = polygon({ points: roof })
or
let poly = polygon({ points: [roof, wall] })
or
let poly = polygon({ points: roof, paths: [0, 1, 2] })
or
let poly = polygon({ points: [roof, wall], paths: [[0, 1, 2], [3, 4, 5, 6]] })
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | options for construction Properties
|
Returns:
new 2D geometry
- Type
- geom2
(static) polyhedron(options) → {geom3}
Construct a polyhedron in three dimensional space from the given set of 3D points and faces. The faces can define outward or inward facing polygons (orientation). However, each face must define a counter clockwise rotation of points which follows the right hand rule.
Example
let mypoints = [ [10, 10, 0], [10, -10, 0], [-10, -10, 0], [-10, 10, 0], [0, 0, 10] ]
let myfaces = [ [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [1, 0, 3], [2, 1, 3] ]
let myshape = polyhedron({points: mypoint, faces: myfaces, orientation: 'inward'})
Parameters:
Name | Type | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | options for construction Properties
|
Returns:
new 3D geometry
- Type
- geom3
(static) rectangle(optionsopt) → {geom2}
Construct an axis-aligned rectangle in two dimensional space with four sides at right angles.
Example
let myshape = rectangle({size: [10, 20]})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 2D geometry
- Type
- geom2
(static) roundedCuboid(optionsopt) → {geom3}
Construct an axis-aligned solid cuboid in three dimensional space with rounded corners.
Example
let mycube = roundedCuboid({size: [10, 20, 10], roundRadius: 2, segments: 16})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 3D geometry
- Type
- geom3
(static) roundedCylinder(optionsopt) → {geom3}
Construct a Z axis-aligned solid cylinder in three dimensional space with rounded ends.
Example
let myshape = roundedCylinder({ height: 10, radius: 2, roundRadius: 0.5 })
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 3D geometry
- Type
- geom3
(static) roundedRectangle(optionsopt) → {geom2}
Construct an axis-aligned rectangle in two dimensional space with rounded corners.
Example
let myshape = roundedRectangle({size: [10, 20], roundRadius: 2})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 2D geometry
- Type
- geom2
(static) sphere(optionsopt) → {geom3}
- Source:
- See:
-
ellipsoid for more options
Construct a sphere in three dimensional space where all points are at the same distance from the center.
Example
let myshape = sphere({radius: 5})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 3D geometry
- Type
- geom3
(static) square(optionsopt) → {geom2}
- Source:
- See:
-
rectangle for more options
Construct an axis-aligned square in two dimensional space with four equal sides at right angles.
Example
let myshape = square({size: 10})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 2D geometry
- Type
- geom2
(static) star(optionsopt) → {geom2}
Construct a star in two dimensional space.
Example
let star1 = star({vertices: 8, outerRadius: 10}) // star with 8/2 density
let star2 = star({vertices: 12, outerRadius: 40, innerRadius: 20}) // star with given radius
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 2D geometry
- Type
- geom2
(static) torus(optionsopt) → {geom3}
- Source:
Construct a torus by revolving a small circle (inner) about the circumference of a large (outer) circle.
Example
let myshape = torus({ innerRadius: 10, outerRadius: 100 })
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 3D geometry
- Type
- geom3
(static) triangle(optionsopt) → {geom2}
- Source:
- See:
Construct a triangle in two dimensional space from the given options. The triangle is always constructed CCW from the origin, [0, 0, 0].
Example
let myshape = triangle({type: 'AAS', values: [degToRad(62), degToRad(35), 7]})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
options for construction Properties
|
Returns:
new 2D geometry
- Type
- geom2