openSCAD Techniques, Tricks, and Hacks

Epsilon!

Here’s a pretty basic technique. Once you start using openSCAD, it won’t take long before you create a model that won’t render.

Here’s a very simple example:

cube ([10,10,10], center=true);
translate([10,0,0]) cylinder (h=10, d=10, center=true);

If you cut/paste this snippet into openSCAD and try to render it, you’ll get this message:

UI-WARNING: Object may not be a valid 2-manifold and may need repair!

The problem is that the cube and cylinder intersect along a line - that they touch but do not overlap. The same thing will happen at point intersections as well, and when adjacent holes just touch.
The solution is to define a special variable - I always call it “epsilon” that is small enough that when you use it it does not damage your model, and use it to force the objects to overlap or to be separate. (Just how to include it can involve some thought if your model is complex).

Here’s the same bit of code, but using epsilon to avoid the geometric ambiguity.

epsilon=0.001;
cube ([10,10,10], center=true);
translate([10-epsilon,0,0]) cylinder (h=10, d=10, center=true);

1 Like