diff --git a/tests/nuts.scad b/tests/nuts.scad index 6626223..30d14c1 100644 --- a/tests/nuts.scad +++ b/tests/nuts.scad @@ -22,13 +22,12 @@ use <../utils/layout.scad> include <../vitamins/screws.scad> module nuts() { - for(nyloc = [false, true]) - translate([0, nyloc ? 20 : 0]) - layout([for(n = nuts) 2 * nut_radius(n)], 5) - nut(nuts[$i], nyloc); + layout([for(n = nuts) 2 * nut_radius(n)], 5) let(n = nuts[$i]) { + for(nyloc = [false, true]) + translate([0, nyloc ? 20 : 0]) + nut(n, nyloc); - translate([0, 40]) - layout([for(n = nuts) 2 * nut_radius(n)], 5) let(n = nuts[$i]) { + translate([0, 40]) { if(n == M3_nut) nut(n, brass = true); @@ -46,18 +45,25 @@ module nuts() { #nut_trap(M8_cap_screw, n, h = 30); } - translate([0, 60]) - layout([for(n = nuts) 2 * nut_radius(n)], 5) let(n = nuts[$i]) { + translate([0, 60]) { if(n == M3_nut) - sliding_t_nut(M3_sliding_t); + sliding_t_nut(M3_sliding_t_nut); if(n == M4_nut) - sliding_t_nut(M4_sliding_t); + sliding_t_nut(M4_sliding_t_nut); if(n == M5_nut) - sliding_t_nut(M5_sliding_t); - + sliding_t_nut(M5_sliding_t_nut); } + + translate([0, 80]) { + if(n == M3_nut) + hammer_nut(M3_hammer_nut); + + if(n == M4_nut) + hammer_nut(M4_hammer_nut); + } + } } if($preview) diff --git a/vitamins/nut.scad b/vitamins/nut.scad index 9a3384c..d00bcae 100644 --- a/vitamins/nut.scad +++ b/vitamins/nut.scad @@ -25,6 +25,7 @@ include <../core.scad> use use +use <../utils/fillet.scad> use <../utils/rounded_cylinder.scad> brass_colour = brass; @@ -109,42 +110,72 @@ module wingnut(type) { //! Draw a wingnut } } -module sliding_t_nut(type) { //! Draw a sliding T-nut - vitamin(str("sliding_t_nut(", type[0], "): Sliding T-nut M", nut_size(type))); +module sliding_t_nut(type) { + vitamin(str("sliding_t_nut(", type[0], "): Nut M", nut_size(type), " sliding T")); - hole_diameter = nut_size(type); - sizeX = type[7]; - sizeY = type[2]; + size = [type[7], type[2], nut_thickness(type)]; tabSizeY1 = type[8]; tabSizeY2 = type[9]; - nut_thickness = nut_thickness(type); tabSizeZ = type[10]; + holeRadius = nut_size(type) / 2; - color(grey70) { - // center section - linear_extrude(nut_thickness - tabSizeZ) - difference() { - square([sizeX, sizeY], center = true); - circle(d = hole_diameter); + if($preview) + color(grey80) + extrusionSlidingNut(size, tabSizeY1, tabSizeY2, tabSizeZ, holeRadius); + +} + +module hammer_nut(type) { + vitamin(str("hammer_nut(", type[0], "): Nut M", nut_size(type), " hammer")); + + size = [type[7], type[2], nut_thickness(type)]; + tabSizeY1 = type[8]; + tabSizeY2 = type[9]; + tabSizeZ = type[10]; + holeRadius = nut_size(type) / 2; + + if($preview) + color(grey80) + extrusionSlidingNut(size, tabSizeY1, tabSizeY2, tabSizeZ, holeRadius, 0, hammerNut = true); + +} + +module extrusionSlidingNut(size, tabSizeY1, tabSizeY2, tabSizeZ, holeRadius, holeOffset = 0, hammerNut = false) { + // center section + linear_extrude(size[2] - tabSizeZ) + difference() { + square([size[0], size[1]], center = true); + if(hammerNut) { + translate([size[0] / 2, size[1] / 2]) + rotate(180) + fillet(1); + translate([-size[0] / 2, -size[1] / 2]) + fillet(1); + } + if(holeRadius) + translate([holeOffset, 0]) + circle(holeRadius); + } + translate_z(size[2] - tabSizeZ) + linear_extrude(tabSizeZ) + difference() { + square([size[0], tabSizeY2], center = true); + if(holeRadius) + translate([holeOffset, 0]) + circle(holeRadius); + } + + // add the side tabs + for(m = [0, 1]) + mirror([0, m, 0]) + translate([0, tabSizeY2 / 2, size[2] - tabSizeZ]) { + cubeZ = 1; + translate([-size[0] / 2, 0, 0]) + cube([size[0], (tabSizeY1 - tabSizeY2) / 2, cubeZ]); + translate_z(cubeZ) + rotate([0, -90, 0]) + right_triangle(tabSizeZ - cubeZ, (tabSizeY1 - tabSizeY2) / 2, size[0], center = true); } - translate_z(nut_thickness - tabSizeZ) - linear_extrude(tabSizeZ) - difference() { - square([sizeX, tabSizeY2], center = true); - circle(d = hole_diameter); - } - // add the side tabs - for(m = [0, 1]) - mirror([0, m, 0]) - translate([0, tabSizeY2 / 2, nut_thickness - tabSizeZ]) { - cubeZ = 1; - translate([-sizeX / 2, 0, 0]) - cube([sizeX, (tabSizeY1 - tabSizeY2) / 2, cubeZ]); - translate_z(cubeZ) - rotate([0, -90, 0]) - right_triangle(tabSizeZ - cubeZ, (tabSizeY1 - tabSizeY2) / 2, sizeX, center = true); - } - } } function nut_trap_radius(nut, horizontal = false) = nut_radius(nut) + (horizontal ? layer_height / 4 : 0); //! Radius across the corners of a nut trap diff --git a/vitamins/nuts.scad b/vitamins/nuts.scad index 8e1ef7d..4e6ff62 100644 --- a/vitamins/nuts.scad +++ b/vitamins/nuts.scad @@ -51,10 +51,12 @@ toggle_nut = ["toggle_nut", 6.1, 9.2, 1.5, 1.5, M6_washer, 1.5]; M4_wingnut = ["M4_wingnut", 4, 10, 3.75,8, M4_washer, 0, 22, 10, 6, 3]; -// sx ty1 ty2 tz -M3_sliding_t= ["M3_sliding_t_nut",3, 6, 4.0, 0, M3_washer, 0, 10, 10, 6, 3]; -M4_sliding_t= ["M4_sliding_t_nut",4, 6, 4.5, 0, M4_washer, 0, 11, 10, 6, 3.25]; -M5_sliding_t= ["M5_sliding_t_nut",5, 7, 4.5, 0, M5_washer, 0, 11, 10, 7, 3.25]; +// sx ty1 ty2 tz +M3_sliding_t_nut = ["M3_sliding_t_nut", 3, 6, 4.0, 0, M3_washer, 0, 10, 10, 6, 3]; +M4_sliding_t_nut = ["M4_sliding_t_nut", 4, 6, 4.5, 0, M4_washer, 0, 11, 10, 6, 3.25]; +M5_sliding_t_nut = ["M5_sliding_t_nut", 5, 6, 4.5, 0, M5_washer, 0, 11, 10, 7, 3.25]; +M3_hammer_nut = ["M3_hammer_nut", 3, 6, 4.0, 0, M3_washer, 0, 5.5, 10, 6, 2.75]; +M4_hammer_nut = ["M4_hammer_nut", 4, 6, 4.5, 0, M4_washer, 0, 5.5, 10, 6, 3.25]; nuts = [M2_nut, M2p5_nut, M3_nut, M4_nut, M5_nut, M6_nut, M8_nut];