Class: CSG

CSG

new CSG()

Class CSG Holds a binary space partition tree representing a 3D solid. Two solids can be combined using the `union()`, `subtract()`, and `intersect()` methods.
Source:

Classes

Vector3D

Members

(static) angleEPS

Epsilon used during determination of near zero areas.
Default Value:
  • 0.1
Source:

(static) areaEPS

Epsilon used during determination of near zero areas. This is the minimal area of a minimal polygon.
Source:

(static) defaultResolution2D

Number of polygons per 360 degree revolution for 2D objects.
Default Value:
  • 32
Source:

(static) defaultResolution3D

Number of polygons per 360 degree revolution for 3D objects.
Default Value:
  • 12
Source:

(static) EPS

Epsilon used during determination of near zero distances.
Default Value:
  • 0.00001
Source:

Methods

(static) cube(optionsopt) → {CSG}

Construct an axis-aligned solid cuboid.
Parameters:
Name Type Attributes Description
options Object <optional>
options for construction
Properties
Name Type Attributes Default Description
center Vector3D <optional>
[0,0,0] center of cube
radius Vector3D <optional>
[1,1,1] radius of cube, single scalar also possible
Source:
Returns:
new 3D solid
Type
CSG
Example
var cube = CSG.cube({
  center: [5, 5, 5],
  radius: 5, // scalar radius
});

(static) cylinder(optionsopt) → {CSG}

Construct a solid cylinder.
Parameters:
Name Type Attributes Description
options Object <optional>
options for construction
Properties
Name Type Attributes Default Description
start Vector <optional>
[0,-1,0] start point of cylinder
end Vector <optional>
[0,1,0] end point of cylinder
radius Number <optional>
1 radius of cylinder, must be scalar
resolution Number <optional>
CSG.defaultResolution3D number of polygons per 360 degree revolution
Source:
Returns:
new 3D solid
Type
CSG
Example
var cylinder = CSG.cylinder({
  start: [0, -10, 0],
  end: [0, 10, 0],
  radius: 10,
  resolution: 16
});

(static) cylinderElliptic(optionsopt) → {CSG}

Construct an elliptic cylinder.
Parameters:
Name Type Attributes Description
options Object <optional>
options for construction
Properties
Name Type Attributes Default Description
start Vector3D <optional>
[0,-1,0] start point of cylinder
end Vector3D <optional>
[0,1,0] end point of cylinder
radius Vector2D <optional>
[1,1] radius of rounded ends, must be two dimensional array
radiusStart Vector2D <optional>
[1,1] OPTIONAL radius of rounded start, must be two dimensional array
radiusEnd Vector2D <optional>
[1,1] OPTIONAL radius of rounded end, must be two dimensional array
resolution Number <optional>
CSG.defaultResolution2D number of polygons per 360 degree revolution
Source:
Returns:
new 3D solid
Type
CSG
Example
var cylinder = CSG.cylinderElliptic({
      start: [0, -10, 0],
      end: [0, 10, 0],
      radiusStart: [10,5],
      radiusEnd: [8,3],
      resolution: 16
    });

(static) fromCompactBinary(bin) → {CSG}

Reconstruct a CSG from the output of toCompactBinary().
Parameters:
Name Type Description
bin CompactBinary see toCompactBinary().
Source:
Returns:
new CSG object
Type
CSG

(static) fromObject(obj) → {CSG}

Reconstruct a CSG solid from an object with identical property names.
Parameters:
Name Type Description
obj Object anonymous object, typically from JSON
Source:
Returns:
new CSG object
Type
CSG

(static) fromPolygons(polygons) → {CSG}

Construct a CSG solid from a list of `CSG.Polygon` instances.
Parameters:
Name Type Description
polygons Array.<CSG.Polygon> list of polygons
Source:
Returns:
new CSG object
Type
CSG

(static) fromSlices(options) → {CSG}

Construct a CSG solid from a list of pre-generated slices. See CSG.Polygon.prototype.solidFromSlices() for details.
Parameters:
Name Type Description
options Object options passed to solidFromSlices()
Source:
Returns:
new CSG object
Type
CSG

(static) polyhedron(optionsopt) → {CSG}

Create a polyhedron using Openscad style arguments. Define face vertices clockwise looking from outside.
Parameters:
Name Type Attributes Description
options Object <optional>
options for construction
Source:
Returns:
new 3D solid
Type
CSG

(static) roundedCube(optionsopt) → {CSG}

Construct an axis-aligned solid rounded cuboid.
Parameters:
Name Type Attributes Description
options Object <optional>
options for construction
Properties
Name Type Attributes Default Description
center Vector3D <optional>
[0,0,0] center of rounded cube
radius Vector3D <optional>
[1,1,1] radius of rounded cube, single scalar is possible
roundradius Number <optional>
0.2 radius of rounded edges
resolution Number <optional>
CSG.defaultResolution3D number of polygons per 360 degree revolution
Source:
Returns:
new 3D solid
Type
CSG
Example
var cube = CSG.roundedCube({
  center: [2, 0, 2],
  radius: 15,
  roundradius: 2,
  resolution: 36,
});

(static) roundedCylinder(optionsopt) → {CSG}

Construct a cylinder with rounded ends.
Parameters:
Name Type Attributes Description
options Object <optional>
options for construction
Properties
Name Type Attributes Default Description
start Vector3D <optional>
[0,-1,0] start point of cylinder
end Vector3D <optional>
[0,1,0] end point of cylinder
radius Number <optional>
1 radius of rounded ends, must be scalar
normal Vector3D <optional>
vector determining the starting angle for tesselation. Should be non-parallel to start.minus(end)
resolution Number <optional>
CSG.defaultResolution3D number of polygons per 360 degree revolution
Source:
Returns:
new 3D solid
Type
CSG
Example
var cylinder = CSG.roundedCylinder({
  start: [0, -10, 0],
  end: [0, 10, 0],
  radius: 2,
  resolution: 16
});

(static) sphere(optionsopt) → {CSG}

Construct a solid sphere
Parameters:
Name Type Attributes Description
options Object <optional>
options for construction
Properties
Name Type Attributes Default Description
center Vector3D <optional>
[0,0,0] center of sphere
radius Number <optional>
1 radius of sphere
resolution Number <optional>
CSG.defaultResolution3D number of polygons per 360 degree revolution
axes Array <optional>
an array with 3 vectors for the x, y and z base vectors
Source:
Returns:
new 3D solid
Type
CSG
Example
var sphere = CSG.sphere({
  center: [0, 0, 0],
  radius: 2,
  resolution: 32,
});

toPolygons() → {Array.<CSG.Polygon>}

Source:
Returns:
The list of polygons.
Type
Array.<CSG.Polygon>