From 70f268775c132e2f726b1650a48bc0888b64cf38 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Wed, 27 Feb 2019 03:50:16 -0800 Subject: [PATCH] Cleaned up fillet() code. --- masks.scad | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/masks.scad b/masks.scad index 8c03c6c..b7d7d95 100644 --- a/masks.scad +++ b/masks.scad @@ -31,9 +31,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -include -include -include +use +use +use +include module angle_half_pie_mask( @@ -301,55 +302,42 @@ module fillet(fillet=1, size=[1,1,1], edges=[[0,0,0,0], [1,1,0,0], [0,0,0,0]]) rx = x - 2*fillet; ry = y - 2*fillet; rz = z - 2*fillet; - offsets = [ - [[0, 1, 1], [ 0,-1, 1], [ 0,-1,-1], [0, 1,-1]], - [[1, 0, 1], [-1, 0, 1], [-1, 0,-1], [1, 0,-1]], - [[1, 1, 0], [-1, 1, 0], [-1,-1, 0], [1,-1, 0]] - ]; - corners = [ - edges[0][2] + edges[1][2] + edges[2][2], - edges[0][2] + edges[1][3] + edges[2][3], - edges[0][3] + edges[1][2] + edges[2][1], - edges[0][3] + edges[1][3] + edges[2][0], - edges[0][1] + edges[1][1] + edges[2][2], - edges[0][1] + edges[1][0] + edges[2][3], - edges[0][0] + edges[1][1] + edges[2][1], - edges[0][0] + edges[1][0] + edges[2][0] - ]; majrots = [[0,90,0], [90,0,0], [0,0,0]]; sides = quantup(segs(fillet),4); sc = 1/cos(180/sides); - $fn = sides; difference() { children(); + + // Round edges. for (axis=[0:2], i=[0:3]) { if (edges[axis][i]>0) { difference() { - translate(vmul(offsets[axis][i], [lx,ly,lz]/2)) { + translate(vmul(EDGE_OFFSETS[axis][i], [lx,ly,lz]/2)) { rotate(majrots[axis]) { cube([fillet*2, fillet*2, size[axis]+eps], center=true); } } - translate(vmul(offsets[axis][i], [rx,ry,rz]/2)) { + translate(vmul(EDGE_OFFSETS[axis][i], [rx,ry,rz]/2)) { rotate(majrots[axis]) { - zrot(180/sides) cylinder(h=size[axis]+eps*2, r=fillet*sc, center=true); + zrot(180/sides) cylinder(h=size[axis]+eps*2, r=fillet*sc, center=true, $fn=sides); } } } } } - for (za=[0,1], ya=[0,1], xa=[0,1]) { - idx = xa + 2*ya + 4*za; - if (corners[idx] > 2) { + + // Round corners. + for (za=[-1,1], ya=[-1,1], xa=[-1,1]) { + if (corner_edge_count(edges, [xa,ya,za]) > 2) { difference() { - translate([(xa-0.5)*lx, (ya-0.5)*ly, (za-0.5)*lz]) { + translate(vmul([xa,ya,za]/2, [lx,ly,lz])) { cube(fillet*2, center=true); } - translate([(xa-0.5)*rx, (ya-0.5)*ry, (za-0.5)*rz]) { + translate(vmul([xa,ya,za]/2, [rx,ry,rz])) { zrot(180/sides) { rotate_extrude(convexity=2) { difference() { - zrot(180/sides) circle(r=fillet*sc*sc); + zrot(180/sides) circle(r=fillet*sc*sc, $fn=sides); left(fillet*2) square(fillet*2*2, center=true); } }