-
Notifications
You must be signed in to change notification settings - Fork 28
/
rounded_square.scad
88 lines (76 loc) · 2.33 KB
/
rounded_square.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// helper module for drawing rectangles with rounded borders
//
// (c) 2013 Metamáquina <http://www.metamaquina.com.br/>
//
// Author:
// * Felipe C. da S. Sanches <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
module rounded_square(dim, corners=[10,10,10,10], center=false){
w=dim[0];
h=dim[1];
if (center){
translate([-w/2, -h/2])
rounded_square_(dim, corners=corners);
}else{
rounded_square_(dim, corners=corners);
}
}
module rounded_square_(dim, corners, center=false){
w=dim[0];
h=dim[1];
render(){
difference(){
square([w,h]);
if (corners[0])
square([corners[0], corners[0]]);
if (corners[1])
translate([w-corners[1],0])
square([corners[1], corners[1]]);
if (corners[2])
translate([0,h-corners[2]])
square([corners[2], corners[2]]);
if (corners[3])
translate([w-corners[3], h-corners[3]])
square([corners[3], corners[3]]);
}
if (corners[0])
translate([corners[0], corners[0]])
intersection(){
circle(r=corners[0]);
translate([-corners[0], -corners[0]])
square([corners[0], corners[0]]);
}
if (corners[1])
translate([w-corners[1], corners[1]])
intersection(){
circle(r=corners[1]);
translate([0, -corners[1]])
square([corners[1], corners[1]]);
}
if (corners[2])
translate([corners[2], h-corners[2]])
intersection(){
circle(r=corners[2]);
translate([-corners[2], 0])
square([corners[2], corners[2]]);
}
if (corners[3])
translate([w-corners[3], h-corners[3]])
intersection(){
circle(r=corners[3]);
square([corners[3], corners[3]]);
}
}
}