forked from BelfrySCAD/BOSL2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshapes.scad
1755 lines (1673 loc) · 72.1 KB
/
shapes.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
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////
// LibFile: shapes.scad
// Common useful shapes and structured objects.
// To use, add the following lines to the beginning of your file:
// ```
// include <BOSL2/std.scad>
// ```
//////////////////////////////////////////////////////////////////////
// Section: Cuboids
// Module: cuboid()
//
// Description:
// Creates a cube or cuboid object, with optional chamfering or rounding.
// Negative chamfers and roundings can be applied to create external masks,
// but only apply to edges around the top or bottom faces.
//
// Arguments:
// size = The size of the cube.
// chamfer = Size of chamfer, inset from sides. Default: No chamfering.
// rounding = Radius of the edge rounding. Default: No rounding.
// edges = Edges to chamfer/round. See the docs for [`edges()`](edges.scad#edges) to see acceptable values. Default: All edges.
// except_edges = Edges to explicitly NOT chamfer/round. See the docs for [`edges()`](edges.scad#edges) to see acceptable values. Default: No edges.
// trimcorners = If true, rounds or chamfers corners where three chamfered/rounded edges meet. Default: `true`
// p1 = Align the cuboid's corner at `p1`, if given. Forces `anchor=ALLNEG`.
// p2 = If given with `p1`, defines the cornerpoints of the cuboid.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis. See [spin](attachments.scad#spin). Default: `0`
// orient = Vector to rotate top towards. See [orient](attachments.scad#orient). Default: `UP`
//
// Example: Simple regular cube.
// cuboid(40);
// Example: Cube with minimum cornerpoint given.
// cuboid(20, p1=[10,0,0]);
// Example: Rectangular cube, with given X, Y, and Z sizes.
// cuboid([20,40,50]);
// Example: Cube by Opposing Corners.
// cuboid(p1=[0,10,0], p2=[20,30,30]);
// Example: Chamferred Edges and Corners.
// cuboid([30,40,50], chamfer=5);
// Example: Chamferred Edges, Untrimmed Corners.
// cuboid([30,40,50], chamfer=5, trimcorners=false);
// Example: Rounded Edges and Corners
// cuboid([30,40,50], rounding=10);
// Example: Rounded Edges, Untrimmed Corners
// cuboid([30,40,50], rounding=10, trimcorners=false);
// Example: Chamferring Selected Edges
// cuboid([30,40,50], chamfer=5, edges=[TOP+FRONT,TOP+RIGHT,FRONT+RIGHT], $fn=24);
// Example: Rounding Selected Edges
// cuboid([30,40,50], rounding=5, edges=[TOP+FRONT,TOP+RIGHT,FRONT+RIGHT], $fn=24);
// Example: Negative Chamferring
// cuboid([30,40,50], chamfer=-5, edges=[TOP,BOT], except_edges=RIGHT, $fn=24);
// Example: Negative Chamferring, Untrimmed Corners
// cuboid([30,40,50], chamfer=-5, edges=[TOP,BOT], except_edges=RIGHT, trimcorners=false, $fn=24);
// Example: Negative Rounding
// cuboid([30,40,50], rounding=-5, edges=[TOP,BOT], except_edges=RIGHT, $fn=24);
// Example: Negative Rounding, Untrimmed Corners
// cuboid([30,40,50], rounding=-5, edges=[TOP,BOT], except_edges=RIGHT, trimcorners=false, $fn=24);
// Example: Standard Connectors
// cuboid(40) show_anchors();
module cuboid(
size=[1,1,1],
p1=undef, p2=undef,
chamfer=undef,
rounding=undef,
edges=EDGES_ALL,
except_edges=[],
trimcorners=true,
anchor=CENTER,
spin=0,
orient=UP
) {
size = scalar_vec3(size);
edges = edges(edges, except=except_edges);
if (!is_undef(p1)) {
if (!is_undef(p2)) {
translate(pointlist_bounds([p1,p2])[0]) {
cuboid(size=vabs(p2-p1), chamfer=chamfer, rounding=rounding, edges=edges, trimcorners=trimcorners, anchor=ALLNEG) children();
}
} else {
translate(p1) {
cuboid(size=size, chamfer=chamfer, rounding=rounding, edges=edges, trimcorners=trimcorners, anchor=ALLNEG) children();
}
}
} else {
if (chamfer != undef) {
if (any(edges[0])) assert(chamfer <= size.y/2 && chamfer <=size.z/2, "chamfer must be smaller than half the cube length or height.");
if (any(edges[1])) assert(chamfer <= size.x/2 && chamfer <=size.z/2, "chamfer must be smaller than half the cube width or height.");
if (any(edges[2])) assert(chamfer <= size.x/2 && chamfer <=size.y/2, "chamfer must be smaller than half the cube width or length.");
}
if (rounding != undef) {
if (any(edges[0])) assert(rounding <= size.y/2 && rounding<=size.z/2, "rounding radius must be smaller than half the cube length or height.");
if (any(edges[1])) assert(rounding <= size.x/2 && rounding<=size.z/2, "rounding radius must be smaller than half the cube width or height.");
if (any(edges[2])) assert(rounding <= size.x/2 && rounding<=size.y/2, "rounding radius must be smaller than half the cube width or length.");
}
majrots = [[0,90,0], [90,0,0], [0,0,0]];
attachable(anchor,spin,orient, size=size) {
if (chamfer != undef) {
if (edges == EDGES_ALL && trimcorners) {
if (chamfer<0) {
cube(size, center=true) {
attach(TOP) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
attach(BOT) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
}
} else {
isize = [for (v = size) max(0.001, v-2*chamfer)];
hull() {
cube([size.x, isize.y, isize.z], center=true);
cube([isize.x, size.y, isize.z], center=true);
cube([isize.x, isize.y, size.z], center=true);
}
}
} else if (chamfer<0) {
ach = abs(chamfer);
cube(size, center=true);
// External-Chamfer mask edges
difference() {
union() {
for (i = [0:3], axis=[0:1]) {
if (edges[axis][i]>0) {
vec = EDGE_OFFSETS[axis][i];
translate(vmul(vec/2, size+[ach,ach,-ach])) {
rotate(majrots[axis]) {
cube([ach, ach, size[axis]], center=true);
}
}
}
}
// Add multi-edge corners.
if (trimcorners) {
for (za=[-1,1], ya=[-1,1], xa=[-1,1]) {
if (corner_edge_count(edges, [xa,ya,za]) > 1) {
translate(vmul([xa,ya,za]/2, size+[ach-0.01,ach-0.01,-ach])) {
cube([ach+0.01,ach+0.01,ach], center=true);
}
}
}
}
}
// Remove bevels from overhangs.
for (i = [0:3], axis=[0:1]) {
if (edges[axis][i]>0) {
vec = EDGE_OFFSETS[axis][i];
translate(vmul(vec/2, size+[2*ach,2*ach,-2*ach])) {
rotate(majrots[axis]) {
zrot(45) cube([ach*sqrt(2), ach*sqrt(2), size[axis]+2.1*ach], center=true);
}
}
}
}
}
} else {
difference() {
cube(size, center=true);
// Chamfer edges
for (i = [0:3], axis=[0:2]) {
if (edges[axis][i]>0) {
translate(vmul(EDGE_OFFSETS[axis][i], size/2)) {
rotate(majrots[axis]) {
zrot(45) cube([chamfer*sqrt(2), chamfer*sqrt(2), size[axis]+0.01], center=true);
}
}
}
}
// Chamfer triple-edge corners.
if (trimcorners) {
for (za=[-1,1], ya=[-1,1], xa=[-1,1]) {
if (corner_edge_count(edges, [xa,ya,za]) > 2) {
translate(vmul([xa,ya,za]/2, size-[1,1,1]*chamfer*4/3)) {
rot(from=UP, to=[xa,ya,za]) {
cube(chamfer*3, anchor=BOTTOM);
}
}
}
}
}
}
}
} else if (rounding != undef) {
sides = quantup(segs(rounding),4);
if (edges == EDGES_ALL) {
if(rounding<0) {
cube(size, center=true);
zflip_copy() {
up(size.z/2) {
difference() {
down(-rounding/2) cube([size.x-2*rounding, size.y-2*rounding, -rounding], center=true);
down(-rounding) {
ycopies(size.y-2*rounding) xcyl(l=size.x-3*rounding, r=-rounding);
xcopies(size.x-2*rounding) ycyl(l=size.y-3*rounding, r=-rounding);
}
}
}
}
} else {
isize = [for (v = size) max(0.001, v-2*rounding)];
minkowski() {
cube(isize, center=true);
if (trimcorners) {
spheroid(r=rounding, style="octa", $fn=sides);
} else {
intersection() {
cyl(r=rounding, h=rounding*2, $fn=sides);
rotate([90,0,0]) cyl(r=rounding, h=rounding*2, $fn=sides);
rotate([0,90,0]) cyl(r=rounding, h=rounding*2, $fn=sides);
}
}
}
}
} else if (rounding<0) {
ard = abs(rounding);
cube(size, center=true);
// External-Chamfer mask edges
difference() {
union() {
for (i = [0:3], axis=[0:1]) {
if (edges[axis][i]>0) {
vec = EDGE_OFFSETS[axis][i];
translate(vmul(vec/2, size+[ard,ard,-ard])) {
rotate(majrots[axis]) {
cube([ard, ard, size[axis]], center=true);
}
}
}
}
// Add multi-edge corners.
if (trimcorners) {
for (za=[-1,1], ya=[-1,1], xa=[-1,1]) {
if (corner_edge_count(edges, [xa,ya,za]) > 1) {
translate(vmul([xa,ya,za]/2, size+[ard-0.01,ard-0.01,-ard])) {
cube([ard+0.01,ard+0.01,ard], center=true);
}
}
}
}
}
// Remove roundings from overhangs.
for (i = [0:3], axis=[0:1]) {
if (edges[axis][i]>0) {
vec = EDGE_OFFSETS[axis][i];
translate(vmul(vec/2, size+[2*ard,2*ard,-2*ard])) {
rotate(majrots[axis]) {
cyl(l=size[axis]+2.1*ard, r=ard);
}
}
}
}
}
} else {
difference() {
cube(size, center=true);
// Round edges.
for (i = [0:3], axis=[0:2]) {
if (edges[axis][i]>0) {
difference() {
translate(vmul(EDGE_OFFSETS[axis][i], size/2)) {
rotate(majrots[axis]) cube([rounding*2, rounding*2, size[axis]+0.1], center=true);
}
translate(vmul(EDGE_OFFSETS[axis][i], size/2 - [1,1,1]*rounding)) {
rotate(majrots[axis]) cyl(h=size[axis]+0.2, r=rounding, $fn=sides);
}
}
}
}
// Round triple-edge corners.
if (trimcorners) {
for (za=[-1,1], ya=[-1,1], xa=[-1,1]) {
if (corner_edge_count(edges, [xa,ya,za]) > 2) {
difference() {
translate(vmul([xa,ya,za], size/2)) {
cube(rounding*2, center=true);
}
translate(vmul([xa,ya,za], size/2-[1,1,1]*rounding)) {
spheroid(r=rounding, style="octa", $fn=sides);
}
}
}
}
}
}
}
} else {
cube(size=size, center=true);
}
children();
}
}
}
// Section: Prismoids
// Function&Module: prismoid()
//
// Usage: As Module
// prismoid(size1, size2, h|l, [shift], [rounding], [chamfer]);
// prismoid(size1, size2, h|l, [shift], [rounding1], [rounding2], [chamfer1], [chamfer2]);
// Usage: As Function
// vnf = prismoid(size1, size2, h|l, [shift], [rounding], [chamfer]);
// vnf = prismoid(size1, size2, h|l, [shift], [rounding1], [rounding2], [chamfer1], [chamfer2]);
//
// Description:
// Creates a rectangular prismoid shape with optional roundovers and chamfering.
// You can only round or chamfer the vertical(ish) edges. For those edges, you can
// specify rounding and/or chamferring per-edge, and for top and bottom separately.
// Note: if using chamfers or rounding, you **must** also include the hull.scad file:
// ```
// include <BOSL2/hull.scad>
// ```
//
// Arguments:
// size1 = [width, length] of the axis-negative end of the prism.
// size2 = [width, length] of the axis-positive end of the prism.
// h|l = Height of the prism.
// shift = [X,Y] amount to shift the center of the top with respect to the center of the bottom.
// rounding = The roundover radius for the edges of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual radii for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-]. Default: 0 (no rounding)
// rounding1 = The roundover radius for the bottom corners of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual radii for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-].
// rounding2 = The roundover radius for the top corners of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual radii for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-].
// chamfer = The chamfer size for the edges of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-]. Default: 0 (no chamfer)
// chamfer1 = The chamfer size for the bottom corners of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-].
// chamfer2 = The chamfer size for the top corners of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-].
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP`
//
// Example: Rectangular Pyramid
// prismoid([40,40], [0,0], h=20);
// Example: Prism
// prismoid(size1=[40,40], size2=[0,40], h=20);
// Example: Truncated Pyramid
// prismoid(size1=[35,50], size2=[20,30], h=20);
// Example: Wedge
// prismoid(size1=[60,35], size2=[30,0], h=30);
// Example: Truncated Tetrahedron
// prismoid(size1=[10,40], size2=[40,10], h=40);
// Example: Inverted Truncated Pyramid
// prismoid(size1=[15,5], size2=[30,20], h=20);
// Example: Right Prism
// prismoid(size1=[30,60], size2=[0,60], shift=[-15,0], h=30);
// Example(FlatSpin): Shifting/Skewing
// prismoid(size1=[50,30], size2=[20,20], h=20, shift=[15,5]);
// Example: Rounding
// include <BOSL2/hull.scad>
// prismoid(100, 80, rounding=10, h=30);
// Example: Outer Chamfer Only
// include <BOSL2/hull.scad>
// prismoid(100, 80, chamfer=5, h=30);
// Example: Gradiant Rounding
// include <BOSL2/hull.scad>
// prismoid(100, 80, rounding1=10, rounding2=0, h=30);
// Example: Per Corner Rounding
// include <BOSL2/hull.scad>
// prismoid(100, 80, rounding=[0,5,10,15], h=30);
// Example: Per Corner Chamfer
// include <BOSL2/hull.scad>
// prismoid(100, 80, chamfer=[0,5,10,15], h=30);
// Example: Mixing Chamfer and Rounding
// include <BOSL2/hull.scad>
// prismoid(100, 80, chamfer=[0,5,0,10], rounding=[5,0,10,0], h=30);
// Example: Really Mixing It Up
// include <BOSL2/hull.scad>
// prismoid(
// size1=[100,80], size2=[80,60], h=20,
// chamfer1=[0,5,0,10], chamfer2=[5,0,10,0],
// rounding1=[5,0,10,0], rounding2=[0,5,0,10]
// );
// Example(Spin): Standard Connectors
// prismoid(size1=[50,30], size2=[20,20], h=20, shift=[15,5])
// show_anchors();
module prismoid(
size1, size2, h, shift=[0,0],
rounding=0, rounding1, rounding2,
chamfer=0, chamfer1, chamfer2,
l, center,
anchor, spin=0, orient=UP
) {
assert(is_num(size1) || is_vector(size1,2));
assert(is_num(size2) || is_vector(size2,2));
assert(is_num(h) || is_num(l));
assert(is_vector(shift,2));
assert(is_num(rounding) || is_vector(rounding,4), "Bad rounding argument.");
assert(is_undef(rounding1) || is_num(rounding1) || is_vector(rounding1,4), "Bad rounding1 argument.");
assert(is_undef(rounding2) || is_num(rounding2) || is_vector(rounding2,4), "Bad rounding2 argument.");
assert(is_num(chamfer) || is_vector(chamfer,4), "Bad chamfer argument.");
assert(is_undef(chamfer1) || is_num(chamfer1) || is_vector(chamfer1,4), "Bad chamfer1 argument.");
assert(is_undef(chamfer2) || is_num(chamfer2) || is_vector(chamfer2,4), "Bad chamfer2 argument.");
eps = pow(2,-14);
size1 = is_num(size1)? [size1,size1] : size1;
size2 = is_num(size2)? [size2,size2] : size2;
s1 = [max(size1.x, eps), max(size1.y, eps)];
s2 = [max(size2.x, eps), max(size2.y, eps)];
rounding1 = default(rounding1, rounding);
rounding2 = default(rounding2, rounding);
chamfer1 = default(chamfer1, chamfer);
chamfer2 = default(chamfer2, chamfer);
anchor = get_anchor(anchor, center, BOT, BOT);
vnf = prismoid(
size1=size1, size2=size2, h=h, shift=shift,
rounding=rounding, rounding1=rounding1, rounding2=rounding2,
chamfer=chamfer, chamfer1=chamfer1, chamfer2=chamfer2,
l=l, center=CENTER
);
attachable(anchor,spin,orient, size=[s1.x,s1.y,h], size2=s2, shift=shift) {
vnf_polyhedron(vnf, convexity=4);
children();
}
}
function prismoid(
size1, size2, h, shift=[0,0],
rounding=0, rounding1, rounding2,
chamfer=0, chamfer1, chamfer2,
l, center,
anchor=DOWN, spin=0, orient=UP
) =
assert(is_vector(size1,2))
assert(is_vector(size2,2))
assert(is_num(h) || is_num(l))
assert(is_vector(shift,2))
assert(is_num(rounding) || is_vector(rounding,4), "Bad rounding argument.")
assert(is_undef(rounding1) || is_num(rounding1) || is_vector(rounding1,4), "Bad rounding1 argument.")
assert(is_undef(rounding2) || is_num(rounding2) || is_vector(rounding2,4), "Bad rounding2 argument.")
assert(is_num(chamfer) || is_vector(chamfer,4), "Bad chamfer argument.")
assert(is_undef(chamfer1) || is_num(chamfer1) || is_vector(chamfer1,4), "Bad chamfer1 argument.")
assert(is_undef(chamfer2) || is_num(chamfer2) || is_vector(chamfer2,4), "Bad chamfer2 argument.")
let(
eps = pow(2,-14),
h = first_defined([h,l,1]),
shiftby = point3d(point2d(shift)),
s1 = [max(size1.x, eps), max(size1.y, eps)],
s2 = [max(size2.x, eps), max(size2.y, eps)],
rounding1 = default(rounding1, rounding),
rounding2 = default(rounding2, rounding),
chamfer1 = default(chamfer1, chamfer),
chamfer2 = default(chamfer2, chamfer),
anchor = get_anchor(anchor, center, BOT, BOT),
vnf = (rounding1==0 && rounding2==0 && chamfer1==0 && chamfer2==0)? (
let(
corners = [[1,1],[1,-1],[-1,-1],[-1,1]] * 0.5,
points = [
for (p=corners) point3d(vmul(s2,p), +h/2) + shiftby,
for (p=corners) point3d(vmul(s1,p), -h/2)
],
faces=[
[0,1,2], [0,2,3], [0,4,5], [0,5,1],
[1,5,6], [1,6,2], [2,6,7], [2,7,3],
[3,7,4], [3,4,0], [4,7,6], [4,6,5],
]
) [points, faces]
) : (
let(
path1 = rect(size1, rounding=rounding1, chamfer=chamfer1, anchor=CTR),
path2 = rect(size2, rounding=rounding2, chamfer=chamfer2, anchor=CTR),
points = [
each path3d(path1, -h/2),
each path3d(move(shiftby, p=path2), +h/2),
],
faces = hull(points)
) [points, faces]
)
) reorient(anchor,spin,orient, size=[s1.x,s1.y,h], size2=s2, shift=shift, p=vnf);
// Module: right_triangle()
//
// Usage:
// right_triangle(size, [center]);
//
// Description:
// Creates a 3D right triangular prism with the hypotenuse in the X+Y+ quadrant.
//
// Arguments:
// size = [width, thickness, height]
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `ALLNEG`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP`
//
// Example: Centered
// right_triangle([60, 40, 10], center=true);
// Example: *Non*-Centered
// right_triangle([60, 40, 10]);
// Example: Standard Connectors
// right_triangle([60, 40, 15]) show_anchors();
module right_triangle(size=[1, 1, 1], center, anchor, spin=0, orient=UP)
{
size = scalar_vec3(size);
anchor = get_anchor(anchor, center, ALLNEG, ALLNEG);
attachable(anchor,spin,orient, size=size) {
linear_extrude(height=size.z, convexity=2, center=true) {
polygon([[-size.x/2,-size.y/2], [-size.x/2,size.y/2], [size.x/2,-size.y/2]]);
}
children();
}
}
// Section: Cylindroids
// Module: cyl()
//
// Description:
// Creates cylinders in various anchors and orientations,
// with optional rounding and chamfers. You can use `r` and `l`
// interchangably, and all variants allow specifying size
// by either `r`|`d`, or `r1`|`d1` and `r2`|`d2`.
// Note that that chamfers and rounding cannot cross the
// midpoint of the cylinder's length.
//
// Usage: Normal Cylinders
// cyl(l|h, r|d, [circum], [realign], [center]);
// cyl(l|h, r1|d1, r2/d2, [circum], [realign], [center]);
//
// Usage: Chamferred Cylinders
// cyl(l|h, r|d, chamfer, [chamfang], [from_end], [circum], [realign], [center]);
// cyl(l|h, r|d, chamfer1, [chamfang1], [from_end], [circum], [realign], [center]);
// cyl(l|h, r|d, chamfer2, [chamfang2], [from_end], [circum], [realign], [center]);
// cyl(l|h, r|d, chamfer1, chamfer2, [chamfang1], [chamfang2], [from_end], [circum], [realign], [center]);
//
// Usage: Rounded End Cylinders
// cyl(l|h, r|d, rounding, [circum], [realign], [center]);
// cyl(l|h, r|d, rounding1, [circum], [realign], [center]);
// cyl(l|h, r|d, rounding2, [circum], [realign], [center]);
// cyl(l|h, r|d, rounding1, rounding2, [circum], [realign], [center]);
//
// Arguments:
// l / h = Length of cylinder along oriented axis. (Default: 1.0)
// r = Radius of cylinder.
// r1 = Radius of the negative (X-, Y-, Z-) end of cylinder.
// r2 = Radius of the positive (X+, Y+, Z+) end of cylinder.
// d = Diameter of cylinder.
// d1 = Diameter of the negative (X-, Y-, Z-) end of cylinder.
// d2 = Diameter of the positive (X+, Y+, Z+) end of cylinder.
// circum = If true, cylinder should circumscribe the circle of the given size. Otherwise inscribes. Default: `false`
// chamfer = The size of the chamfers on the ends of the cylinder. Default: none.
// chamfer1 = The size of the chamfer on the axis-negative end of the cylinder. Default: none.
// chamfer2 = The size of the chamfer on the axis-positive end of the cylinder. Default: none.
// chamfang = The angle in degrees of the chamfers on the ends of the cylinder.
// chamfang1 = The angle in degrees of the chamfer on the axis-negative end of the cylinder.
// chamfang2 = The angle in degrees of the chamfer on the axis-positive end of the cylinder.
// from_end = If true, chamfer is measured from the end of the cylinder, instead of inset from the edge. Default: `false`.
// rounding = The radius of the rounding on the ends of the cylinder. Default: none.
// rounding1 = The radius of the rounding on the axis-negative end of the cylinder.
// rounding2 = The radius of the rounding on the axis-positive end of the cylinder.
// realign = If true, rotate the cylinder by half the angle of one face.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP`
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=DOWN`.
//
// Example: By Radius
// xdistribute(30) {
// cyl(l=40, r=10);
// cyl(l=40, r1=10, r2=5);
// }
//
// Example: By Diameter
// xdistribute(30) {
// cyl(l=40, d=25);
// cyl(l=40, d1=25, d2=10);
// }
//
// Example: Chamferring
// xdistribute(60) {
// // Shown Left to right.
// cyl(l=40, d=40, chamfer=7); // Default chamfang=45
// cyl(l=40, d=40, chamfer=7, chamfang=30, from_end=false);
// cyl(l=40, d=40, chamfer=7, chamfang=30, from_end=true);
// }
//
// Example: Rounding
// cyl(l=40, d=40, rounding=10);
//
// Example: Heterogenous Chamfers and Rounding
// ydistribute(80) {
// // Shown Front to Back.
// cyl(l=40, d=40, rounding1=15, orient=UP);
// cyl(l=40, d=40, chamfer2=5, orient=UP);
// cyl(l=40, d=40, chamfer1=12, rounding2=10, orient=UP);
// }
//
// Example: Putting it all together
// cyl(l=40, d1=25, d2=15, chamfer1=10, chamfang1=30, from_end=true, rounding2=5);
//
// Example: External Chamfers
// cyl(l=50, r=30, chamfer=-5, chamfang=30, $fa=1, $fs=1);
//
// Example: External Roundings
// cyl(l=50, r=30, rounding1=-5, rounding2=5, $fa=1, $fs=1);
//
// Example: Standard Connectors
// xdistribute(40) {
// cyl(l=30, d=25) show_anchors();
// cyl(l=30, d1=25, d2=10) show_anchors();
// }
//
module cyl(
l=undef, h=undef,
r=undef, r1=undef, r2=undef,
d=undef, d1=undef, d2=undef,
chamfer=undef, chamfer1=undef, chamfer2=undef,
chamfang=undef, chamfang1=undef, chamfang2=undef,
rounding=undef, rounding1=undef, rounding2=undef,
circum=false, realign=false, from_end=false,
center, anchor, spin=0, orient=UP
) {
r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=1);
r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=1);
l = first_defined([l, h, 1]);
sides = segs(max(r1,r2));
sc = circum? 1/cos(180/sides) : 1;
phi = atan2(l, r2-r1);
anchor = get_anchor(anchor,center,BOT,CENTER);
attachable(anchor,spin,orient, r1=r1, r2=r2, l=l) {
zrot(realign? 180/sides : 0) {
if (!any_defined([chamfer, chamfer1, chamfer2, rounding, rounding1, rounding2])) {
cylinder(h=l, r1=r1*sc, r2=r2*sc, center=true, $fn=sides);
} else {
vang = atan2(l, r1-r2)/2;
chang1 = 90-first_defined([chamfang1, chamfang, vang]);
chang2 = 90-first_defined([chamfang2, chamfang, 90-vang]);
cham1 = first_defined([chamfer1, chamfer]) * (from_end? 1 : tan(chang1));
cham2 = first_defined([chamfer2, chamfer]) * (from_end? 1 : tan(chang2));
fil1 = first_defined([rounding1, rounding]);
fil2 = first_defined([rounding2, rounding]);
if (chamfer != undef) {
assert(chamfer <= r1, "chamfer is larger than the r1 radius of the cylinder.");
assert(chamfer <= r2, "chamfer is larger than the r2 radius of the cylinder.");
}
if (cham1 != undef) {
assert(cham1 <= r1, "chamfer1 is larger than the r1 radius of the cylinder.");
}
if (cham2 != undef) {
assert(cham2 <= r2, "chamfer2 is larger than the r2 radius of the cylinder.");
}
if (rounding != undef) {
assert(rounding <= r1, "rounding is larger than the r1 radius of the cylinder.");
assert(rounding <= r2, "rounding is larger than the r2 radius of the cylinder.");
}
if (fil1 != undef) {
assert(fil1 <= r1, "rounding1 is larger than the r1 radius of the cylinder.");
}
if (fil2 != undef) {
assert(fil2 <= r2, "rounding2 is larger than the r1 radius of the cylinder.");
}
dy1 = abs(first_defined([cham1, fil1, 0]));
dy2 = abs(first_defined([cham2, fil2, 0]));
assert(dy1+dy2 <= l, "Sum of fillets and chamfer sizes must be less than the length of the cylinder.");
path = concat(
[[0,l/2]],
!is_undef(cham2)? (
let(
p1 = [r2-cham2/tan(chang2),l/2],
p2 = lerp([r2,l/2],[r1,-l/2],abs(cham2)/l)
) [p1,p2]
) : !is_undef(fil2)? (
let(
cn = find_circle_2tangents([r2-fil2,l/2], [r2,l/2], [r1,-l/2], r=abs(fil2)),
ang = fil2<0? phi : phi-180,
steps = ceil(abs(ang)/360*segs(abs(fil2))),
step = ang/steps,
pts = [for (i=[0:1:steps]) let(a=90+i*step) cn[0]+abs(fil2)*[cos(a),sin(a)]]
) pts
) : [[r2,l/2]],
!is_undef(cham1)? (
let(
p1 = lerp([r1,-l/2],[r2,l/2],abs(cham1)/l),
p2 = [r1-cham1/tan(chang1),-l/2]
) [p1,p2]
) : !is_undef(fil1)? (
let(
cn = find_circle_2tangents([r1-fil1,-l/2], [r1,-l/2], [r2,l/2], r=abs(fil1)),
ang = fil1<0? 180-phi : -phi,
steps = ceil(abs(ang)/360*segs(abs(fil1))),
step = ang/steps,
pts = [for (i=[0:1:steps]) let(a=(fil1<0?180:0)+(phi-90)+i*step) cn[0]+abs(fil1)*[cos(a),sin(a)]]
) pts
) : [[r1,-l/2]],
[[0,-l/2]]
);
rotate_extrude(convexity=2) {
polygon(path);
}
}
}
children();
}
}
// Module: xcyl()
//
// Description:
// Creates a cylinder oriented along the X axis.
//
// Usage:
// xcyl(l|h, r|d, [anchor]);
// xcyl(l|h, r1|d1, r2|d2, [anchor]);
//
// Arguments:
// l / h = Length of cylinder along oriented axis. (Default: `1.0`)
// r = Radius of cylinder.
// r1 = Optional radius of left (X-) end of cylinder.
// r2 = Optional radius of right (X+) end of cylinder.
// d = Optional diameter of cylinder. (use instead of `r`)
// d1 = Optional diameter of left (X-) end of cylinder.
// d2 = Optional diameter of right (X+) end of cylinder.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
//
// Example: By Radius
// ydistribute(50) {
// xcyl(l=35, r=10);
// xcyl(l=35, r1=15, r2=5);
// }
//
// Example: By Diameter
// ydistribute(50) {
// xcyl(l=35, d=20);
// xcyl(l=35, d1=30, d2=10);
// }
module xcyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, anchor=CENTER)
{
anchor = rot(from=RIGHT, to=UP, p=anchor);
cyl(l=l, h=h, r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, orient=RIGHT, anchor=anchor) children();
}
// Module: ycyl()
//
// Description:
// Creates a cylinder oriented along the Y axis.
//
// Usage:
// ycyl(l|h, r|d, [anchor]);
// ycyl(l|h, r1|d1, r2|d2, [anchor]);
//
// Arguments:
// l / h = Length of cylinder along oriented axis. (Default: `1.0`)
// r = Radius of cylinder.
// r1 = Radius of front (Y-) end of cone.
// r2 = Radius of back (Y+) end of one.
// d = Diameter of cylinder.
// d1 = Diameter of front (Y-) end of one.
// d2 = Diameter of back (Y+) end of one.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
//
// Example: By Radius
// xdistribute(50) {
// ycyl(l=35, r=10);
// ycyl(l=35, r1=15, r2=5);
// }
//
// Example: By Diameter
// xdistribute(50) {
// ycyl(l=35, d=20);
// ycyl(l=35, d1=30, d2=10);
// }
module ycyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, anchor=CENTER)
{
anchor = rot(from=BACK, to=UP, p=anchor);
cyl(l=l, h=h, r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, orient=BACK, anchor=anchor) children();
}
// Module: zcyl()
//
// Description:
// Creates a cylinder oriented along the Z axis.
//
// Usage:
// zcyl(l|h, r|d, [anchor]);
// zcyl(l|h, r1|d1, r2|d2, [anchor]);
//
// Arguments:
// l / h = Length of cylinder along oriented axis. (Default: 1.0)
// r = Radius of cylinder.
// r1 = Radius of front (Y-) end of cone.
// r2 = Radius of back (Y+) end of one.
// d = Diameter of cylinder.
// d1 = Diameter of front (Y-) end of one.
// d2 = Diameter of back (Y+) end of one.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
//
// Example: By Radius
// xdistribute(50) {
// zcyl(l=35, r=10);
// zcyl(l=35, r1=15, r2=5);
// }
//
// Example: By Diameter
// xdistribute(50) {
// zcyl(l=35, d=20);
// zcyl(l=35, d1=30, d2=10);
// }
module zcyl(l=undef, r=undef, d=undef, r1=undef, r2=undef, d1=undef, d2=undef, h=undef, anchor=CENTER)
{
cyl(l=l, h=h, r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, orient=UP, anchor=anchor) children();
}
// Module: tube()
//
// Description:
// Makes a hollow tube with the given outer size and wall thickness.
//
// Usage:
// tube(h|l, ir|id, wall, [realign]);
// tube(h|l, or|od, wall, [realign]);
// tube(h|l, ir|id, or|od, [realign]);
// tube(h|l, ir1|id1, ir2|id2, wall, [realign]);
// tube(h|l, or1|od1, or2|od2, wall, [realign]);
// tube(h|l, ir1|id1, ir2|id2, or1|od1, or2|od2, [realign]);
//
// Arguments:
// h|l = height of tube. (Default: 1)
// or = Outer radius of tube.
// or1 = Outer radius of bottom of tube. (Default: value of r)
// or2 = Outer radius of top of tube. (Default: value of r)
// od = Outer diameter of tube.
// od1 = Outer diameter of bottom of tube.
// od2 = Outer diameter of top of tube.
// wall = horizontal thickness of tube wall. (Default 0.5)
// ir = Inner radius of tube.
// ir1 = Inner radius of bottom of tube.
// ir2 = Inner radius of top of tube.
// id = Inner diameter of tube.
// id1 = Inner diameter of bottom of tube.
// id2 = Inner diameter of top of tube.
// realign = If true, rotate the tube by half the angle of one face.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP`
//
// Example: These all Produce the Same Tube
// tube(h=30, or=40, wall=5);
// tube(h=30, ir=35, wall=5);
// tube(h=30, or=40, ir=35);
// tube(h=30, od=80, id=70);
// Example: These all Produce the Same Conical Tube
// tube(h=30, or1=40, or2=25, wall=5);
// tube(h=30, ir1=35, or2=20, wall=5);
// tube(h=30, or1=40, or2=25, ir1=35, ir2=20);
// Example: Circular Wedge
// tube(h=30, or1=40, or2=30, ir1=20, ir2=30);
// Example: Standard Connectors
// tube(h=30, or=40, wall=5) show_anchors();
module tube(
h, wall=undef,
r=undef, r1=undef, r2=undef,
d=undef, d1=undef, d2=undef,
or=undef, or1=undef, or2=undef,
od=undef, od1=undef, od2=undef,
ir=undef, id=undef, ir1=undef,
ir2=undef, id1=undef, id2=undef,
anchor, spin=0, orient=UP,
center, realign=false, l
) {
h = first_defined([h,l,1]);
r1 = first_defined([or1, od1/2, r1, d1/2, or, od/2, r, d/2, ir1+wall, id1/2+wall, ir+wall, id/2+wall]);
r2 = first_defined([or2, od2/2, r2, d2/2, or, od/2, r, d/2, ir2+wall, id2/2+wall, ir+wall, id/2+wall]);
ir1 = first_defined([ir1, id1/2, ir, id/2, r1-wall, d1/2-wall, r-wall, d/2-wall]);
ir2 = first_defined([ir2, id2/2, ir, id/2, r2-wall, d2/2-wall, r-wall, d/2-wall]);
assert(ir1 <= r1, "Inner radius is larger than outer radius.");
assert(ir2 <= r2, "Inner radius is larger than outer radius.");
sides = segs(max(r1,r2));
anchor = get_anchor(anchor, center, BOT, BOT);
attachable(anchor,spin,orient, r1=r1, r2=r2, l=h) {
zrot(realign? 180/sides : 0) {
difference() {
cyl(h=h, r1=r1, r2=r2, $fn=sides) children();
cyl(h=h+0.05, r1=ir1, r2=ir2);
}
}
children();
}
}
// Module: rect_tube()
// Usage:
// rect_tube(size, wall, h, [center]);
// rect_tube(isize, wall, h, [center]);
// rect_tube(size, isize, h, [center]);
// rect_tube(size1, size2, wall, h, [center]);
// rect_tube(isize1, isize2, wall, h, [center]);
// rect_tube(size1, size2, isize1, isize2, h, [center]);
// Description:
// Creates a rectangular or prismoid tube with optional roundovers and/or chamfers.
// You can only round or chamfer the vertical(ish) edges. For those edges, you can
// specify rounding and/or chamferring per-edge, and for top and bottom, inside and
// outside separately.
// Note: if using chamfers or rounding, you **must** also include the hull.scad file:
// ```
// include <BOSL2/hull.scad>
// ```
// Arguments:
// size = The outer [X,Y] size of the rectangular tube.
// isize = The inner [X,Y] size of the rectangular tube.
// h|l = The height or length of the rectangular tube. Default: 1
// wall = The thickness of the rectangular tube wall.
// size1 = The [X,Y] side of the outside of the bottom of the rectangular tube.
// size2 = The [X,Y] side of the outside of the top of the rectangular tube.
// isize1 = The [X,Y] side of the inside of the bottom of the rectangular tube.
// isize2 = The [X,Y] side of the inside of the top of the rectangular tube.
// rounding = The roundover radius for the outside edges of the rectangular tube.
// rounding1 = The roundover radius for the outside bottom corner of the rectangular tube.
// rounding2 = The roundover radius for the outside top corner of the rectangular tube.
// chamfer = The chamfer size for the outside edges of the rectangular tube.
// chamfer1 = The chamfer size for the outside bottom corner of the rectangular tube.
// chamfer2 = The chamfer size for the outside top corner of the rectangular tube.
// irounding = The roundover radius for the inside edges of the rectangular tube. Default: Same as `rounding`
// irounding1 = The roundover radius for the inside bottom corner of the rectangular tube.
// irounding2 = The roundover radius for the inside top corner of the rectangular tube.
// ichamfer = The chamfer size for the inside edges of the rectangular tube. Default: Same as `chamfer`
// ichamfer1 = The chamfer size for the inside bottom corner of the rectangular tube.
// ichamfer2 = The chamfer size for the inside top corner of the rectangular tube.
// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `BOTTOM`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0`
// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP`
// Examples:
// rect_tube(size=50, wall=5, h=30);
// rect_tube(size=[100,60], wall=5, h=30);
// rect_tube(isize=[60,80], wall=5, h=30);
// rect_tube(size=[100,60], isize=[90,50], h=30);
// rect_tube(size1=[100,60], size2=[70,40], wall=5, h=30);
// rect_tube(size1=[100,60], size2=[70,40], isize1=[40,20], isize2=[65,35], h=15);
// Example: Outer Rounding Only
// include <BOSL2/hull.scad>
// rect_tube(size=100, wall=5, rounding=10, irounding=0, h=30);
// Example: Outer Chamfer Only
// include <BOSL2/hull.scad>
// rect_tube(size=100, wall=5, chamfer=5, ichamfer=0, h=30);
// Example: Outer Rounding, Inner Chamfer
// include <BOSL2/hull.scad>
// rect_tube(size=100, wall=5, rounding=10, ichamfer=8, h=30);
// Example: Inner Rounding, Outer Chamfer
// include <BOSL2/hull.scad>
// rect_tube(size=100, wall=5, chamfer=10, irounding=8, h=30);
// Example: Gradiant Rounding
// include <BOSL2/hull.scad>
// rect_tube(size1=100, size2=80, wall=5, rounding1=10, rounding2=0, irounding1=8, irounding2=0, h=30);
// Example: Per Corner Rounding
// include <BOSL2/hull.scad>
// rect_tube(size=100, wall=10, rounding=[0,5,10,15], irounding=0, h=30);
// Example: Per Corner Chamfer
// include <BOSL2/hull.scad>
// rect_tube(size=100, wall=10, chamfer=[0,5,10,15], ichamfer=0, h=30);
// Example: Mixing Chamfer and Rounding
// include <BOSL2/hull.scad>
// rect_tube(size=100, wall=10, chamfer=[0,5,0,10], ichamfer=0, rounding=[5,0,10,0], irounding=0, h=30);
// Example: Really Mixing It Up
// include <BOSL2/hull.scad>
// rect_tube(
// size1=[100,80], size2=[80,60],
// isize1=[50,30], isize2=[70,50], h=20,
// chamfer1=[0,5,0,10], ichamfer1=[0,3,0,8],
// chamfer2=[5,0,10,0], ichamfer2=[3,0,8,0],
// rounding1=[5,0,10,0], irounding1=[3,0,8,0],
// rounding2=[0,5,0,10], irounding2=[0,3,0,8]
// );
module rect_tube(
size, isize,
h, shift=[0,0], wall,
size1, size2,
isize1, isize2,
rounding=0, rounding1, rounding2,
irounding=0, irounding1, irounding2,
chamfer=0, chamfer1, chamfer2,
ichamfer=0, ichamfer1, ichamfer2,
anchor, spin=0, orient=UP,
center, l
) {
h = first_defined([h,l,1]);
assert(is_num(h), "l or h argument required.");
assert(is_vector(shift,2));
s1 = is_num(size1)? [size1, size1] :