### User Tools

This is an old revision of the document!

## 3D Primitives

Introduction

### 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

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

### Cuboid

A three dimensional shape created from six retangular faces, each at right angles to another, and opposite faces are equal. The cube is a special case of the a cuboid in which all six faces are squares.

Cubes can be created at a requested center. The radius specifies the size of the faces. Cubes with different radius for X, Y and Z axis can be specified by supplying an array of values.

Defaults:

• size : 1 or [1,1,1]
• center : [0,0,0]
• round: false
```cube({size: 1})
cube({size: [1,2,3]})
cube({size: 1, center: true}) // default center:false
cube({size: 1, center: [false,false,false]}) // individual axis center true or false
cube({size: [1,2,3], round: true})```

Also, the CSG library functions can be used directly. NOTE Deprecated in the V2 API

```CSG.cube({
center: [0, 0, 0],
})

CSG.cube({ // define two opposite corners
corner1: [4, 4, 4],
corner2: [5, 4, 2]
})```

Rounded cubes are created by specifying a rounded radius for the corners and the sides.

```CSG.roundedCube({ // rounded cube
center: [0, 0, 0],
resolution: 8,
});```

### Sphere

A three dimensional shape like a ball, where every point on the surface is the same distance from the center.

Creates a sphere at the requested center. The radius argument determines the size of the sphere. The resolution option determines the number of segments to create in 360 degrees of rotation.

Note: See the start of 3D Primitives for information about the resolution of three dimenional shapes.

Defaults:

• radius : 1 or [1,1,1]
• center : [0,0,0]
• resolution : Resolution3D (12)
```sphere(1);
sphere({r: 2});                    // Note: center:true is default (unlike other primitives, as OpenSCAD)
sphere({r: 2, center: true});     // Note: OpenSCAD doesn't support center for sphere but we do
sphere({r: 2, center: [false, false, true]}); // individual axis center
sphere({r: 10, fn: 100 });
sphere({r: 10, fn: 100, type: 'geodesic'});  // geodesic approach (icosahedron further triangulated)```

In case of ``type: 'geodesic'`` the fn tries to match the non-geodesic fn, yet, actually changes in steps of 6 (e.g. fn=6..11 is the same), fn = 1 reveals the base form: the icosahedron.

The CSG library functions can also be used. NOTE Deprecated in the V2 API

```CSG.sphere({
center: [0, 0, 0],
radius: 2,                      // must be scalar
resolution: 128
});```

### Cylinder

Cylinders and cones can be created like this:

```cylinder({r: 1, h: 10});                 // openscad like
cylinder({d: 1, h: 10});
cylinder({r: 1, h: 10, center: true});   // default: center:false
cylinder({r: 1, h: 10, center: [true, true, false]});  // individual x,y,z center flags
cylinder({r: 1, h: 10, round: true});
cylinder({r1: 3, r2: 0, h: 10});
cylinder({d1: 1, d2: 0.5, h: 10});
cylinder({start: [0,0,0], end: [0,0,10], r1: 1, r2: 2, fn: 50});

CSG.cylinder({                      //using the CSG primitives
start: [0, -1, 0],
end: [0, 1, 0],
resolution: 16
});
CSG.cylinder({
start: [0, -1, 0],
end: [0, 1, 0],
resolution: 16
});
CSG.roundedCylinder({               // and its rounded version
start: [0, -1, 0],
end: [0, 1, 0],
resolution: 16
});```

### Torus

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

A torus is defined as such:

• Inner Circle
• fni = inner resolution
• roti = inner rotation
• Outer Circle
• fno = outer resolution

Note: See the start of 3D Primitives for information about the resolution of three dimensional shapes.

Defaults:

• ri : 1
• fni : 16
• roti : 0
• ro : 4
• fno : 32
```torus()
torus({ ri: 1.5, ro: 3 })
torus({ ri: 0.2 })

torus({ fni:4 })           // make inner circle fn = 4 => square
torus({ fni:4,roti:45 })   // rotate inner circle, so flat is top/bottom
torus({ fni:4,fno:4,roti:45 })
torus({ fni:4,fno:5,roti:45 })```