User:LABoyd2/Boolean 150919

2D examples
union      {square(10);circle(10);} // square and circle difference {square(10);circle(10);} // square and not circle difference {circle(10);square(10);} // circle and not square intersection{square(10);circle(10);} // square and circle

3D examples
union      {cube(12, center=true); sphere(8);} // cube and sphere difference {cube(12, center=true); sphere(8);} // cube and not sphere difference {sphere(8); cube(12, center=true);} // sphere and not cube intersection{cube(12, center=true); sphere(8);} // cube and sphere

union
Creates a union of all its child nodes. This is the sum of all children (logical or).

May be used with either 2D or 3D objects, but don't mix them.



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. Alias for group.

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

May be used with either 2D or 3D objects, but don't mix them.



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 with multiple children
Note the effect of adding a union in the second instance.



Usage example for difference of multiple children: $fn=90; difference{ cylinder(r=5,h=20,center=true); rotate([00,140,-45]) color("LightBlue") cylinder(r=2,h=25,center=true); rotate([00,40,-50])                    cylinder(r=2,h=30,center=true); translate([0,0,-10])rotate([00,40,-50]) cylinder(r=1.4,h=30,center=true); } translate([10,10,0]){ difference{ union{       // combine 1st and 2nd children cylinder(r=5,h=20,center=true); rotate([00,140,-45]) color("LightBlue") cylinder(r=2,h=25,center=true); }     rotate([00,40,-50])                       cylinder(r=2,h=30,center=true); translate([0,0,-10])rotate([00,40,-50])  cylinder(r=1.4,h=30,center=true); } }

intersection
Creates the intersection of all child nodes. This keeps the overlapping portion (logical and).

Only the area which is common or shared by all children is retained.

May be used with either 2D or 3D objects, but don't mix them.



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); }

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

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



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.