[project_box] Clean up dimensions API

Use coordinate triples to represent the 3D volumes being built upon.
This commit is contained in:
Correl Roush 2022-12-07 12:09:05 -05:00
parent a01323641b
commit 4fabdf070d
3 changed files with 63 additions and 57 deletions

View file

@ -3,7 +3,6 @@ $fn=50;
mode = "case"; // ["case", "lid", "all"]
project_box(50, 70,
above=0,
project_box([50, 70, 0],
below=1,
mode=mode);

View file

@ -34,8 +34,7 @@ module cutouts() {
square([15,10]);
}
project_box(x, y,
above=z,
project_box([x, y, z],
below=10,
mode=mode) {
cutouts();

View file

@ -22,16 +22,16 @@ corner_radius=3; // [1:10]
support_radius=5; // [1:10]
wall_width=3; // [3:10]
module _rounded_box(h, w, d, r) {
module _rounded_box(box, r) {
hull() {
translate([0 + r,0 + r,0])
cylinder(h=h,r=r);
translate([w - r,0 + r,0])
cylinder(h=h, r=r);
translate([w - r,d - r,0])
cylinder(h=h, r=r);
translate([0 + r,d - r,0])
cylinder(h=h, r=r);
cylinder(h=box.z,r=r);
translate([box.x - r,0 + r,0])
cylinder(h=box.z, r=r);
translate([box.x - r,box.y - r,0])
cylinder(h=box.z, r=r);
translate([0 + r,box.y - r,0])
cylinder(h=box.z, r=r);
}
}
@ -43,17 +43,17 @@ module corner_post(h, r) {
}
}
module lid_base(x, y, z, slot_depth=1.5) {
module lid_base(dimensions, slot_depth=1.5) {
polyhedron([// bottom face
[0, 0, 0],
[x, 0, 0],
[x, y, 0],
[0, y, 0],
[dimensions.x, 0, 0],
[dimensions.x, dimensions.y, 0],
[0, dimensions.y, 0],
// top face
[slot_depth, 0, z],
[x - slot_depth, 0, z],
[x - slot_depth, y, z],
[slot_depth, y, z]],
[slot_depth, 0, dimensions.z],
[dimensions.x - slot_depth, 0, dimensions.z],
[dimensions.x - slot_depth, dimensions.y, dimensions.z],
[slot_depth, dimensions.y, dimensions.z]],
[[0,1,2,3],
[4,5,1,0],
[7,6,5,4],
@ -62,26 +62,29 @@ module lid_base(x, y, z, slot_depth=1.5) {
[7,4,0,3]]);
}
module lid(x, y, z, slot_depth=1.5, wall_width=3, fit_tolerance=0.5) {
indent_width = x / 4;
module lid(dimensions, slot_depth=1.5, wall_width=3, fit_tolerance=0.5) {
indent_width = dimensions.x / 4;
difference() {
union() {
lid_base(x, y, z, slot_depth);
lid_base([dimensions.x, dimensions.y, dimensions.z], slot_depth);
// locking tab
translate([x / 2 - indent_width / 2 - fit_tolerance, y - wall_width - fit_tolerance, 0])
translate([dimensions.x / 2 - indent_width / 2 - fit_tolerance,
dimensions.y - wall_width - fit_tolerance,
0])
rotate([0, 90, 0])
cylinder(h=x / 4, r=2*fit_tolerance);
cylinder(h=dimensions.x / 4, r=2*fit_tolerance);
}
// pull handle
translate([x / 2 - indent_width / 2 - fit_tolerance, y - wall_width + fit_tolerance + 0.001, -0.001]) {
cube([indent_width,wall_width - 2 * fit_tolerance,0.6 * z]);
cube([indent_width,2 + wall_width - 2 * fit_tolerance,0.3 * z]);
translate([dimensions.x / 2 - indent_width / 2 - fit_tolerance,
dimensions.y - wall_width + fit_tolerance + 0.001,
-0.001]) {
cube([indent_width,wall_width - 2 * fit_tolerance,0.6 * dimensions.z]);
cube([indent_width,2 + wall_width - 2 * fit_tolerance,0.3 * dimensions.z]);
}
}
}
module project_box(x, y,
above=20,
module project_box(box,
below=10,
board_thickness=1,
fit_tolerance=0.5,
@ -89,12 +92,12 @@ module project_box(x, y,
support_radius=5,
wall_width=3,
mode="case") {
width=board_x + (fit_tolerance * 2);
depth=board_y + (fit_tolerance * 2);
width=box.x + (fit_tolerance * 2);
depth=box.y + (fit_tolerance * 2);
lid_width = width + wall_width; // Extends halfway into each side wall
lid_depth = depth + wall_width; // Extends out of one wall
lid_height = wall_width; // Replaces most of the top wall
height=board_thickness + above + below + (fit_tolerance * 2) + lid_height;
height=board_thickness + box.z + below + (fit_tolerance * 2) + lid_height;
// case
if ((mode == "case") || (mode == "all")) {
@ -102,15 +105,15 @@ module project_box(x, y,
union() {
// hollow shell
difference() {
_rounded_box(h=height + (wall_width * 2),
w=width + (wall_width * 2),
d=depth + (wall_width * 2),
_rounded_box([width + (wall_width * 2),
depth + (wall_width * 2),
height + (wall_width * 2)],
r=corner_radius);
translate([wall_width,wall_width,wall_width])
cube([width, depth, height + (wall_width * 2)]);
// lid slot
translate([wall_width / 2, wall_width, height + wall_width + 0.001]) {
lid_base(lid_width, lid_depth, lid_height);
lid_base([lid_width, lid_depth, lid_height]);
}
}
// supports
@ -131,19 +134,23 @@ module project_box(x, y,
// locking nubs
translate([wall_width,wall_width,wall_width]) {
nub_size = fit_tolerance * 2;
nub_width = board_y / 4;
nub_width = box.y / 4;
nub_height = below + board_thickness + (nub_size/2) + (fit_tolerance*2);
translate([0,board_y / 2 - nub_width / 2,nub_height])
translate([0,box.y / 2 - nub_width / 2,nub_height])
rotate([270,0,0])
cylinder(h=nub_width, r=nub_size/2);
translate([width,board_y / 2 - nub_width / 2,nub_height])
translate([width,box.y / 2 - nub_width / 2,nub_height])
rotate([270,0,0])
cylinder(h=nub_width, r=nub_size/2);
}
if (mode == "all") {
// lid
translate([wall_width / 2 + fit_tolerance, wall_width + fit_tolerance, height + wall_width + fit_tolerance]) {
lid(lid_width - (fit_tolerance * 2), lid_depth - (fit_tolerance * 2), lid_height - (fit_tolerance * 2));
translate([wall_width / 2 + fit_tolerance,
wall_width + fit_tolerance,
height + wall_width + fit_tolerance]) {
lid([lid_width - (fit_tolerance * 2),
lid_depth - (fit_tolerance * 2),
lid_height - (fit_tolerance * 2)]);
}
}
}
@ -156,7 +163,9 @@ module project_box(x, y,
translate([lid_width - (fit_tolerance * 2),0,lid_height - (fit_tolerance * 2)]) {
rotate([0, 180, 0]) {
difference() {
lid(lid_width - (fit_tolerance * 2), lid_depth - (fit_tolerance * 2), lid_height - (fit_tolerance * 2));
lid([lid_width - (fit_tolerance * 2),
lid_depth - (fit_tolerance * 2),
lid_height - (fit_tolerance * 2)]);
translate([wall_width + fit_tolerance, wall_width + fit_tolerance, -0.001])
children();
}
@ -165,39 +174,38 @@ module project_box(x, y,
}
}
module cutout_front(volume) {
module cutout_front(box) {
rotate([90, 0, 0])
linear_extrude(height=volume.y * 2)
linear_extrude(height=box.y * 2)
children(0);
}
module cutout_back(volume) {
translate([volume.x,0,0])
module cutout_back(box) {
translate([box.x,0,0])
rotate([90, 0, 180])
linear_extrude(height=volume.y * 2)
linear_extrude(height=box.y * 2)
children(0);
}
module cutout_right(volume) {
module cutout_right(box) {
rotate([90, 0, 90])
linear_extrude(height=volume.x * 2)
linear_extrude(height=box.x * 2)
children(0);
}
module cutout_left(volume) {
translate([volume.x, volume.y, 0])
module cutout_left(box) {
translate([box.x, box.y, 0])
rotate([90, 0, 270])
linear_extrude(height=volume.x * 2)
linear_extrude(height=box.x * 2)
children(0);
}
module cutout_top(volume) {
linear_extrude(height=volume.y * 2)
module cutout_top(box) {
linear_extrude(height=box.y * 2)
children(0);
}
project_box(board_x, board_y,
above=clearance_above,
project_box([board_x, board_y, clearance_above],
below=clearance_below,
board_thickness=board_thickness,
fit_tolerance=fit_tolerance,