meta data for this page
  •  

This is an old revision of the document!


3D Primitives

‘3D’ stands for three (3) dimensional. A 3D primitive is any shape that has three dimensions, which are often called width, depth, and height (or X, Y, Z.) 3D shapes have a known volume if closed.


The mathematical study of 3D shapes and dimensions is called solid geometry.

Resolution of Shapes

All rounded shapes have a resolution option which controls tesselation. If resolution is set to 8, then 8 polygons are used to create 360 degrees of revolution.

This allows each design to control the amount of detail present, but beware that calculations and rendering time will also increase. For example, the number of polygons increases quadratically with each increase of the resolution for spheres.

EXAMPLE

If the resolution option is omitted, the following resolution is used.

  • CSG.defaultResolution3D = 12

OpenSCAD like functions support the fn parameter, which is the same as resolution.

Cylinder

A three dimensional shape with two flat ends that are circular. The cylinder has the same cross-section from one end to the other, extending about the Z axis.


Learn about cylinders at MathIsFun.com

The radius specifies the circular size about the Z axis, while the height specifies the size. Cylinders can be created at a requested center. The segments specify the number of segments to create per full rotation.

Defaults:

  • radius : 1
  • height : 2
  • center : [0, 0, 0]
  • segments : 32
const { cylinder } = require('@jscad/modeling').primitives
 
const myshape = cylinder({radius: 5, height: 10})
const myshape = cylinder({radius: 5, height: 10, center: [5, 5, 5], segments: 64})

Elliptical Cylinder

 Cylinder Elliptic

Various cylindrical shapes can be created using the elliptical cylinder, including cylinders with changing radius (cones).

Defaults:

  • height : 2
  • startRadius : [1, 1]
  • endRadius : [1, 1]
  • center : [0, 0, 0]
  • segments : 32
  • startAngle : 0
  • endAngle : PI * 2
const { cylinderElliptic } = require('@jscad/modeling').primitives
 
const myshape = cylinderElliptic({height: 2, startRadius: [10, 5], endRadius: [8, 3]})

Rounded Cylinder

 Rounded Cylinder

Cylinders can be created with rounded ends by specifying roundRadius.

Defaults:

  • radius : 1
  • height : 2
  • roundRadius: 0.5
  • center : [0, 0, 0]
  • segments : 32
const { roundedCylinder } = require('@jscad/modeling').primitives
 
const myshape = roundedCylinder({radius: 5, height: 10, roundRadius: 0.5})
const myshape = roundedCylinder({radius: 5, height: 10, roundRadius: 0.5, center: [5, 5, 5], segments: 64})

Torus

A three dimensional shape made by revolving a small circle (inner) along the circumference a bigger circle (outer).


Learn about torus at MathIsFun.com

A torus is defined as such:

  • Inner Circle
    • inner radius
    • inner rotation before rotating about the outer circle
    • inner segments
  • Outer Circle
    • outer radius
    • outer segments
  • Rotation
    • start angle of rotation
    • outer rotation

Defaults:

  • innerRadius : 1
  • innerRotation : 0
  • innerSegments : 32
  • outerRadius : 4
  • outerSegments : 32
  • startAngle : 0
  • outerRotation : PI * 2
const { torus } = require('@jscad/modeling').primitives
 
const myshape = torus({innerRadius: 10, outerRadius: 100})

Polyhedron

A three dimensional shape where connecting faces create a solid. Each face is a three dimensional polygon (a flat shape with straight sides).

Learn about polyhedrons at MathIsFun.com

Create a polyhedron from a list of points and a list of faces. The points list all the vertexes of the shape, while the faces define the points used within each face.

Note: The order of the points must be consistent, defining 'inward' or 'outward' facing polygons.

const { polyhedron } = require('@jscad/modeling').primitives
 
const points = [ [10, 10, 0], [10, -10, 0], [-10, -10, 0], [-10, 10, 0], [0, 0, 10] ]
const faces = [ [0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 4], [1, 0, 3], [2, 1, 3] ]
const myshape = polyhedron({points, faces, orientation: 'inward'})