OpenSCAD User Manual/CSG Modelling

From Wikibooks, open books for an open world
< OpenSCAD User Manual
Jump to: navigation, search


union[edit]

Creates a union of all its child nodes. This is the sum of all children.

Usage example:
union() {
        cylinder (h = 4, r=1, center = true, $fn=100);
        rotate ([90,0,0]) cylinder (h = 4, r=0.9, center = true, $fn=100);
}

Remark: union is implicit when not used. But it is mandatory, for example, in difference to group first child nodes into one.

Union

difference[edit]

Subtracts the 2nd (and all further) child nodes from the first one.

Usage example:
difference() {
        cylinder (h = 4, r=1, center = true, $fn=100);
        rotate ([90,0,0]) cylinder (h = 4, r=0.9, center = true, $fn=100);
}


Difference


intersection[edit]

Creates the intersection of all child nodes. This keeps the overlapping portion

Usage example:
intersection() {
        cylinder (h = 4, r=1, center = true, $fn=100);
        rotate ([90,0,0]) cylinder (h = 4, r=0.9, center = true, $fn=100);
}


Intersection


render[edit]

Always calculate the CSG model for this tree (even in OpenCSG preview mode).

Usage example:
render(convexity = 1) { ... }


convexity Integer. The convexity parameter specifies the maximum number of front sides (back sides) a ray intersecting the object might penetrate. This parameter is only needed for correctly displaying the object in OpenCSG preview mode and has no effect on the polyhedron rendering.


Openscad convexity.jpg

This image shows a 2D shape with a convexity of 4, as the ray indicated in red crosses the 2D shape a maximum of 4 times. The convexity of a 3D shape would be determined in a similar way. Setting it to 10 should work fine for most cases.