-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpanel-notch.scad
563 lines (486 loc) · 21.8 KB
/
panel-notch.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
//
// PANEL-NOTCHES
// by ISC 2021-09
//
// NotchProfile( ... ) - create profile
// Notch( targetWidth, notches, profile ) - draw 2D centered notches or notch holes
// NotchEdge( targetWidth, notches, profile ) - draw notches/holes edge to edge
//
include <KVTree.scad>
//
// DEMO
//
// run me !!!
//$vpr=[0,0,0]; Notch_Demo_2D();
//Notch_Demo();
//Notch_Assembly_Demo();
module Notch_Demo_2D() {
include <orientation.scad>
profile1 = NotchProfile( panelThickness = 3 );
profile2 = NotchProfile( panelThickness = 3,
notchWidthAllowance = -1, holeWidthAllowance = 1,
notchHeightAllowance = 3, holeHeightAllowance = 1,
leftGap = 10, rightGap = 10
);
kvEchoAligned(profile2);
// gray patches were punched out
translate([ 0, 0,0]) demoM( 80,profile1,"gray") Notch ( 80, 2, profile1 );
translate([ 0, 35,0]) demoM( 80,profile1,"gray") NotchEdge( 80, 2, profile1 );
translate([ 0, 60,0]) demoF( 80, "gray") Notch ( 80, -2, profile1 );
// green patches were added
translate([ 90, 0,0]) demoM( 80,profile1,"green") Notch ( 80, 2, profile1, additive=true );
translate([ 90, 35,0]) demoM( 80,profile1,"green") NotchEdge( 80, 2, profile1, additive=true );
// gray patches were punched out
translate([190, 0,0]) demoM(100,profile2,"gray") Notch ( 100, 2, profile2 );
translate([190, 35,0]) demoM(100,profile2,"gray") Notch ( 100, 2, profile2, punchGap=false );
translate([190, 70,0]) demoM(100,profile2,"gray") NotchEdge( 100, 2, profile2 );
translate([190,105,0]) demoM(100,profile2,"gray") NotchEdge( 100, 2, profile2, punchGap=false );
translate([190,130,0]) demoF(100, "gray") Notch ( 100, -2, profile2 );
module demoM(width,profile,color) {
color("red") translate([0,0,1]) square([width,0.5],center=true); // origin
difference() {
union() {
translate([0,-10,0]) square([width,20],center=true); // panel top at origin
nHa=kvGet(profile,"notch.heightAllowance");
if (nHa>0) // notchHeightAllowance above origin
translate([0,nHa/2-0.5,0]) square([width,nHa+1],center=true);
}
children();
}
color(color) children();
}
module demoF(width,color) {
color("red") translate([0,0,1]) square([width,0.5],center=true); // origin
difference() {
square([width,20],center=true);
children();
}
color(color) children();
}
}
module Notch_Demo() {
include <orientation.scad>
panelThickness = 3;
profile1 = NotchProfile( panelThickness = panelThickness );
profile2 = NotchProfile( panelThickness = panelThickness,
notchWidthAllowance = -1, holeWidthAllowance = 1,
notchHeightAllowance = 3, holeHeightAllowance = 1,
leftGap = 10, rightGap = 10
);
// *** MALE/FEMALE ***
translate([0,0,0]) {
solid() malePanel(80,profile1)
/* ▶ */ Notch( 80, 2, profile1 );
OBack(panelThickness) color("green",0.5) solid() femalePanel(80)
/* ▶ */ Notch( 80, -2, profile1 );
}
// *** MALE/MALE BROMANCE ***
translate([0,50,0]) {
OTop(panelThickness) solid() malePanel(80,profile1)
/* ▶ */ Notch( 80, 2, profile1 );
OBack(panelThickness) color("green",0.5) solid() malePanel(80,profile1)
/* ▶ */ NotchEdge( 80, 2, profile1, punchGap=false );
}
// *** MALE/FEMALE WITH ADJUSTMENTS ***
translate([0,100,0]) {
solid() malePanel(100,profile2)
/* ▶ */ Notch( 100, 2, profile2 );
OBack(panelThickness) color("green",0.5) solid() femalePanel(100)
/* ▶ */ Notch( 100, -2, profile2 );
}
// *** MALE/MALE BROMANCE WITH ADJUSTMENTS ***
translate([0,150,0]) {
OTop(panelThickness) solid() malePanel(100,profile2)
/* ▶ */ Notch( 100, 2, profile2 );
OBack(panelThickness) color("green",0.5) solid() malePanel(100,profile2)
/* ▶ */ NotchEdge( 100, 2, profile2, punchGap=false );
}
module solid() linear_extrude(panelThickness,center=true) children();
module malePanel(width,profile) {
difference() {
union() {
translate([0,-10,0]) square([width,20],center=true); // panel top at origin
nHa=kvGet(profile,"notch.heightAllowance");
if (nHa>0) // notchHeightAllowance above origin
translate([0,nHa/2-0.5,0]) square([width,nHa+1],center=true);
}
children();
}
}
module femalePanel(width) {
difference() {
square([width,20],center=true);
children();
}
}
}
module Notch_Assembly_Demo() {
include <positioning.scad>
include <orientation.scad>
W = 80; // width
D = 50; // depth
H = 100; // height
T = 3; // panel thickness
S1 = 10; // shelf1 position (from bottom)
S2 = 50; // shelf2 position (from bottom)
SF1 = S1+T/2; // shelf1 front panel height
SF2 = H-S2+T/2; // shelf2 front panel height
profile = NotchProfile(panelThickness=T);
assembly();
translate([120,0,0])
rotate([0,0,180])
assembly();
module assembly() {
CubeExtents(W,D,H);
// shelves
color("LightGrey") OBottom(0,H/2-S1) solid() shelfBottom();
color("LightGrey") OBottom(0,H/2-S2) solid() shelfBottom();
// walls
OLeft (T,W/2) solid() walls();
ORight(T,W/2) solid() rotate([0,180,0]) walls();
// shelves front panel
color("gray") OFront(T,D/2,0,-H/2+SF1/2) solid() frontPanel1();
color("gray") OFront(T,D/2,0, H/2-SF2/2) solid() frontPanel2();
// back panel
color("DarkGray") OBack (T,D/2) solid() back();
}
module solid() linear_extrude(T,center=true) children();
module walls() {
punch() {
square([D,H],center=true);
union() {
MUp(S1) PBottom(H) Notch (D,-2,profile); // holes for shelf bottom
MUp(S2) PBottom(H) Notch (D,-2,profile);
PRight(D) NotchEdge(H,3,profile); // back panel
// shelves front panel
PLeft(D) NotchEdge(H,1,profile,punchGap=false,rightGap=H-SF1);
PLeft(D) NotchEdge(H,2,profile,punchGap=false,leftGap =H-SF2);
}
}
}
module back() {
punch() {
square([W,H],center=true);
union() {
PLeft(W) Notch(H,3,profile); // walls
PRight(W) Notch(H,3,profile);
MUp(S1) PBottom(H) Notch(W,-2,profile); // shelves bottom
MUp(S2) PBottom(H) Notch(W,-2,profile);
}
}
}
module shelfBottom() {
punch() {
square([W,D],center=true);
union() {
PLeft(W) Notch (D,2,profile); // walls
PRight(W) Notch (D,2,profile);
PBottom(D) NotchEdge(W,2,profile); // front
PTop(D) Notch (W,2,profile); // back
}
}
}
module frontPanel1() {
punch() {
square([W,SF1],center=true);
union() {
PLeft(W) Notch(SF1,1,profile); // walls
PRight(W) Notch(SF1,1,profile);
PTop(SF1) Notch(W,2,profile); // front
}
}
}
module frontPanel2() {
punch() {
square([W,SF2],center=true);
union() {
PLeft(W) Notch(SF2,2,profile); // walls
PRight(W) Notch(SF2,2,profile);
PBottom(SF2) Notch(W,2,profile); // front
}
}
}
// to diagnose a part while designing,
// set debug to true and generate the part. ex:
// debug=true;
// walls();
debug=false;
module punch() {
if (debug) {
color("green",0.5)
difference() {
children(0); children(1);
}
children(1);
} else {
difference() {
children(0); children(1);
}
}
}
}
//
// NOTCH
//
// FEMALE:
// +-------------------+
// | +---+ +---+ |
// | | | | | | holeHeight + holeHeightAllowance
// | +---+ +---+ |
// +-------------------+
// -->| |<-- computed holeWidth + holeWidthAllowance
//
//
// MALE: -->| |<-- computed notchWidth + notchWidthAllowance
// +---+ +---+
// | | | | notchHeight + nothHeightAllowance
// +---+ +---+ +---+
// | |
function NotchProfile(
panelThickness, // settings for both notchHeight and holeHeight
notchHeight, // height of notch, usually same as panel thickness
holeHeight, // height of holes, usually same as panel thickness
notchWidthAllowance = 0, // allowance when creating notches, - smaller, to fit notches
notchHeightAllowance = 0, // to adjust protrusion to the other face when inserted
holeWidthAllowance = 0, // allowance when creating holes, + bigger, to for notches
holeHeightAllowance = 0, // ...
// params to Notch()/NotchEdge(), for default
// but can be overridden when calling those modules
punchGap = undef,
leftGap = 0, // ... will be added to supplied params
rightGap = 0, // ... will be added to supplied params
fromEdge = undef,
additive = undef,
) = let(
eNotchHeight = (notchHeight==undef)?panelThickness:notchHeight,
eHoleHeight = (holeHeight ==undef)?panelThickness:holeHeight,
e1=ErrorIf(eNotchHeight==undef, "notchHeight or panelThickness required" ),
e2=ErrorIf(eHoleHeight ==undef, "holeHeight or panelThickness required" )
) KVTree([
"notch", KVTree([ "height", eNotchHeight, "widthAllowance", notchWidthAllowance, "heightAllowance", notchHeightAllowance ]),
"hole", KVTree([ "height", eHoleHeight, "widthAllowance", holeWidthAllowance, "heightAllowance", holeHeightAllowance ]),
"defaults", KVTree([ "punchGap", punchGap, "leftGap", leftGap, "rightGap", rightGap, "fromEdge", fromEdge, "additive", additive ])
]);
module Notch(targetWidth,notches,profile,punchGap,leftGap=0,rightGap=0,additive,fromEdge) {
// notches value fromEdge result notes
// -------- ----- -------- |-------------------| -----
//
// positive 2 false +---+ +---+ 2 notches centered
// +---+ +---+ +---+
//
// negative -2 false | ##### ##### | 2 holes centered
//
// positive [ 2] -any- +---+ +---+ +---+ partner of "2 nothces centered"
// 2 true | +---+ +---+ | ... so 3 notches edge to edge
//
// negative [-2] -any ##### ##### ##### holes for partner of "2 notches centered"
// -2 true ... so 3 holes edge to edge
//
// ex. male/male connected, visually 2 and 2:
// Notch(notches=2)
// Notch(notches=2,fromEdge=true)
// vs. male/male connected, visually 2 and 3:
// Notch(notches=2)
// Notch(notches=3,fromEdge=true)
defaults = kvGet(profile,"defaults");
eFromEdge = is_list(notches) || SELECT(fromEdge,kvGet(defaults,"fromEdge"),false);
value = is_list(notches)?notches[0]:notches;
eNotch = abs(value);
ExitIf(eNotch<=0,"invalid notches");
if (value<=0) {
notchFemale(targetWidth,eNotch,profile,eFromEdge,leftGap,rightGap);
} else {
eAdditive=SELECT(additive,kvGet(defaults,"additive"),false);
if (eAdditive)
notchMaleAdditive(targetWidth,eNotch,profile,eFromEdge,leftGap,rightGap);
else
notchMale(targetWidth,eNotch,profile,eFromEdge,punchGap,leftGap,rightGap);
}
}
module NotchEdge(targetWidth,notches,profile,punchGap,leftGap=0,rightGap=0,additive,notEdge) {
// same notes as Notch(), but reversed
//
// ex. male/male connected, visually 2 and 2:
// Notch (notches=2)
// NotchEdge(notches=2)
eNotEdge=is_list(notches) || (notEdge==true);
value =is_list(notches)?notches[0]:notches;
Notch(targetWidth,value,profile,punchGap,leftGap,rightGap,additive,!eNotEdge);
}
module notchMaleAdditive(targetWidth,notches,profile,fromEdge,leftGap=0,rightGap=0) {
// for union() to panels
overlap = 1; // extra at the bottom for clean union
notch = kvGet(profile,"notch");
notchHeight = kvGet(notch,"height" );
nWa = kvGet(notch,"widthAllowance" );
nHa = kvGet(notch,"heightAllowance");
defaults = kvGet(profile,"defaults");
eFromEdge = SELECT(fromEdge,kvGet(defaults,"fromEdge"),false);
eGapLeft = kvGet(defaults,"leftGap" ) + leftGap;
eGapRight = kvGet(defaults,"rightGap") + rightGap;
effWidth = targetWidth-eGapLeft-eGapRight;
div = notches*2+1;
notchWidth = effWidth/div;
translate( [eGapLeft/2-eGapRight/2,notchHeight/2+nHa/2-overlap/2,0] )
notchRepeater(effWidth,notches,eFromEdge)
square( [notchWidth+nWa,notchHeight+nHa+overlap], center=true );
}
module notchMale(targetWidth,notches,profile,fromEdge,punchGap,leftGap=0,rightGap=0) {
// for difference() to panels
overlap = 1; // extra on top for clean punch
gapOverlap = 0.0001;
notch = kvGet(profile,"notch");
notchHeight = kvGet(notch,"height" );
nWa = kvGet(notch,"widthAllowance" );
nHa = kvGet(notch,"heightAllowance");
defaults = kvGet(profile,"defaults" );
eFromEdge = SELECT(fromEdge,kvGet(defaults,"fromEdge"),false);
ePunchGap = SELECT(punchGap,kvGet(defaults,"punchGap"),true);
eGapLeft = kvGet(defaults,"leftGap" ) + leftGap;
eGapRight = kvGet(defaults,"rightGap") + rightGap;
effWidth = targetWidth-eGapLeft-eGapRight;
div = notches*2+1;
punchWidth = effWidth/div;
// notchHeightAllowance > 0, higher notches
//
// increase notch height
// move pattern up by heightAllowance
//
// assume user has positioned panel +notchHeightAllowance above the origin
// for easier positioning with female panel, eg. female still anchored on origin
//
// ### <-- heightAllowance if +, above y-axis
// --+---###---+---- y-axis
// | F ### | # - notch
// +---###---+ F - female panel
// | M | M - male panel
//
// otherwise, need to move female panel down by notchHeightAllowance
//
// ------###-------- y-axis
// +---###---+
// | F ### | # - notch
// +---###---+ F - female panel
// | M | M - male panel
//
// notchHeightAllowance < 0, increase notch height below origin
//
// use same cutting depth without allowance
// remove strip on top of the whole panel, female still anchored on origin
//
// --+---------+---- y-axis
// | F ### | # - notch
// +---###---+ F - female panel
// | M | M - male panel
//
eHeight=(nHa>=0)?notchHeight+nHa:notchHeight;
yOffset=(nHa>=0)?nHa :0 ;
translate( [0,yOffset,0] ) {
// notEdge, notches = 2
// +---+ +---+
// +---+ +---+ +---+
// | |
//
// edge, notches = 2
// +---+ +---+ +---+
// | +---+ +---+ |
// | |
effOffset=eGapLeft/2-eGapRight/2;
// we are punching so reverse allowance and notch positions
translate( [effOffset,-eHeight/2+overlap/2,0] ) {
notchRepeater(effWidth,notches,!eFromEdge)
square( [punchWidth-nWa,eHeight+overlap], center=true );
if (nWa>0) {
// width was increased, therefore punch was reduced
// there will be leftoever material on the leftmost/rightmost
// notch which will not be present had it been additive
offset =effWidth/2-gapOverlap/2-nWa/4;
gapWidth=gapOverlap*2+nWa/2;
//color("green") translate([0,2,0])
translate([-offset,0,0] )
square([gapWidth,eHeight+overlap],center=true);
//color("green") translate([0,2,0])
translate([offset,0,0])
square([gapWidth,eHeight+overlap],center=true);
}
}
if (nHa<0) {
// remove strip from top
translate([effOffset,nHa/2+overlap/2,0])
square([effWidth+gapOverlap*2,-nHa+overlap],center=true);
}
if (ePunchGap) {
// punch out left/right gaps
if (eGapLeft!=0) // && eGapLeft<=targetWidth)
translate([-targetWidth/2-gapOverlap,-eHeight,0])
square([eGapLeft+gapOverlap*2,eHeight+overlap]);
if (eGapRight!=0) // && eGapRight<=targetWidth)
translate([targetWidth/2-eGapRight,-eHeight,0])
square([eGapRight+gapOverlap*2,eHeight+overlap]);
}
}
}
module notchFemale(targetWidth,notches,profile,fromEdge,leftGap=0,rightGap=0) {
// holes to receive notches
hole = kvGet(profile,"hole");
holeHeight = kvGet(hole,"height" );
hWa = kvGet(hole,"widthAllowance" );
hHa = kvGet(hole,"heightAllowance");
defaults = kvGet(profile,"defaults");
eFromEdge = SELECT(fromEdge,kvGet(defaults,"fromEdge"),false);
eGapLeft = kvGet(defaults,"leftGap" ) + leftGap;
eGapRight = kvGet(defaults,"rightGap") + rightGap;
effWidth = targetWidth-eGapLeft-eGapRight;
div = notches*2+1;
holeWidth = effWidth/div;
translate([eGapLeft/2-eGapRight/2,0,0])
notchRepeater(effWidth,notches,eFromEdge)
square([holeWidth+hWa,holeHeight+hHa],center=true);
if (eFromEdge && hWa==0) {
// if widthAllowance +, will already punch cleanly
// if widthAllowance -, user wants space ???
// if widthAllowance 0, add extra to punch cleanly
overlap = 1;
if (eGapLeft==0) {
translate([-targetWidth/2,0,0])
square([overlap,holeHeight+hHa],center=true);
}
if (eGapRight==0) {
translate([targetWidth/2,0,0])
square([overlap,holeHeight+hHa],center=true);
}
}
}
//
// REPEATERS
//
module notchRepeater(targetWidth,notches,fromEdge=false) {
if (fromEdge)
notchRepeaterOutside(targetWidth,notches) children();
else
notchRepeaterInside(targetWidth,notches) children();
}
module notchRepeaterInside(targetWidth,notches) {
// ### ###
// +-- --- --+
// | |
div =notches*2+1;
notchSize=targetWidth/div;
translate([-(notches-1)*notchSize,0,0])
for( i=[0:notches-1] ) {
translate([i*notchSize*2,0,0])
children();
}
}
module notchRepeaterOutside(targetWidth,notches) {
// ### ### ###
// | --- --- |
// | |
div =notches*2+1;
notchSize=targetWidth/div;
translate([-notches*notchSize,0,0])
for( i=[0:notches] ) {
translate([i*notchSize*2,0,0])
children();
}
}