From ec51898f0b616537ba9056f07ac7519aa3d048be Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Sat, 13 Jan 2018 21:06:04 -0600 Subject: [PATCH] fingerjoint box generator - initial commit --- 2d/box/box.scad | 149 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 2d/box/box.scad diff --git a/2d/box/box.scad b/2d/box/box.scad new file mode 100644 index 0000000..533433d --- /dev/null +++ b/2d/box/box.scad @@ -0,0 +1,149 @@ +mode = "project"; // default +//mode = "parts"; +//mode = "assembly"; + +thickness = 3.25; // 3.25mm = 1/8" +spacing = 3.25; + +outer_width = 52*0.75; +outer_height = 52*3*0.75; +outer_depth = 52*1.333*0.75; + +golden_ratio = 1.61803398875; +notch_size = golden_ratio*thickness; +notches_w = round((outer_width - 6*thickness) / (2*notch_size)); +notches_h = round((outer_height - 6*thickness) / (2*notch_size)); +notches_d = round((outer_depth - 6*thickness) / (2*notch_size)); + +module label(label_text) { + if (mode != "project") text(label_text, halign="center", valign="center"); +} + +// 2D notch pattern for an edge from [-width/2,0] to [width/2,0] in the XY plane with a +Y normal. +// Meant to be subtracted from the shape with difference(). +module notches_neg(n, width, depth=thickness) { + // n notches + n-1 spaces + notch_width = width / (2*n - 1); + space_width = notch_width; + for (i = [0 : n-1]) { + translate([-width/2 + i*notch_width + i*space_width + notch_width/2, -depth/2, 0]) + square([notch_width, depth], center=true); + } +} + +// The inverse of notches_neg() for the same parameters, for the mating edge. +module notches_pos(n, width, depth=thickness) { + // n spaces + n-1 notches + space_width = width / (2*n - 1); + notch_width = space_width; + translate([-1e6/2 - width/2, -depth/2, 0]) square([1e6, depth], center=true); + for (i = [0 : n-1]) { + translate([-width/2 + (i+1)*space_width + i*notch_width + notch_width/2, -depth/2, 0]) + square([notch_width, depth], center=true); + } + translate([10000/2 + width/2, -depth/2, 0]) square([10000, depth], center=true); +} + +module top_side() { + difference() { + square([outer_width, outer_depth], center=true); + translate([0,outer_depth/2+0.005,0]) rotate([0,0,0]) notches_neg(notches_w, outer_width - 6*thickness); + translate([-outer_width/2-0.005,0,0]) rotate([0,0,90]) notches_neg(notches_d, outer_depth - 6*thickness); + translate([0,-outer_depth/2-0.005,0]) rotate([0,0,180]) notches_neg(notches_w, outer_width - 6*thickness); + translate([outer_width/2+0.005,0,0]) rotate([0,0,270]) notches_neg(notches_d, outer_depth - 6*thickness); + label("Top"); + } +} + +module bottom_side() { + difference() { + square([outer_width, outer_depth], center=true); + translate([0,outer_depth/2+0.005,0]) rotate([0,0,0]) notches_neg(notches_w, outer_width - 6*thickness); + translate([-outer_width/2-0.005,0,0]) rotate([0,0,90]) notches_neg(notches_d, outer_depth - 6*thickness); + translate([0,-outer_depth/2-0.005,0]) rotate([0,0,180]) notches_neg(notches_w, outer_width - 6*thickness); + translate([outer_width/2+0.005,0,0]) rotate([0,0,270]) notches_neg(notches_d, outer_depth - 6*thickness); + label("Bottom"); + } +} + +module left_side() { + difference() { + square([outer_height, outer_depth], center=true); + translate([0,outer_depth/2+0.005,0]) rotate([0,0,0]) notches_neg(notches_h, outer_height - 6*thickness); + translate([-outer_height/2-0.005,0,0]) rotate([0,0,90]) notches_pos(notches_d, outer_depth - 6*thickness); + translate([0,-outer_depth/2-0.005,0]) rotate([0,0,180]) notches_neg(notches_h, outer_height - 6*thickness); + translate([outer_height/2+0.005,0,0]) rotate([0,0,270]) notches_pos(notches_d, outer_depth - 6*thickness); + label("Left"); + } +} + +module right_side() { + difference() { + square([outer_height, outer_depth], center=true); + translate([0,outer_depth/2+0.005,0]) rotate([0,0,0]) notches_neg(notches_h, outer_height - 6*thickness); + translate([-outer_height/2-0.005,0,0]) rotate([0,0,90]) notches_pos(notches_d, outer_depth - 6*thickness); + translate([0,-outer_depth/2-0.005,0]) rotate([0,0,180]) notches_neg(notches_h, outer_height - 6*thickness); + translate([outer_height/2+0.005,0,0]) rotate([0,0,270]) notches_pos(notches_d, outer_depth - 6*thickness); + label("Right"); + } +} + +module front_side() { + difference() { + square([outer_width, outer_height], center=true); + translate([0,outer_height/2+0.005,0]) rotate([0,0,0]) notches_pos(notches_w, outer_width - 6*thickness); + translate([-outer_width/2-0.005,0,0]) rotate([0,0,90]) notches_pos(notches_h, outer_height - 6*thickness); + translate([0,-outer_height/2-0.005,0]) rotate([0,0,180]) notches_pos(notches_w, outer_width - 6*thickness); + translate([outer_width/2+0.005,0,0]) rotate([0,0,270]) notches_pos(notches_h, outer_height - 6*thickness); + label("Front"); + } +} + +module back_side() { + difference() { + square([outer_width, outer_height], center=true); + translate([0,outer_height/2+0.005,0]) rotate([0,0,0]) notches_pos(notches_w, outer_width - 6*thickness); + translate([-outer_width/2-0.005,0,0]) rotate([0,0,90]) notches_pos(notches_h, outer_height - 6*thickness); + translate([0,-outer_height/2-0.005,0]) rotate([0,0,180]) notches_pos(notches_w, outer_width - 6*thickness); + translate([outer_width/2+0.005,0,0]) rotate([0,0,270]) notches_pos(notches_h, outer_height - 6*thickness); + label("Back"); + } +} + +module thicken() { + linear_extrude(height=thickness, center=true, convexity=10) children(); +} + +module std_part_layout() { + translate([0,0,0]) top_side(); + translate([-(outer_width/2 + outer_height/2 + spacing), 0, 0]) left_side(); + translate([ (outer_width/2 + outer_height/2 + spacing), 0, 0]) right_side(); + translate([0, -(outer_depth/2 + outer_height/2 + spacing), 0]) front_side(); + translate([0, (outer_depth/2 + outer_height/2 + spacing), 0]) back_side(); + translate([0, -(outer_depth + outer_height + 2*spacing), 0]) bottom_side(); +} + +module part_layout() { + translate([-2*(outer_depth/2 + outer_width/2 + spacing), 0, 0]) back_side(); + translate([-1*(outer_depth/2 + outer_width/2 + spacing), 0, 0]) rotate([0,0,90]) left_side(); + front_side(); + translate([outer_depth/2 + outer_width/2 + spacing, 0, 0]) rotate([0,0,90]) right_side(); + translate([outer_depth + outer_width + 2*spacing,(outer_height-outer_depth)/2,0]) top_side(); + translate([outer_depth + outer_width + 2*spacing,-(outer_height-outer_depth)/2,0]) bottom_side(); +} + +module part_assembly() { + color("red") translate([0,0, outer_height/2 - thickness/2]) rotate([0,0,0]) thicken() top_side(); + color("green") translate([0,0,-outer_height/2 + thickness/2]) rotate([180,0,0]) thicken() bottom_side(); + color("blue") translate([-outer_width/2 + thickness/2,0,0]) rotate([0,-90,0]) thicken() left_side(); + color("cyan") translate([ outer_width/2 - thickness/2,0,0]) rotate([0, 90,0]) thicken() right_side(); + color("magenta") translate([0,-outer_depth/2 + thickness/2,0]) rotate([ 90,0,0]) thicken() front_side(); + color("yellow") translate([0, outer_depth/2 - thickness/2,0]) rotate([-90,0,0]) thicken() back_side(); +} + +if (mode == "project") + part_layout(); +else if (mode == "parts") + thicken() part_layout(); +else + part_assembly();