openscad

Way to round edges of objects opensCAD


Is there an easy way/function to round edges for an openscad object?

e.g. round the edges of the cylinders


Solution

  • minkowski() sums geometric objects (whether 2D or 3D) and can be used to round out sharp edges.

    You can think of it like this: to sum objects A + B, for each particle of A, draw the whole object B. So taking a 3D object, if you minkowski sum it with a small sphere, it will round out all the outer edges (while also making the whole object larger by the radius of the sphere.) Similarly with 2D objects, sum with a small circle.

    minkowski() can also incredibly slow, so be careful of how many times it gets called. In this example, I implement it only on the top-level object:

    $fn=60;
    
    module drawLedgeRing()
    {
        difference()
        {
            cylinder(4,10,10);
            translate([0,0,-1]) cylinder(4,6,6);
            translate([0,0,2]) cylinder(4,8,8);
        }
    }
    
    minkowski()
    {
        drawLedgeRing();
        sphere(.25);
    }
    
    //drawLedgeRing();
    

    Here is the above, with and without the minkowski step:

    A 3D geometry, with and without minkowski sum with a sphere

    For some shapes, like this one, you can get the same result way more efficiently by doing the minkowski in 2D, then rotate-extruding the result. Notice the symmetry of the 2D / 3D code:

    module ledgeProfile() {
      difference() {
        square([10,4]);
        translate([0,-1]) square([6,4]);
        translate([0,2]) square([8,4]);
      }
    }
    
    module roundedProfile() {
      minkowski() {
        ledgeProfile();
        circle(.25);
      }
    }
    
    rotate_extrude() roundedProfile();
    

    Using minkowski in 2D for faster result