From c684ea353dcdeb41b8be9d8c9ea854a71a1993c2 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Sat, 16 Feb 2019 00:55:35 -0800 Subject: [PATCH] Added EDGE constants to constants.scad. --- constants.scad | 47 +++++++++++++++++++++++++++++++++++++++++++++++ masks.scad | 31 ++++++++++++++++--------------- 2 files changed, 63 insertions(+), 15 deletions(-) diff --git a/constants.scad b/constants.scad index 434fcd4..dc819f1 100644 --- a/constants.scad +++ b/constants.scad @@ -40,4 +40,51 @@ V_DOWN = [ 0, 0, -1]; V_UP = [ 0, 0, 1]; +// Constants for defining edges for chamfer(), etc. +EDGE_TOP_BK = [[1,0,0,0], [0,0,0,0], [0,0,0,0]]; +EDGE_TOP_FR = [[0,1,0,0], [0,0,0,0], [0,0,0,0]]; +EDGE_BOT_FR = [[0,0,1,0], [0,0,0,0], [0,0,0,0]]; +EDGE_BOT_BK = [[0,0,0,1], [0,0,0,0], [0,0,0,0]]; + +EDGE_TOP_RT = [[0,0,0,0], [1,0,0,0], [0,0,0,0]]; +EDGE_TOP_LF = [[0,0,0,0], [0,1,0,0], [0,0,0,0]]; +EDGE_BOT_LF = [[0,0,0,0], [0,0,1,0], [0,0,0,0]]; +EDGE_BOT_RT = [[0,0,0,0], [0,0,0,1], [0,0,0,0]]; + +EDGE_BK_RT = [[0,0,0,0], [0,0,0,0], [1,0,0,0]]; +EDGE_BK_LF = [[0,0,0,0], [0,0,0,0], [0,1,0,0]]; +EDGE_FR_LF = [[0,0,0,0], [0,0,0,0], [0,0,1,0]]; +EDGE_FR_RT = [[0,0,0,0], [0,0,0,0], [0,0,0,1]]; + +EDGES_X_TOP = [[1,1,0,0], [0,0,0,0], [0,0,0,0]]; +EDGES_X_BOT = [[0,0,1,1], [0,0,0,0], [0,0,0,0]]; +EDGES_X_FR = [[0,1,1,0], [0,0,0,0], [0,0,0,0]]; +EDGES_X_BK = [[1,0,0,1], [0,0,0,0], [0,0,0,0]]; +EDGES_X_ALL = [[1,1,1,1], [0,0,0,0], [0,0,0,0]]; + +EDGES_Y_TOP = [[0,0,0,0], [1,1,0,0], [0,0,0,0]]; +EDGES_Y_BOT = [[0,0,0,0], [0,0,1,1], [0,0,0,0]]; +EDGES_Y_LF = [[0,0,0,0], [0,1,1,0], [0,0,0,0]]; +EDGES_Y_RT = [[0,0,0,0], [1,0,0,1], [0,0,0,0]]; +EDGES_Y_ALL = [[0,0,0,0], [1,1,1,1], [0,0,0,0]]; + +EDGES_Z_BK = [[0,0,0,0], [0,0,0,0], [1,1,0,0]]; +EDGES_Z_FR = [[0,0,0,0], [0,0,0,0], [0,0,1,1]]; +EDGES_Z_LF = [[0,0,0,0], [0,0,0,0], [0,1,1,0]]; +EDGES_Z_RT = [[0,0,0,0], [0,0,0,0], [1,0,0,1]]; +EDGES_Z_ALL = [[0,0,0,0], [0,0,0,0], [1,1,1,1]]; + +EDGES_LEFT = [[0,0,0,0], [0,1,1,0], [0,1,1,0]]; +EDGES_RIGHT = [[0,0,0,0], [1,0,0,1], [1,0,0,1]]; + +EDGES_FRONT = [[0,1,1,0], [0,0,0,0], [0,0,1,1]]; +EDGES_BACK = [[1,0,0,1], [0,0,0,0], [1,1,0,0]]; + +EDGES_BOTTOM = [[0,0,1,1], [0,0,1,1], [0,0,0,0]]; +EDGES_TOP = [[1,1,0,0], [1,1,0,0], [0,0,0,0]]; + +EDGES_NONE = [[0,0,0,0], [0,0,0,0], [0,0,0,0]]; +EDGES_ALL = [[1,1,1,1], [1,1,1,1], [1,1,1,1]]; + + // vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap diff --git a/masks.scad b/masks.scad index 3d4b06f..8776742 100644 --- a/masks.scad +++ b/masks.scad @@ -126,16 +126,17 @@ module chamfer_mask_x(l=1.0, chamfer=1.0) { // Chamfers the edges of a cuboid region containing the given children. -// chamfer = inset of the chamfer from the edge. (Default: 1) +// chamfer = Inset of the chamfer from the edge. (Default: 1) // size = The size of the rectangular cuboid we want to chamfer. -// edges = which edges do we want to chamfer. +// edges = Which edges do we want to chamfer. Recommend to use EDGE constants from constants.scad. // [ // [Y+Z+, Y-Z+, Y-Z-, Y+Z-], // [X+Z+, X-Z+, X-Z-, X+Z-], // [X+Y+, X-Y+, X-Y-, X+Y-] // ] // Example: -// chamfer(chamfer=2, size=[10,40,30], edges=[[0,0,0,1], [1,1,0,0], [0,0,0,0]]) { +// include +// chamfer(chamfer=2, size=[10,40,30], edges=EDGE_BOT_BK + EDGE_TOP_RT + EDGE_TOP_LF) { // cube(size=[10,40,30], center=true); // } module chamfer(chamfer=1, size=[1,1,1], edges=[[0,0,0,0], [1,1,0,0], [0,0,0,0]]) @@ -152,31 +153,31 @@ module chamfer(chamfer=1, size=[1,1,1], edges=[[0,0,0,0], [1,1,0,0], [0,0,0,0]]) children(); } union() { - if (edges[0][0] != 0) + if (edges[0][0] > 0) up(z/2) back(y/2) chamfer_mask_x(l=lx, chamfer=chamfer); - if (edges[0][1] != 0) + if (edges[0][1] > 0) up(z/2) fwd(y/2) chamfer_mask_x(l=lx, chamfer=chamfer); - if (edges[0][2] != 0) + if (edges[0][2] > 0) down(z/2) back(y/2) chamfer_mask_x(l=lx, chamfer=chamfer); - if (edges[0][3] != 0) + if (edges[0][3] > 0) down(z/2) fwd(y/2) chamfer_mask_x(l=lx, chamfer=chamfer); - if (edges[1][0] != 0) + if (edges[1][0] > 0) up(z/2) right(x/2) chamfer_mask_y(l=ly, chamfer=chamfer); - if (edges[1][1] != 0) + if (edges[1][1] > 0) up(z/2) left(x/2) chamfer_mask_y(l=ly, chamfer=chamfer); - if (edges[1][2] != 0) + if (edges[1][2] > 0) down(z/2) right(x/2) chamfer_mask_y(l=ly, chamfer=chamfer); - if (edges[1][3] != 0) + if (edges[1][3] > 0) down(z/2) left(x/2) chamfer_mask_y(l=ly, chamfer=chamfer); - if (edges[2][0] != 0) + if (edges[2][0] > 0) back(y/2) right(x/2) chamfer_mask_z(l=lz, chamfer=chamfer); - if (edges[2][1] != 0) + if (edges[2][1] > 0) back(y/2) left(x/2) chamfer_mask_z(l=lz, chamfer=chamfer); - if (edges[2][2] != 0) + if (edges[2][2] > 0) fwd(y/2) right(x/2) chamfer_mask_z(l=lz, chamfer=chamfer); - if (edges[2][3] != 0) + if (edges[2][3] > 0) fwd(y/2) left(x/2) chamfer_mask_z(l=lz, chamfer=chamfer); } }