forked from BelfrySCAD/BOSL2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hingesnaps.scad
200 lines (187 loc) · 8.77 KB
/
hingesnaps.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
//////////////////////////////////////////////////////////////////////
// LibFile: hingesnaps.scad
// Modules for creating snap-locking foldable hined parts. Includes the mask to create the hinge and
// modules to create the snap-locks.
// Includes:
// include <BOSL2/std.scad>
// include <BOSL2/hingesnaps.scad>
// FileGroup: Parts
// FileSummary: Foldable, snap-locking parts.
//////////////////////////////////////////////////////////////////////
// Section: Hinges and Snaps
// Module: apply_folding_hinges_and_snaps()
// Usage:
// apply_folding_hinges_and_snaps(thick, [foldangle=], [hinges=], [snaps=], [sockets=], [snaplen=], [snapdiam=], [hingegap=], [layerheight=]) CHILDREN;
// Description:
// Adds snaplocks and create hinges in children at the given positions.
// Arguments:
// thick = Thickness in mm of the material to make the hinge in.
// foldangle = The interior angle in degrees of the joint to be created with the hinge. Default: 90
// hinges = List of [LENGTH, POSITION, SPIN] for each hinge to difference from the children.
// snaps = List of [POSITION, SPIN] for each central snaplock to add to the children.
// sockets = List of [POSITION, SPIN] for each outer snaplock sockets to add to the children.
// snaplen = Length of locking snaps.
// snapdiam = Diameter/width of locking snaps.
// hingegap = Size in mm of the gap at the bottom of the hinge, to make room for folding.
// layerheight = The expected printing layer height in mm.
// Example(Med):
// size=100;
// apply_folding_hinges_and_snaps(
// thick=3, foldangle=54.74,
// hinges=[
// for (a=[0,120,240], b=[-size/2,size/4]) each [
// [200, polar_to_xy(b,a), a+90]
// ]
// ],
// snaps=[
// for (a=[0,120,240]) each [
// [rot(a,p=[ size/4, 0 ]), a+90],
// [rot(a,p=[-size/2,-size/2.33]), a-90]
// ]
// ],
// sockets=[
// for (a=[0,120,240]) each [
// [rot(a,p=[ size/4, 0 ]), a+90],
// [rot(a,p=[-size/2, size/2.33]), a+90]
// ]
// ]
// ) {
// $fn=3;
// difference() {
// cylinder(r=size-1, h=3);
// down(0.01) cylinder(r=size/4.5, h=3.1, spin=180);
// down(0.01) for (a=[0:120:359.9]) zrot(a) right(size/2) cylinder(r=size/4.5, h=3.1);
// }
// }
module apply_folding_hinges_and_snaps(thick, foldangle=90, hinges=[], snaps=[], sockets=[], snaplen=5, snapdiam=5, hingegap=undef, layerheight=0.2)
{
hingegap = default(hingegap, layerheight)+2*get_slop();
difference() {
children();
for (hinge = hinges) {
translate(hinge[1]) {
folding_hinge_mask(
l=hinge[0], thick=thick, layerheight=layerheight,
foldangle=foldangle, hingegap=hingegap, spin=hinge[2]
);
}
}
}
for (snap = snaps) {
translate(snap[0]) {
snap_lock(
thick=thick, snaplen=snaplen, snapdiam=snapdiam,
layerheight=layerheight, foldangle=foldangle,
hingegap=hingegap, spin=snap[1]
);
}
}
for (socket = sockets) {
translate(socket[0]) {
snap_socket(
thick=thick, snaplen=snaplen, snapdiam=snapdiam,
layerheight=layerheight, foldangle=foldangle,
hingegap=hingegap, spin=socket[1]
);
}
}
}
// Module: folding_hinge_mask()
// Usage:
// folding_hinge_mask(l, thick, [layerheight=], [foldangle=], [hingegap=], [anchor=], [spin=], [orient=]) [ATTACHMENTS];
// Description:
// Creates a mask to be differenced away from a plate to create a foldable hinge.
// Center the mask at the bottom of the plate you want to make a hinge in.
// The mask will leave hinge material two `layerheight`s thick on the bottom of the hinge.
// Arguments:
// l = Length of the hinge in mm.
// thick = Thickness in mm of the material to make the hinge in.
// ---
// layerheight = The expected printing layer height in mm.
// foldangle = The interior angle in degrees of the joint to be created with the hinge. Default: 90
// hingegap = Size in mm of the gap at the bottom of the hinge, to make room for folding.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top towards. See [orient](attachments.scad#subsection-orient). Default: `UP`
// Example:
// folding_hinge_mask(l=100, thick=3, foldangle=60);
module folding_hinge_mask(l, thick, layerheight=0.2, foldangle=90, hingegap=undef, anchor=CENTER, spin=0, orient=UP)
{
hingegap = default(hingegap, layerheight)+2*get_slop();
size = [l, hingegap, 2*thick];
size2 = [l, hingegap+2*thick*tan(foldangle/2)];
attachable(anchor,spin,orient, size=size, size2=size2) {
up(layerheight*2) prismoid([l,hingegap], [l, hingegap+2*thick/tan(foldangle/2)], h=thick, anchor=BOT);
children();
}
}
// Module: snap_lock()
// Usage:
// snap_lock(thick, [snaplen=], [snapdiam=], [layerheight=], [foldangle=], [hingegap=], [anchor=], [spin=], [orient=]) [ATTACHMENTS];
// Description:
// Creates the central snaplock part.
// Arguments:
// thick = Thickness in mm of the material to make the hinge in.
// ---
// snaplen = Length of locking snaps.
// snapdiam = Diameter/width of locking snaps.
// layerheight = The expected printing layer height in mm.
// foldangle = The interior angle in degrees of the joint to be created with the hinge. Default: 90
// hingegap = Size in mm of the gap at the bottom of the hinge, to make room for folding.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top towards. See [orient](attachments.scad#subsection-orient). Default: `UP`
// Example:
// snap_lock(thick=3, foldangle=60);
module snap_lock(thick, snaplen=5, snapdiam=5, layerheight=0.2, foldangle=90, hingegap=undef, anchor=CENTER, spin=0, orient=UP)
{
hingegap = default(hingegap, layerheight)+2*get_slop();
snap_x = (snapdiam/2) / tan(foldangle/2) + (thick-2*layerheight)/tan(foldangle/2) + hingegap/2;
size = [snaplen, snapdiam, 2*thick];
attachable(anchor,spin,orient, size=size) {
back(snap_x) {
cube([snaplen, snapdiam, snapdiam/2+thick], anchor=BOT) {
attach(TOP) xcyl(l=snaplen, d=snapdiam, $fn=16);
attach(TOP) xcopies(snaplen-snapdiam/4/3) xscale(0.333) sphere(d=snapdiam*0.8, $fn=12);
}
}
children();
}
}
// Module: snap_socket()
// Usage:
// snap_socket(thick, [snaplen=], [snapdiam=], [layerheight=], [foldangle=], [hingegap=], [anchor=], [spin=], [orient=]) [ATTACHMENTS];
// Description:
// Creates the outside snaplock socketed part.
// Arguments:
// thick = Thickness in mm of the material to make the hinge in.
// ---
// snaplen = Length of locking snaps.
// snapdiam = Diameter/width of locking snaps.
// layerheight = The expected printing layer height in mm.
// foldangle = The interior angle in degrees of the joint to be created with the hinge. Default: 90
// hingegap = Size in mm of the gap at the bottom of the hinge, to make room for folding.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top towards. See [orient](attachments.scad#subsection-orient). Default: `UP`
// Example:
// snap_socket(thick=3, foldangle=60);
module snap_socket(thick, snaplen=5, snapdiam=5, layerheight=0.2, foldangle=90, hingegap=undef, anchor=CENTER, spin=0, orient=UP)
{
hingegap = default(hingegap, layerheight)+2*get_slop();
snap_x = (snapdiam/2) / tan(foldangle/2) + (thick-2*layerheight)/tan(foldangle/2) + hingegap/2;
size = [snaplen, snapdiam, 2*thick];
attachable(anchor,spin,orient, size=size) {
fwd(snap_x) {
zrot_copies([0,180], r=snaplen+get_slop()) {
diff("divot")
cube([snaplen, snapdiam, snapdiam/2+thick], anchor=BOT) {
attach(TOP) xcyl(l=snaplen, d=snapdiam, $fn=16);
attach(TOP) left((snaplen+snapdiam/4/3)/2) xscale(0.333) sphere(d=snapdiam*0.8, $fn=12, $tags="divot");
}
}
}
children();
}
}
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap