215 lines
7.4 KiB
OpenSCAD
215 lines
7.4 KiB
OpenSCAD
mode = "2D"; // default
|
|
//mode = "layout";
|
|
//mode = "assembly";
|
|
|
|
golden_ratio = 1.61803398875;
|
|
inch = 25.4/*mm*/;
|
|
|
|
thickness = 3.25; // 3.25mm = 1/8" medium draftboard
|
|
spacing = thickness;
|
|
explode = $t*(5*thickness);
|
|
|
|
outer_width = 5*inch;
|
|
outer_depth = outer_width/golden_ratio;
|
|
outer_height = outer_depth/golden_ratio;
|
|
|
|
inc_top = true;
|
|
inc_bottom = true;
|
|
inc_left = true;
|
|
inc_right = true;
|
|
inc_front = true;
|
|
inc_back = true;
|
|
|
|
notch_margin = 3*thickness;
|
|
notch_size = golden_ratio*thickness;
|
|
|
|
notches_w = round((outer_width - 2*notch_margin) / (2*notch_size));
|
|
notches_h = round((outer_height - 2*notch_margin) / (2*notch_size));
|
|
notches_d = round((outer_depth - 2*notch_margin) / (2*notch_size));
|
|
|
|
inc_labels = mode == "layout" || mode == "assembly";
|
|
label_size = min(outer_width, min(outer_depth, outer_height)) / 5;
|
|
|
|
// 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(n, width, depth=thickness) {
|
|
// The side with notches cut out and the remainder flush.
|
|
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, extra_width=10000) {
|
|
// n spaces + n-1 notches
|
|
space_width = width / (2*n - 1);
|
|
notch_width = space_width;
|
|
translate([-extra_width/2 - width/2, -depth/2, 0]) square([extra_width, 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([extra_width/2 + width/2, -depth/2, 0]) square([extra_width, depth], center=true);
|
|
}
|
|
|
|
if (n < 0) notches_neg(-n, width, depth);
|
|
else if (n > 0) notches_pos( n, width, depth);
|
|
}
|
|
|
|
// For use inside a surface. Always uses the "negative" pattern.
|
|
module holes(n, width, height=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, 0, 0])
|
|
square([notch_width, height], center=true);
|
|
}
|
|
}
|
|
|
|
module panel(label_text, xsize, ysize, yp, xn, yn, xp, margin=notch_margin) {
|
|
difference() {
|
|
square([xsize, ysize], center=true);
|
|
translate([0,ysize/2+0.005,0]) rotate([0,0,0]) notches(yp, xsize - 2*margin);
|
|
translate([-xsize/2-0.005,0,0]) rotate([0,0,90]) notches(xn, ysize - 2*margin);
|
|
translate([0,-ysize/2-0.005,0]) rotate([0,0,180]) notches(yn, xsize - 2*margin);
|
|
translate([xsize/2+0.005,0,0]) rotate([0,0,270]) notches(xp, ysize - 2*margin);
|
|
children();
|
|
if (inc_labels) text(label_text, size=label_size, halign="center", valign="center");
|
|
}
|
|
}
|
|
|
|
module top_side_base() {
|
|
panel("Top", outer_width, outer_depth,
|
|
inc_back ? -notches_w : 0,
|
|
inc_left ? -notches_d : 0,
|
|
inc_front ? -notches_w : 0,
|
|
inc_right ? -notches_d : 0);
|
|
}
|
|
|
|
module bottom_side_base() {
|
|
panel("Bottom", outer_width, outer_depth,
|
|
inc_front ? -notches_w : 0,
|
|
inc_left ? -notches_d : 0,
|
|
inc_back ? -notches_w : 0,
|
|
inc_right ? -notches_d : 0);
|
|
}
|
|
|
|
module left_side_base() {
|
|
panel("Left", outer_depth, outer_height,
|
|
inc_top ? notches_d : 0,
|
|
inc_back ? -notches_h : 0,
|
|
inc_bottom ? notches_d : 0,
|
|
inc_front ? -notches_h : 0);
|
|
}
|
|
|
|
module right_side_base() {
|
|
panel("Right", outer_depth, outer_height,
|
|
inc_top ? notches_d : 0,
|
|
inc_front ? -notches_h : 0,
|
|
inc_bottom ? notches_d : 0,
|
|
inc_back ? -notches_h : 0);
|
|
}
|
|
|
|
module front_side_base() {
|
|
panel("Front", outer_width, outer_height,
|
|
inc_top ? notches_w : 0,
|
|
inc_left ? notches_h : 0,
|
|
inc_bottom ? notches_w : 0,
|
|
inc_right ? notches_h : 0);
|
|
}
|
|
|
|
module back_side_base() {
|
|
panel("Back", outer_width, outer_height,
|
|
inc_top ? notches_w : 0,
|
|
inc_right ? notches_h : 0,
|
|
inc_bottom ? notches_w : 0,
|
|
inc_left ? notches_h : 0);
|
|
}
|
|
|
|
module top_side() { top_side_base(); }
|
|
module bottom_side() { bottom_side_base(); }
|
|
module left_side() { left_side_base(); }
|
|
module right_side() { right_side_base(); }
|
|
module front_side() { front_side_base(); }
|
|
module back_side() { back_side_base(); }
|
|
|
|
// Optimized for height > depth > width.
|
|
module part_layout_hdw() {
|
|
if (inc_front) front_side();
|
|
translate([-(outer_width/2 + spacing + outer_depth/2), 0, 0]) {
|
|
if (inc_left) left_side();
|
|
translate([0, -(outer_height/2 + spacing + outer_width/2), 0]) {
|
|
if (inc_bottom) rotate([0,0,270]) bottom_side();
|
|
}
|
|
translate([-(outer_depth/2 + spacing + outer_width/2), 0, 0]) {
|
|
if (inc_back) back_side();
|
|
}
|
|
translate([0, outer_height/2 + spacing + outer_width/2, 0]) {
|
|
if (inc_top) rotate([0,0,90]) top_side();
|
|
}
|
|
}
|
|
translate([outer_width/2 + spacing + outer_depth/2, 0, 0]) {
|
|
if (inc_right) right_side();
|
|
}
|
|
}
|
|
|
|
// Optimized for width > depth > height.
|
|
module part_layout_wdh() {
|
|
if (inc_front) front_side();
|
|
translate([0, outer_height/2 + spacing + outer_depth/2, 0]) {
|
|
if (inc_top) top_side();
|
|
translate([-(outer_width/2 + spacing + outer_height/2), 0, 0]) {
|
|
if (inc_left) rotate([0,0,270]) left_side();
|
|
}
|
|
translate([0, outer_depth/2 + spacing + outer_height/2, 0]) {
|
|
if (inc_back) rotate([0,0,180]) back_side();
|
|
}
|
|
translate([outer_width/2 + spacing + outer_height/2, 0, 0]) {
|
|
if (inc_right) rotate([0,0,90]) right_side();
|
|
}
|
|
}
|
|
translate([0, -(outer_height/2 + spacing + outer_depth/2), 0]) {
|
|
if (inc_bottom) bottom_side();
|
|
}
|
|
}
|
|
|
|
module extra_layout() {}
|
|
module std_part_layout() {
|
|
if (outer_width > outer_height)
|
|
part_layout_wdh();
|
|
else
|
|
part_layout_hdw();
|
|
|
|
extra_layout();
|
|
}
|
|
module part_layout() { std_part_layout(); }
|
|
|
|
module thicken() {
|
|
linear_extrude(height=thickness, center=true, convexity=10) children();
|
|
}
|
|
|
|
module extra_assembly() {}
|
|
module std_part_assembly() {
|
|
if (inc_left) color("red") translate([ -(outer_width/2 - thickness/2 + explode),0,0]) rotate([90,0,270]) thicken() left_side();
|
|
if (inc_front) color("green") translate([0, -(outer_depth/2 - thickness/2 + explode),0]) rotate([90,0,0]) thicken() front_side();
|
|
if (inc_right) color("blue") translate([ (outer_width/2 - thickness/2 + explode),0,0]) rotate([90,0,90]) thicken() right_side();
|
|
if (inc_back) color("yellow") translate([0, (outer_depth/2 - thickness/2 + explode),0]) rotate([90,0,180]) thicken() back_side();
|
|
if (inc_top) color("cyan") translate([0,0, (outer_height/2 - thickness/2 + explode)]) rotate([0,0,0]) thicken() top_side();
|
|
if (inc_bottom) color("magenta") translate([0,0,-(outer_height/2 - thickness/2 + explode)]) rotate([180,0,0]) thicken() bottom_side();
|
|
extra_assembly();
|
|
}
|
|
module part_assembly() { std_part_assembly(); }
|
|
|
|
if (mode == "assembly")
|
|
part_assembly();
|
|
else if (mode == "layout")
|
|
thicken() part_layout();
|
|
else
|
|
part_layout();
|