-
Notifications
You must be signed in to change notification settings - Fork 0
/
rounded-box-template.scad
64 lines (55 loc) · 2.31 KB
/
rounded-box-template.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Global config variables
enclosure_height = 30;
enclosure_length = 92;
enclosure_width = 66;
wall_thickness = 1.6;
$fn = 48; // curved resolution (used for cylinders and spheres)
box();
module box() {
difference() {
rcube([enclosure_width,enclosure_length,enclosure_height], 10);
//cylinder(h = enclosure_height, r = enclosure_radius);
// Make the cylinder hollow
translate([wall_thickness,wall_thickness,wall_thickness]) {
rcube([enclosure_width - wall_thickness * 2, enclosure_length - wall_thickness * 2,enclosure_height], 10);
inner_height = enclosure_height;
inner_radius = enclosure_radius - (wall_thickness * 2);
//cylinder(h = inner_height, r = inner_radius, center = false);
}
}
}
module rcube(size, radius) {
if(len(radius) == undef) {
// The same radius on all corners
rcube(size, [radius, radius, radius, radius]);
} else if(len(radius) == 2) {
// Different radii on top and bottom
rcube(size, [radius[0], radius[0], radius[1], radius[1]]);
} else if(len(radius) == 4) {
// Different radius on different corners
hull() {
// BL
if(radius[0] == 0) cube([1, 1, size[2]]);
else translate([radius[0], radius[0]]) cylinder(r = radius[0], h = size[2]);
// BR
if(radius[1] == 0) translate([size[0] - 1, 0]) cube([1, 1, size[2]]);
else translate([size[0] - radius[1], radius[1]]) cylinder(r = radius[1], h = size[2]);
// TR
if(radius[2] == 0) translate([size[0] - 1, size[1] - 1])cube([1, 1, size[2]]);
else translate([size[0] - radius[2], size[1] - radius[2]]) cylinder(r = radius[2], h = size[2]);
// TL
if(radius[3] == 0) translate([0, size[1] - 1]) cube([1, 1, size[2]]);
else translate([radius[3], size[1] - radius[3]]) cylinder(r = radius[3], h = size[2]);
}
} else {
echo("ERROR: Incorrect length of 'radius' parameter. Expecting integer or vector with length 2 or 4.");
}
}
module fillet(r, h) {
translate([r / 2, r / 2, 0])
difference() {
cube([r + 0.01, r + 0.01, h], center = true);
translate([r/2, r/2, 0])
cylinder(r = r, h = h + 1, center = true);
}
}