3D-prints/gift-box.scad

115 lines
3.5 KiB
OpenSCAD
Raw Normal View History

2023-12-17 12:40:52 -06:00
/**
# Parameters
*/
2023-12-17 15:43:11 -06:00
$box_inner_width = 15;
$box_inner_depth = 6;
2023-12-17 12:40:52 -06:00
$box_inner_height = 15;
2023-12-17 15:43:11 -06:00
$box_wall_thickness = 6;
2023-12-17 12:40:52 -06:00
// [0, 1] Higher the ratio, the bigger the bottom will be.
$box_bottom_top_height_fraction = 0.2;
// [0, 1] The amount the bottom and top will overlap.
$overlap_fraction = 0.8;
// [0, 1] The thickness of the overlap as a fraction of the wall thickness.
$overlap_thickness_fraction = 0.5;
2023-12-17 15:43:11 -06:00
// [1, *] Bottom scale. Scale the bottom up by settings this to a small amount like 1.05 to increase the gap between lid and bottom. Raise this number if the lid is too tight and won't go in, lower it if the lid is too loose.
$bottom_scale = 1.05;
// [0, 1] Screw scale. Lower this number if the screw is too tight and won't go through the hole.
$lid_screw_scale = 0.94;
2023-12-17 12:40:52 -06:00
/**
# Code
*/
include <Thread_Library.scad>;
2023-12-17 15:43:11 -06:00
$fn = $preview ? 12 : 200;
2023-12-17 12:40:52 -06:00
$box_outer_width = $box_inner_width + $box_wall_thickness * 2;
$box_outer_depth = $box_inner_depth + $box_wall_thickness * 2;
$box_outer_height = $box_inner_height + $box_wall_thickness * 2;
$bottom_height = $box_inner_height * $box_bottom_top_height_fraction;
$top_height = $box_inner_height * (1 - $box_bottom_top_height_fraction);
$overlap_height = $box_inner_height * $overlap_fraction;
$overlap_thickness = $box_wall_thickness * $overlap_thickness_fraction;
2023-12-17 15:43:11 -06:00
scale([$lid_screw_scale, $lid_screw_scale, $lid_screw_scale])
translate([0, 0, 5])
rotate([90, 0, 0])
screw();
difference() {
scale([$bottom_scale, $bottom_scale, 1])
bottom();
thread();
};
2023-12-17 12:40:52 -06:00
2023-12-17 15:43:11 -06:00
translate([-10, 0, $bottom_height + $top_height + 2 * $box_wall_thickness])
rotate([0, 180, 0])
difference() {
color("blue")
translate([$box_outer_width, 0, $bottom_height + $top_height + 2 * $box_wall_thickness])
rotate([0, 180, 0])
top();
thread();
};
2023-12-17 12:40:52 -06:00
module top() {
2023-12-17 15:43:11 -06:00
difference() {
box_half($box_inner_width, $box_inner_depth, $top_height, $box_wall_thickness);
translate([-0.002, -0.002, 0])
scale([1.001, 1.001, 1.001])
translate([0, 0, $top_height + $bottom_height + $box_wall_thickness * 2])
color("red")
mirror([0, 0, 1])
bottom();
};
2023-12-17 12:40:52 -06:00
}
module bottom() {
union() {
box_half($box_inner_width, $box_inner_depth, $bottom_height, $box_wall_thickness);
2023-12-17 15:43:11 -06:00
box_half(
$box_inner_width + $box_wall_thickness,
$box_inner_depth + $box_wall_thickness, $overlap_height + $box_wall_thickness,
$overlap_thickness
);
2023-12-17 12:40:52 -06:00
};
};
module box_half($width, $depth, $height, $wall_thickness) {
difference() {
cube([
$width + $wall_thickness * 2,
$depth + $wall_thickness * 2,
$height + $wall_thickness
]);
translate([$wall_thickness, $wall_thickness, $wall_thickness])
cube([$width, $depth, $height + 0.1]);
};
};
2023-12-17 15:43:11 -06:00
$thread_z_offset = $bottom_height + $overlap_height / 2 + 7;
$screw_scale = 0.33;
module thread(length=$box_wall_thickness * (1/$screw_scale)) {
color("pink")
translate([$box_outer_width / 2, $box_wall_thickness + 0.1, $thread_z_offset])
rotate([90, 0, 0])
scale([$screw_scale, $screw_scale, $screw_scale])
trapezoidThread(length=length);
}
module screw() {
color("orange")
translate([$box_outer_width / 2, 0, $thread_z_offset])
rotate([90, 0, 0])
cylinder(h=5, d=15, $fn=6);
color("red")
translate([0, 0, 0])
thread(length=$box_wall_thickness * (1/$screw_scale));
}