diff --git a/printed/butt_box.scad b/printed/butt_box.scad index 1dc79cc..b2fb650 100644 --- a/printed/butt_box.scad +++ b/printed/butt_box.scad @@ -110,12 +110,9 @@ function fixing_block_positions(type) = let( function side_holes(type) = [for(p = fixing_block_positions(type), q = fixing_block_holes(bbox_screw(type))) p * q]; -module drill_holes(type, t) - for(list = [corner_holes(type), side_holes(type)], p = list) - let(q = t * p) - if(abs(transform([0, 0, 0], q).z) < eps) - multmatrix(q) - drill(screw_clearance_radius(bbox_screw(type)), 0); +module bbox_drill_holes(type, t) + position_children(concat(corner_holes(type), side_holes(type)), t) + drill(screw_clearance_radius(bbox_screw(type)), 0); module bbox_base_blank(type) { //! 2D template for the base dxf(str(bbox_name(type), "_base")); @@ -123,7 +120,7 @@ module bbox_base_blank(type) { //! 2D template for the base difference() { sheet_2D(bbox_base_sheet(type), bbox_width(type), bbox_depth(type), 1); - drill_holes(type, translate(bbox_height(type) / 2)); + bbox_drill_holes(type, translate(bbox_height(type) / 2)); } } @@ -136,7 +133,7 @@ module bbox_top_blank(type) { //! 2D template for the top translate([0, t / 2]) sheet_2D(bbox_top_sheet(type), bbox_width(type) + 2 * t, bbox_depth(type) + t); - drill_holes(type, translate(-bbox_height(type) / 2)); + bbox_drill_holes(type, translate(-bbox_height(type) / 2)); } } @@ -154,7 +151,7 @@ module bbox_left_blank(type, sheet = false) { //! 2D template for the left side translate([-t / 2, -bb / 2]) sheet_2D(subst_sheet(type, sheet), bbox_depth(type) + t, bbox_height(type) + bb); - drill_holes(type, rotate([0, 90, 90]) * translate([bbox_width(type) / 2, 0])); + bbox_drill_holes(type, rotate([0, 90, 90]) * translate([bbox_width(type) / 2, 0])); } } @@ -168,7 +165,7 @@ module bbox_right_blank(type, sheet = false) { //! 2D template for the right sid translate([t / 2, -bb / 2]) sheet_2D(subst_sheet(type, sheet), bbox_depth(type) + t, bbox_height(type) + bb); - drill_holes(type, rotate([0, 90, 90]) * translate([-bbox_width(type) / 2, 0])); + bbox_drill_holes(type, rotate([0, 90, 90]) * translate([-bbox_width(type) / 2, 0])); } } @@ -183,7 +180,7 @@ module bbox_front_blank(type, sheet = false, width = 0) { //! 2D template for th translate([0, (bt - bb) / 2]) sheet_2D(subst_sheet(type, sheet), max(bbox_width(type) + 2 * t, width), bbox_height(type) + bb + bt); - drill_holes(type, rotate([-90, 0, 0]) * translate([0, bbox_depth(type) / 2])); + bbox_drill_holes(type, rotate([-90, 0, 0]) * translate([0, bbox_depth(type) / 2])); } } @@ -197,7 +194,7 @@ module bbox_back_blank(type, sheet = false) { //! 2D template for the back translate([0, -bb / 2]) sheet_2D(subst_sheet(type, sheet), bbox_width(type), bbox_height(type) + bb); - drill_holes(type, rotate([-90, 0, 0]) * translate([0, -bbox_depth(type) / 2])); + bbox_drill_holes(type, rotate([-90, 0, 0]) * translate([0, -bbox_depth(type) / 2])); } } diff --git a/readme.md b/readme.md index f89ec4c..e3c18dd 100644 --- a/readme.md +++ b/readme.md @@ -5231,6 +5231,11 @@ Maths utilities for manipulating vectors and matrices. | ```vec3(v)``` | Return a 3 vector with the first three elements of ```v``` | | ```vec4(v)``` | Return a 4 vector with the first three elements of ```v``` | +### Modules +| Module | Description | +|:--- |:--- | +| ```position_children(list, t)``` | Position children if they are on the Z = 0 plane when transformed by t | + ![maths](tests/png/maths.png) diff --git a/utils/maths.scad b/utils/maths.scad index e83ac73..e8db429 100644 --- a/utils/maths.scad +++ b/utils/maths.scad @@ -90,6 +90,14 @@ function euler(R) = let(ay = asin(-R[2][0]), cy = cos(ay)) //! Convert a rotatio cy ? [ atan2(R[2][1] / cy, R[2][2] / cy), ay, atan2(R[1][0] / cy, R[0][0] / cy) ] : R[2][0] < 0 ? [atan2( R[0][1], R[0][2]), 180, 0] : [atan2(-R[0][1], -R[0][2]), -180, 0]; + +module position_children(list, t) //! Position children if they are on the Z = 0 plane when transformed by t + for(p = list) + let(q = t * p) + if(abs(transform([0, 0, 0], q).z) < 0.01) + multmatrix(q) + children(); + // Matrix inversion: https://www.mathsisfun.com/algebra/matrix-inverse-row-operations-gauss-jordan.html function augment(m) = let(l = len(m), n = identity(l)) [ //! Augment a matrix by adding an identity matrix to the right