-
Notifications
You must be signed in to change notification settings - Fork 185
Expand file tree
/
Copy pathshapes3d.scad
More file actions
5305 lines (5064 loc) · 283 KB
/
shapes3d.scad
File metadata and controls
5305 lines (5064 loc) · 283 KB
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: shapes3d.scad
// Some standard modules for making 3d shapes with attachment support, and function forms
// that produce a VNF. Also included are shortcuts cylinders in each orientation and extended versions of
// the standard modules that provide roundovers and chamfers. The spheroid() module provides
// several different ways to make a sphere, and the text modules let you write text on a path
// so you can place it on a curved object. A ruler lets you measure objects.
// Includes:
// include <BOSL2/std.scad>
// FileGroup: Basic Modeling
// FileSummary: Attachable cubes, cylinders, spheres, ruler, and text. Many can produce a VNF.
// FileFootnotes: STD=Included in std.scad
//////////////////////////////////////////////////////////////////////
_BOSL2_SHAPES3D = is_undef(_BOSL2_STD) && (is_undef(BOSL2_NO_STD_WARNING) || !BOSL2_NO_STD_WARNING) ?
echo("Warning: shapes3d.scad included without std.scad; dependencies may be missing\nSet BOSL2_NO_STD_WARNING = true to mute this warning.") true : true;
use <builtins.scad>
// Section: Cuboids, Prismoids and Pyramids
// Function&Module: cube()
// Synopsis: Creates a cube with anchors for attaching children.
// SynTags: Geom, VNF, Ext
// Topics: Shapes (3D), Attachable, VNF Generators, Textures
// See Also: cuboid(), prismoid()
// Usage: As Module (as in native OpenSCAD)
// cube(size, [center]);
// Usage: With BOSL2 Attachment extensions
// cube(size, [center|anchor=], [spin=], [orient=]) [ATTACHMENTS];
// Usage: As Function (BOSL2 extension)
// vnf = cube(size, ...);
// Description:
// Creates a 3D cubic object.
// This module extends the built-in cube()` module by providing support for attachments and a function form.
// When called as a function, returns a [VNF](vnf.scad) for a cube.
// Arguments:
// size = The size of the cube. Default: 1
// center = A true value sets `anchor=CENTER`, false sets `anchor=FRONT+LEFT+BOTTOM`. Default: `anchor=CENTER`
// ---
// 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 after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top toward, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
// Example: Simple cube.
// cube(40);
// Example: Rectangular cube.
// cube([20,40,50]);
// Example: Anchoring.
// cube([20,40,50], anchor=BOTTOM+FRONT);
// Example: Spin.
// cube([20,40,50], anchor=BOTTOM+FRONT, spin=30);
// Example: Orientation.
// cube([20,40,50], anchor=BOTTOM+FRONT, spin=30, orient=FWD);
// Example: Standard Connectors.
// cube(40, center=true) show_anchors();
// Example: Called as Function
// vnf = cube([20,40,50]);
// vnf_polyhedron(vnf);
module cube(size=1, center, anchor, spin=0, orient=UP)
{
dummy = assert(num_defined([center,anchor])<2, "\nCannot give both center and anchor");
anchor = get_anchor(anchor, center, -[1,1,1], -[1,1,1]);
size = force_list(size,3); // Native cube prints a warning and gives a unit cube when parameters are bogus
attachable(anchor,spin,orient, size=is_vector(size,3)?size:[1,1,1]) {
_cube(size, center=true);
children();
}
}
function cube(size=1, center, anchor, spin=0, orient=UP) =
let(
size = force_list(size,3)
)
assert(is_undef(center) || is_bool(center), "\ncenter must be boolean.")
assert(num_defined([center,anchor])<2, "\nCannot give both center and anchor")
assert(is_vector(size,3), "\nSize parameter cannot be converted to a 3-vector.")
assert(all_positive(size), "\nAll size components must be positive.")
let(
anchor = get_anchor(anchor, center, -[1,1,1], -[1,1,1]),
unscaled = [
[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],
[-1,-1, 1],[1,-1, 1],[1,1, 1],[-1,1, 1],
]/2,
verts = [for (p=unscaled) v_mul(p,size)],
faces = [
[0,1,2], [0,2,3], //BOTTOM
[0,4,5], [0,5,1], //FRONT
[1,5,6], [1,6,2], //RIGHT
[2,6,7], [2,7,3], //BACK
[3,7,4], [3,4,0], //LEFT
[6,4,7], [6,5,4] //TOP
]
) [reorient(anchor,spin,orient, size=size, p=verts), faces];
// Module: cuboid()
// Synopsis: Creates a cube with chamfering and roundovers.
// SynTags: Geom
// Topics: Shapes (3D), Attachable
// See Also: prismoid(), rounded_prism()
// Usage: Standard Cubes
// cuboid(size, [anchor=], [spin=], [orient=]);
// cuboid(size, p1=, ...);
// cuboid(p1=, p2=, ...);
// Usage: Chamfered Cubes
// cuboid(size, [chamfer=], [edges=], [except=], [trimcorners=], ...);
// Usage: Rounded Cubes
// cuboid(size, [rounding=], [teardrop=], [edges=], [except=], [trimcorners=], ...);
// Usage: Attaching children
// cuboid(...) ATTACHMENTS;
//
// Description:
// Creates a cube or cuboid object, with optional chamfering or rounding of edges and corners.
// You cannot mix chamfering and rounding: just one edge treatment with the same size applies to all selected edges.
// Negative chamfers and roundings can be applied to create external fillets, but they
// apply only to edges around the top or bottom faces. If you specify an edge set other than "ALL"
// with negative roundings or chamfers then you will get an error. See [Specifying Edges](attachments.scad#section-specifying-edges)
// for information on how to specify edge sets.
// Arguments:
// size = The size of the cube, a number or length 3 vector.
// ---
// chamfer = Size of chamfer, inset from sides. Default: No chamfering.
// rounding = Radius of the edge rounding. Default: No rounding.
// edges = Edges to mask. See [Specifying Edges](attachments.scad#section-specifying-edges). Default: all edges.
// except = Edges to explicitly NOT mask. See [Specifying Edges](attachments.scad#section-specifying-edges). Default: No edges.
// trimcorners = If true, rounds or chamfers corners where three chamfered/rounded edges meet. Default: `true`
// teardrop = If given as a number, rounding around the bottom edge of the cuboid won't exceed this many degrees from vertical, altering to a chamfer at that angle. If true, the limit angle is 45 degrees. Default: `false`
// clip_angle = If given as a number, rounding around the bottom edge of the cuboid won't exceed this many degrees from vertical, with the rounding stopping at the bottom of the cuboid. Default: (no clipping)
// p1 = Align the cuboid's corner at `p1`, if given. Forces `anchor=FRONT+LEFT+BOTTOM`.
// 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#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 toward. See [orient](attachments.scad#subsection-orient). Default: `UP`
// Example: Simple regular cube.
// cuboid(40);
// Example: Cuboid with a corner at the origin
// cuboid(40, anchor=FRONT+LEFT+BOT);
// Example: Cuboid anchored on its right face
// cuboid(40, anchor=RIGHT);
// 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(VPR=[100,0,25],VPD=180): Rounded Edges and Corners with Teardrop Bottoms
// cuboid([30,40,50], rounding=10, teardrop=true);
// Example(VPR=[100,0,25],VPD=180): Rounded Edges and Corners with Clipped Bottoms
// cuboid([30,40,50], rounding=10, clip_angle=40);
// 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=RIGHT,
// $fn=24
// );
// Example: Negative Chamferring, Untrimmed Corners
// cuboid(
// [30,40,50], chamfer=-5,
// edges=[TOP,BOT], except=RIGHT,
// trimcorners=false, $fn=24
// );
// Example: Negative Rounding
// cuboid(
// [30,40,50], rounding=-5,
// edges=[TOP,BOT], except=RIGHT,
// $fn=24
// );
// Example: Negative Rounding, Untrimmed Corners
// cuboid(
// [30,40,50], rounding=-5,
// edges=[TOP,BOT], except=RIGHT,
// trimcorners=false, $fn=24
// );
// Example: Roundings and Chamfers can be as large as the full size of the cuboid, so long as the edges would not interfere.
// cuboid([40,20,10], rounding=20, edges=[FWD+RIGHT,BACK+LEFT]);
// Example: Standard anchors
// cuboid(40) show_anchors();
module cuboid(
size,
p1, p2,
chamfer,
rounding,
edges=EDGES_ALL,
except=[],
except_edges,
trimcorners=true,
teardrop=false,
clip_angle,
anchor=CENTER,
spin=0,
orient=UP
) {
module trunc_cube(s,corner) {
multmatrix(
(corner.x<0? xflip() : ident(4)) *
(corner.y<0? yflip() : ident(4)) *
(corner.z<0? zflip() : ident(4)) *
scale(s+[1,1,1]*0.001) *
move(-[1,1,1]/2)
) polyhedron(
[[1,1,1],[1,1,0],[1,0,0],[0,1,1],[0,1,0],[1,0,1],[0,0,1]],
[[0,1,2],[2,5,0],[0,5,6],[0,6,3],[0,3,4],[0,4,1],[1,4,2],[3,6,4],[5,2,6],[2,4,6]]
);
}
module xtcyl(l,r) {
if (teardrop) {
teardrop(r=r, l=l, cap_h=r, ang=teardrop, spin=90, orient=DOWN);
} else if (is_finite(clip_angle)) {
cap_h = r * sin(clip_angle);
hull() {
teardrop(r=r, l=l, cap_h=cap_h, ang=clip_angle, spin=90, orient=DOWN);
down(r-cap_h) teardrop(r=r, l=l, cap_h=cap_h, ang=clip_angle, spin=90, orient=DOWN);
}
} else {
yrot(90) cyl(l=l, r=r);
}
}
module ytcyl(l,r) {
if (teardrop) {
teardrop(r=r, l=l, cap_h=r, ang=teardrop, spin=0, orient=DOWN);
} else if (is_finite(clip_angle)) {
cap_h = r * sin(clip_angle);
hull() {
teardrop(r=r, l=l, cap_h=cap_h, ang=clip_angle, spin=0, orient=DOWN);
down(r-cap_h) teardrop(r=r, l=l, cap_h=cap_h, ang=clip_angle, spin=0, orient=DOWN);
}
} else {
zrot(90) yrot(90) cyl(l=l, r=r);
}
}
module tsphere(r) {
if (teardrop) {
onion(r=r, cap_h=r, ang=teardrop, orient=DOWN);
} else if (is_finite(clip_angle)) {
cap_h = r * sin(clip_angle);
hull() {
onion(r=r, cap_h=cap_h, ang=clip_angle, orient=DOWN);
down(r-cap_h) onion(r=r, cap_h=cap_h, ang=clip_angle, orient=DOWN);
}
} else {
spheroid(r=r, style="octa", orient=DOWN);
}
}
module corner_shape(corner) {
e = _corner_edges(edges, corner);
cnt = sum(e);
r = first_defined([chamfer, rounding]);
dummy = assert(is_finite(r) && !approx(r,0));
c = [r,r,r];
m = 0.01;
c2 = v_mul(corner,c/2);
c3 = v_mul(corner,c-[1,1,1]*m/2);
$fn = is_finite(chamfer)? 4 : quantup(segs(r),4);
translate(v_mul(corner, size/2-c)) {
if (cnt == 0 || approx(r,0)) {
translate(c3) cube(m, center=true);
} else if (cnt == 1) {
if (e.x) {
right(c3.x) {
intersection() {
xtcyl(l=m, r=r);
multmatrix(
(corner.y<0? yflip() : ident(4)) *
(corner.z<0? zflip() : ident(4))
) {
yrot(-90) linear_extrude(height=m+0.1, center=true) {
polygon([[r,0],[0.999*r,0],[0,0.999*r],[0,r],[r,r]]);
}
}
}
}
} else if (e.y) {
back(c3.y) {
intersection() {
ytcyl(l=m, r=r);
multmatrix(
(corner.x<0? xflip() : ident(4)) *
(corner.z<0? zflip() : ident(4))
) {
xrot(90) linear_extrude(height=m+0.1, center=true) {
polygon([[r,0],[0.999*r,0],[0,0.999*r],[0,r],[r,r]]);
}
}
}
}
} else if (e.z) {
up(c3.z) {
intersection() {
zcyl(l=m, r=r);
multmatrix(
(corner.x<0? xflip() : ident(4)) *
(corner.y<0? yflip() : ident(4))
) {
linear_extrude(height=m+0.1, center=true) {
polygon([[r,0],[0.999*r,0],[0,0.999*r],[0,r],[r,r]]);
}
}
}
}
}
} else if (cnt == 2) {
intersection() {
if (!e.x) {
intersection() {
ytcyl(l=c.y*2, r=r);
zcyl(l=c.z*2, r=r);
}
} else if (!e.y) {
intersection() {
xtcyl(l=c.x*2, r=r);
zcyl(l=c.z*2, r=r);
}
} else {
intersection() {
xtcyl(l=c.x*2, r=r);
ytcyl(l=c.y*2, r=r);
}
}
translate(c2) trunc_cube(c,corner); // Trim to just the octant.
}
} else {
intersection() {
if (trimcorners) {
tsphere(r=r);
} else {
intersection() {
xtcyl(l=c.x*2, r=r);
ytcyl(l=c.y*2, r=r);
zcyl(l=c.z*2, r=r);
}
}
translate(c2) trunc_cube(c,corner); // Trim to just the octant.
}
}
}
}
sizecheck = assert(num_defined([size,p1,p2])!=3, "\nCannot give size if p2 is given (did you forget brackets on the size argument?)")
assert(is_def(p1) || is_undef(p2), "\nIf p2 is given you must also give p1.");
size = force_list(default(size,1),3);
edges = _edges(edges, except=first_defined([except_edges,except]));
teardrop = is_bool(teardrop)&&teardrop? 45 : teardrop;
chamfer = approx(chamfer,0) ? undef : chamfer;
rounding = approx(rounding,0) ? undef : rounding;
checks =
assert(is_vector(size,3),"\n'size' must be a scalar or 3-vector.")
assert(all_nonnegative(size), "\nAll components of size= must be >=0.")
assert(is_undef(chamfer) || is_finite(chamfer),"\n'chamfer' must be a finite value.")
assert(is_undef(rounding) || is_finite(rounding),"\n'rounding' must be a finite value.")
assert(is_undef(rounding) || is_undef(chamfer), "\nCannot specify nonzero value for both chamfer and rounding.")
assert(teardrop==false || (is_finite(teardrop) && teardrop>0 && teardrop<=90), "\n'teardrop' must be either false or an angle number between 0 and 90.")
assert(clip_angle==undef || (is_finite(clip_angle) && clip_angle>0 && clip_angle<=90), "\nclip_angle must be either false or an angle number between 0 and 90.")
assert(!teardrop || clip_angle==undef, "\nteardrop= and clip_angle= are mutually exclusive features.")
assert(is_undef(p1) || is_vector(p1,3), "\np1 must be a 3-vector.")
assert(is_undef(p2) || is_vector(p2,3), "\np2 must be a 3-vector.")
assert(is_bool(trimcorners));
if (!is_undef(p1)) {
if (!is_undef(p2)) {
translate(pointlist_bounds([p1,p2])[0]) {
cuboid(size=v_abs(p2-p1), chamfer=chamfer, rounding=rounding, edges=edges, trimcorners=trimcorners, anchor=-[1,1,1]) children();
}
} else {
translate(p1) {
cuboid(size=size, chamfer=chamfer, rounding=rounding, edges=edges, trimcorners=trimcorners, anchor=-[1,1,1]) children();
}
}
} else {
rr = max(default(chamfer,0), default(rounding,0));
if (rr>0) {
minx = max(
edges.y[0] + edges.y[1], edges.y[2] + edges.y[3],
edges.z[0] + edges.z[1], edges.z[2] + edges.z[3],
edges.y[0] + edges.z[1], edges.y[0] + edges.z[3],
edges.y[1] + edges.z[0], edges.y[1] + edges.z[2],
edges.y[2] + edges.z[1], edges.y[2] + edges.z[3],
edges.y[3] + edges.z[0], edges.y[3] + edges.z[2]
) * rr;
miny = max(
edges.x[0] + edges.x[1], edges.x[2] + edges.x[3],
edges.z[0] + edges.z[2], edges.z[1] + edges.z[3],
edges.x[0] + edges.z[2], edges.x[0] + edges.z[3],
edges.x[1] + edges.z[0], edges.x[1] + edges.z[1],
edges.x[2] + edges.z[2], edges.x[2] + edges.z[3],
edges.x[3] + edges.z[0], edges.x[3] + edges.z[1]
) * rr;
minz = max(
edges.x[0] + edges.x[2], edges.x[1] + edges.x[3],
edges.y[0] + edges.y[2], edges.y[1] + edges.y[3],
edges.x[0] + edges.y[2], edges.x[0] + edges.y[3],
edges.x[1] + edges.y[2], edges.x[1] + edges.y[3],
edges.x[2] + edges.y[0], edges.x[2] + edges.y[1],
edges.x[3] + edges.y[0], edges.x[3] + edges.y[1]
) * rr;
check =
assert(minx <= size.x, "\nRounding or chamfering too large for cuboid size in the X axis.")
assert(miny <= size.y, "\nRounding or chamfering too large for cuboid size in the Y axis.")
assert(minz <= size.z, "\nRounding or chamfering too large for cuboid size in the Z axis.")
;
}
majrots = [[0,90,0], [90,0,0], [0,0,0]];
attachable(anchor,spin,orient, size=size) {
if (is_finite(chamfer) && !approx(chamfer,0)) {
if (edges == EDGES_ALL && trimcorners) {
if (chamfer<0) {
cube(size, center=true) {
attach(TOP,overlap=0) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP);
attach(BOT,overlap=0) 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) {
checks = assert(edges == EDGES_ALL || edges[2] == [0,0,0,0], "\nCannot use negative chamfer with Z aligned edges.");
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(v_mul(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]) {
ce = _corner_edges(edges, [xa,ya,za]);
if (ce.x + ce.y > 1) {
translate(v_mul([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(v_mul(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 {
hull() {
corner_shape([-1,-1,-1]);
corner_shape([ 1,-1,-1]);
corner_shape([-1, 1,-1]);
corner_shape([ 1, 1,-1]);
corner_shape([-1,-1, 1]);
corner_shape([ 1,-1, 1]);
corner_shape([-1, 1, 1]);
corner_shape([ 1, 1, 1]);
}
}
} else if (is_finite(rounding) && !approx(rounding,0)) {
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) {
tsphere(r=rounding, $fn=sides);
} else {
intersection() {
xtcyl(r=rounding, l=rounding*2, $fn=sides);
ytcyl(r=rounding, l=rounding*2, $fn=sides);
cyl(r=rounding, h=rounding*2, $fn=sides);
}
}
}
}
} else if (rounding<0) {
checks = assert(edges == EDGES_ALL || edges[2] == [0,0,0,0], "\nCannot use negative rounding with Z aligned edges.");
ard = abs(rounding);
cube(size, center=true);
$fn = quantup(segs(rounding),4);
// External-Rounding mask edges
difference() {
union() {
for (i = [0:3], axis=[0:1]) {
if (edges[axis][i]>0) {
vec = EDGE_OFFSETS[axis][i];
translate(v_mul(vec/2, size+[ard,ard,-ard]-[0.01,0.01,0])) {
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]) {
ce = _corner_edges(edges, [xa,ya,za]);
if (ce.x + ce.y > 1) {
translate(v_mul([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(v_mul(vec/2, size+[2*ard,2*ard,-2*ard])) {
rotate(majrots[axis]) {
cyl(l=size[axis]+2.1*ard, r=ard);
}
}
}
}
}
} else {
hull() {
corner_shape([-1,-1,-1]);
corner_shape([ 1,-1,-1]);
corner_shape([-1, 1,-1]);
corner_shape([ 1, 1,-1]);
corner_shape([-1,-1, 1]);
corner_shape([ 1,-1, 1]);
corner_shape([-1, 1, 1]);
corner_shape([ 1, 1, 1]);
}
}
} else {
cube(size=size, center=true);
}
children();
}
}
}
function cuboid(
size=[1,1,1],
p1, p2,
chamfer,
rounding,
edges=EDGES_ALL,
except_edges=[],
trimcorners=true,
anchor=CENTER,
spin=0,
orient=UP
) = no_function("cuboid");
// Function&Module: prismoid()
// Synopsis: Creates a rectangular prismoid shape with optional roundovers and chamfering.
// SynTags: Geom, VNF
// Topics: Shapes (3D), Attachable, VNF Generators
// See Also: cuboid(), rounded_prism(), trapezoid(), edge_profile()
// Usage:
// prismoid(size1, size2, [h|l|height|length], [shift], [xang=], [yang=], ...) [ATTACHMENTS];
// Usage: Chamfered and/or Rounded Prismoids
// prismoid(size1, size2, h|l|height|length, [chamfer=], [rounding=]...) [ATTACHMENTS];
// prismoid(size1, size2, h|l|height|length, [chamfer1=], [chamfer2=], [rounding1=], [rounding2=], ...) [ATTACHMENTS];
// Usage: As Function
// vnf = prismoid(...);
// 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.
// If you want to round the bottom or top edges see {{rounded_prism()}} or {{edge_profile()}}
// .
// Specification of the prismoid is similar to specification for {{trapezoid()}}. You can specify the dimensions of the
// bottom and top and its height to get a symmetric prismoid. You can use the shift argument to shift the top face around.
// You can also specify base angles either in the X direction, Y direction or both. In order to avoid overspecification,
// you may need to specify a parameter such as size2 as a list of two values, one of which is undef. For example,
// specifying `size2=[100,undef]` sets the size in the X direction but allows the size in the Y direction to be computed based on yang.
// .
// The anchors on the top and bottom faces have spin pointing back. The anchors on the side faces have spin point UP.
// The anchors on the top and bottom edges also have anchors that point clockwise as viewed from outside the shapep.
// The anchors on the side edges and the corners have spin with positive Z component, pointing along the edge where the anchor is located.
// A degenerate prismoid with a line segment for the top or bottom has its top or bottom edge anchors set to provide an anchor for that top
// or bottom edge. So for example, if the top is `[0,10]` then the top edge is parallel to the Y axis and you can anchor to that
// edge using the `TOP+RIGHT` or `TOP+LEFT` anchors; these anchors point in the direction that divides the edge in half and provide
// the `$edge_angle` and `$edge_length` values generally provided by edge anchors. The UP or DOWN anchor is in the same location but always points
// in the Z direction and provides no edge data.
// Arguments:
// size1 = [width, length] of the bottom end of the prism.
// size2 = [width, length] of the top end of the prism.
// h/l/height/length = Height of the prism.
// shift = [X,Y] amount to shift the center of the top end with respect to the center of the bottom end.
// ---
// xang = base angle in the X direction. Can be a scalar or list of two values, one of which may be undef
// yang = base angle in the Y direction. Can be a scalar or list of two values, one of which may be undef
// rounding = The roundover radius for the vertical-ish edges of the prismoid. 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 of the vertical-ish edges of the prismoid. 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 of the vertical-ish edges of the prismoid. 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 vertical-ish edges of the prismoid. 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 of the vertical-ish edges of the prismoid. 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 of the vertical-ish edges of the prismoid. 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#subsection-anchor). Default: `BOTTOM`
// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top toward, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
//
// Example: Truncated Pyramid
// prismoid(size1=[35,50], size2=[20,30], h=20);
// Example: Rectangular Pyramid
// prismoid([40,40], [0,0], h=20);
// Example: Prism
// prismoid(size1=[40,40], size2=[0,40], 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,VPD=160,VPT=[0,0,10]): Shifting/Skewing
// prismoid(size1=[50,30], size2=[20,20], h=20, shift=[15,5]);
// Example: Specifying bottom, height and angle
// prismoid(size1=[100,75], h=30, xang=50, yang=70);
// Example: Specifying top, height and angle, with asymmetric angles
// prismoid(size2=[100,75], h=30, xang=[50,60], yang=[70,40]);
// Example: Specifying top, bottom and angle for X and using that to define height. Giving yang here would likely give a conflicting height calculation, which is not allowed.
// prismoid(size1=[100,75], size2=[75,35], xang=50);
// Example: The same as the previous example but we give a shift in Y. Note that shift.x must be undef because you cannot give combine an angle with a shift, so a shift.x value would conflict with xang being defined.
// prismoid(size1=[100,75], size2=[75,35], xang=50, shift=[undef,20]);
// Example: The X dimensions defined by the base length, angle and height; the Y dimensions defined by the top length, angle, and height.
// prismoid(size1=[100,undef], size2=[undef,75], h=30, xang=[20,90], yang=30);
// Example: Rounding
// prismoid(100, 80, rounding=10, h=30);
// Example: Chamfers
// prismoid(100, 80, chamfer=5, h=30);
// Example: Gradiant Rounding
// prismoid(100, 80, rounding1=10, rounding2=0, h=30);
// Example: Per Corner Rounding
// prismoid(100, 80, rounding=[0,5,10,15], h=30);
// Example: Per Corner Chamfer
// prismoid(100, 80, chamfer=[0,5,10,15], h=30);
// Example: Mixing Chamfer and Rounding
// prismoid(
// 100, 80, h=30,
// chamfer=[0,5,0,10],
// rounding=[5,0,10,0]
// );
// Example: Really Mixing It Up
// 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: How to Round a Top or Bottom Edge
// diff()
// prismoid([50,30], [30,20], shift=[3,6], h=15, rounding=[5,0,5,0]) {
// edge_profile([TOP+RIGHT, BOT+FRONT], excess=10, convexity=20) {
// mask2d_roundover(h=5,mask_angle=$edge_angle);
// }
// }
// Example(Spin,VPD=160,VPT=[0,0,10]): Standard anchors
// prismoid(size1=[50,30], size2=[20,20], h=20, shift=[15,5])
// show_anchors();
// Example(3D): When the top or bottom is degenerate, you can anchor to and round the degenerate edge by using either one of the edge anchors that correspond to that edge. But note that {{edge_profile()}} does not work for this degenerate case. We used `TOP+RIGHT` below as the anchor point, but `TOP+LEFT` produces an identical result.
// diff()
// prismoid([10,14],[0,8], shift=[4,3], h=7)
// attach(TOP+RIGHT, FWD+LEFT, inside=true)
// rounding_edge_mask(r=2,l=$edge_length+6);
module prismoid(
size1=undef, size2=undef, h, shift=[undef,undef],
xang, yang,
rounding=0, rounding1, rounding2,
chamfer=0, chamfer1, chamfer2,
l, height, length, center,
anchor, spin=0, orient=UP
)
{
vnf_s1_s2_shift = prismoid(
size1=size1, size2=size2, h=h, shift=shift,
xang=xang, yang=yang,
rounding=rounding, chamfer=chamfer,
rounding1=rounding1, rounding2=rounding2,
chamfer1=chamfer1, chamfer2=chamfer2,
l=l, height=height, length=length, anchor=BOT, _return_dim=true
);
anchor = get_anchor(anchor, center, BOT, BOT);
attachable(anchor,spin,orient, size=vnf_s1_s2_shift[1], size2=vnf_s1_s2_shift[2], shift=vnf_s1_s2_shift[3]) {
down(vnf_s1_s2_shift[1].z/2)
vnf_polyhedron(vnf_s1_s2_shift[0], convexity=4);
children();
}
}
function prismoid(
size1, size2, h, shift=[0,0],
rounding=0, rounding1, rounding2,
chamfer=0, chamfer1, chamfer2,
l, height, length, center,
anchor=DOWN, spin=0, orient=UP, xang, yang,
_return_dim=false
) =
assert(is_undef(shift) || is_num(shift) || len(shift)==2, "\nshift must be a number or list of length 2.")
assert(is_undef(size1) || is_num(size1) || len(size1)==2, "\nsize1 must be a number or list of length 2.")
assert(is_undef(size2) || is_num(size2) || len(size2)==2, "\nsize2 must be a number or list of length 2.")
let(
xang = force_list(xang,2),
yang = force_list(yang,2),
yangOK = len(yang)==2 && (yang==[undef,undef] || (all_positive(yang) && yang[0]<180 && yang[1]<180)),
xangOK = len(xang)==2 && (xang==[undef,undef] || (all_positive(xang) && xang[0]<180 && xang[1]<180)),
size1=force_list(size1,2),
size2=force_list(size2,2),
h=first_defined([l,h,length,height]),
shift = force_list(shift,2)
)
assert(xangOK, "\nPrismoid angles must be scalar or 2-vector, strictly between 0 and 180.")
assert(yangOK, "\nPrismoid angles must be scalar or 2-vector, strictly between 0 and 180.")
assert(xang==[undef,undef] || shift.x==undef, "\nCannot specify xang and a shift.x value together.")
assert(yang==[undef,undef] || shift.y==undef, "\nCannot specify yang and a shift.y value together.")
assert(all_positive([h]) || is_undef(h), "\nh must be a positive value.")
let(
hx = _trapezoid_dims(h,size1.x,size2.x,shift.x,xang)[0],
hy = _trapezoid_dims(h,size1.y,size2.y,shift.y,yang)[0]
)
assert(num_defined([hx,hy])>0, "\nHeight not given and specification does not determine prismoid height.")
assert(hx==undef || hy==undef || approx(hx,hy),
str("\nX and Y angle specifications cause conflicting height values ",hx," and ",hy,"."))
let(
h = first_defined([hx,hy]),
x_h_w1_w2_shift = _trapezoid_dims(h,size1.x,size2.x,shift.x,xang),
y_h_w1_w2_shift = _trapezoid_dims(h,size1.y,size2.y,shift.y,yang)
)
let(
s1 = [x_h_w1_w2_shift[1], y_h_w1_w2_shift[1]],
s2 = [x_h_w1_w2_shift[2], y_h_w1_w2_shift[2]],
shift = [x_h_w1_w2_shift[3], y_h_w1_w2_shift[3]]
)
assert(is_vector(s1,2), "\nInsufficient information to define prismoid.")
assert(is_vector(s2,2), "\nInsufficient information to define prismoid.")
assert(all_nonnegative(concat(s1,s2)),"\nDegenerate prismoid geometry.")
assert(s1.x+s2.x>0 && s1.y+s2.y>0, "\nDegenerate prismoid geometry.")
assert(is_num(rounding) || is_vector(rounding,4), "\nrounding must be a number or 4-vector.")
assert(is_undef(rounding1) || is_num(rounding1) || is_vector(rounding1,4), "\nrounding1 must be a number or 4-vector.")
assert(is_undef(rounding2) || is_num(rounding2) || is_vector(rounding2,4), "\nrounding2 must be a number or 4-vector.")
assert(is_num(chamfer) || is_vector(chamfer,4), "\nchamfer must be a number or 4-vector.")
assert(is_undef(chamfer1) || is_num(chamfer1) || is_vector(chamfer1,4), "\nchamfer1 must be a number or 4-vector.")
assert(is_undef(chamfer2) || is_num(chamfer2) || is_vector(chamfer2,4), "\nchamfer2 must be a number or 4-vector.")
let(
chamfer1=force_list(default(chamfer1,chamfer),4),
chamfer2=force_list(default(chamfer2,chamfer),4),
rounding1=force_list(default(rounding1,rounding),4),
rounding2=force_list(default(rounding2,rounding),4)
)
assert(all_nonnegative(chamfer1), "\nchamfer/chamfer1 must be non-negative.")
assert(all_nonnegative(chamfer2), "\nchamfer/chamfer2 must be non-negative.")
assert(all_nonnegative(rounding1), "\nrounding/rounding1 must be non-negative.")
assert(all_nonnegative(rounding2), "\nrounding/rounding2 must be non-negative.")
assert(all_zero(v_mul(rounding1,chamfer1),0),
"\nrounding1 and chamfer1 (possibly inherited from rounding and chamfer) cannot both be nonzero at the same corner.")
assert(all_zero(v_mul(rounding2,chamfer2),0),
"\nrounding2 and chamfer2 (possibly inherited from rounding and chamfer) cannot both be nonzero at the same corner.")
let(
rounding1 = default(rounding1, rounding),
rounding2 = default(rounding2, rounding),
chamfer1 = default(chamfer1, chamfer),
chamfer2 = default(chamfer2, chamfer),
anchor = get_anchor(anchor, center, BOT, BOT),
path1 = rect(s1, rounding=rounding1, chamfer=chamfer1, anchor=CTR),
path2 = rect(s2, rounding=rounding2, chamfer=chamfer2, anchor=CTR),
points = [
each path3d(path1, -h/2),
each path3d(move(shift, path2), +h/2),
],
faces = hull(points),
vnf = [points, faces]
)
_return_dim ? [reorient(anchor,spin,orient, size=[s1.x,s1.y,h], size2=s2, shift=shift, p=vnf),point3d(s1,h),s2,shift]
: reorient(anchor,spin,orient, size=[s1.x,s1.y,h], size2=s2, shift=shift, p=vnf);
// Function&Module: regular_prism()
// Synopsis: Creates a regular prism with roundovers and chamfering
// SynTags: Geom, VNF
// Topics: Textures, Rounding, Chamfers, Shapes (3D), Attachable
// See Also: cyl(), rounded_prism(), texture(), linear_sweep(), EDGE(), FACE()
// Usage: Normal prisms
// regular_prism(n, h|l=|height=|length=, r, [center=|anchor=], [realign=]) [ATTACHMENTS];
// regular_prism(n, h|l=|height=|length=, d=|id=|od=|ir=|or=|side=, ...) [ATTACHMENTS];
// regular_prism(n, h|l=|height=|length=, r1=|d1=|id1=|od1=|ir1=|or1=|side1=,r2=|d2=|id2=|od2=|ir2=|or2=|side2=, ...) [ATTACHMENTS];
// Usage: Chamferred end prisms
// regular_prism(n, h, r, chamfer=, [chamfang=], [from_end=], ...);
// regular_prism(n, h, r, chamfer1=, [chamfang1=], [from_end=], ...);
// regular_prism(n, h, r, chamfer2=, [chamfang2=], [from_end=], ...);
// regular_prism(n, h, r, chamfer1=, chamfer2=, [chamfang1=], [chamfang2=], [from_end=], ...);
// Usage: Rounded end prisms
// regular_prism(n, h, r, rounding=, ...);
// regular_prism(n, h, r, rounding1=, ...);
// regular_prism(n, h, r, rounding2=, ...);
// regular_prism(n, h, r, rounding1=, rounding2=, ...);
// Usage: Textured prisms
// regular_prism(n, h, r, texture=, [tex_size=]|[tex_reps=], [tex_depth=], [tex_rot=], [tex_samples=], [style=], [tex_inset=], ...);
// Usage: Called as a function to get a VNF
// vnf = rounded_prism(...);
// Description:
// Creates a prism whose ends are similar `n`-sided regular polygons, with optional rounding, chamfers or textures.
// You can specify the size of the ends using diameter or radius measured either inside or outside. Alternatively
// you can give the length of the side of the polygon. You can specify chamfers and roundings for the ends, but not
// the vertical edges. See {{rounded_prism()}} for prisms with rounded vertical edges. You can also specify texture for the side
// faces, but note that texture is not compatible with any roundings or chamfers.
// See [Texturing](skin.scad#section-texturing) for more details on how textures work.
// .
// Anchors are based on the VNF of the prism. Especially for tapered or shifted prisms, this may give unexpected anchor positions, such as top side anchors
// being located at the bottom of the shape, so confirm anchor positions before use.
// Additional named face and edge anchors are located on the side faces and edges of the prism.
// You can use `EDGE(i)`, `EDGE(TOP,i)` and `EDGE(BOT,i)` as a shorthand for accessing the named edge anchors, and `FACE(i)` for the face anchors.
// The "edge0" anchor identifies an edge located along the X+ axis, and then edges
// are labeled counting up in the clockwise direction. Similarly "face0" is the face immediately clockwise from "edge0", and face
// labeling proceeds clockwise. The top and bottom edge anchors label edges directly above and below the face with the same label.
// If you set `realign=true` then "face0" has its normal pointing in the X+ direction.
// .
// This module is similar to {{cyl()}}. It differs in the following ways: you can specify side length or inner radius/diameter, you can apply roundings with
// different `$fn` than the number of prism faces, you can apply texture to the flat faces without forcing a high facet count,
// anchors are located on the true object instead of the ideal cylinder and you can anchor to the edges and faces. Chamfers and roundings
// for this module are **always** evaluated relative to the faces of the prism and never at corners as is done by default in {{cyl()}}.
// .
// Fully specifying the shape requires a height and the radius at each end. You can replace one of those three parameters with
// an angle. If you give the height, angle, and one radius then the other radius is calculated so that the internal angle at the base of
// the prism is the specified angle. If you give the angle and the radius at each end then the height is calculated so that the internal
// angle at one of the ends is the angle you specified. Which end gets the specified angle depends on the relative sizes of the ends
// and whether the angle is smaller or larger than 90 degrees.
// Named Anchors:
// "edge0", "edge1", etc. = Center of each side edge, spin pointing up along the edge. Can access with EDGE(i)
// "face0", "face1", etc. = Center of each side face, spin pointing up. Can access with FACE(i)
// "top_edge0", "top_edge1", etc = Center of each top edge, spin pointing clockwise (from top). Can access with EDGE(TOP,i)
// "bot_edge0", "bot_edge1", etc = Center of each bottom edge, spin pointing clockwise (from bottom). Can access with EDGE(BOT,i)
// "top_corner0", "top_corner1", etc = Top corner, pointing in direction of associated edge anchor, spin up along associated edge
// "bot_corner0", "bot_corner1", etc = Bottom corner, pointing in direction of associated edge anchor, spin up along associated edge
// Arguments:
// l / h / length / height = Length of prism
// r = Outer radius of prism.
// center = A true value sets `anchor=CENTER`, false sets `anchor=DOWN`. Default is `anchor=CENTER`.
// ---
// r1/or1 = Outer radius of the bottom of prism
// r2/or2 = Outer radius of the top end of prism
// d = Outer Diameter of prism
// d1 / od1 = Outer diameter of bottom of prism
// d2 / od2 = Outer diameter of top end of prism
// ir = Inner radius of prism
// ir1 = Inner radius of bottom of prism
// ir2 = Inner radius of top of prism
// id = Inner diameter of prism
// id1 = Inner diameter of bottom of prism
// id2 = Inner diameter of top of prism
// side = Side length of prism faces
// side1 = Side length of prism faces at the bottom
// side2 = Side length of prism faces at the top
// ang = specify the prism angle instead of height or instead of the dimension at one of the two ends.
// shift = [X,Y] amount to shift the center of the top end with respect to the center of the bottom end.
// chamfer = The size of the chamfers on the ends of the prism. (Also see: `from_end=`) Default: none.
// chamfer1 = The size of the chamfer on the bottom end of the prism. (Also see: `from_end1=`) Default: none.
// chamfer2 = The size of the chamfer on the top end of the prism. (Also see: `from_end2=`) Default: none.
// chamfang = The angle in degrees of the chamfers away from the ends of the prismr. Default: Chamfer angle is halfway between the endcap and side face.
// chamfang1 = The angle in degrees of the bottom chamfer away from the bottom end of the prism. Default: Chamfer angle is halfway between the endcap and side face.
// chamfang2 = The angle in degrees of the top chamfer away from the top end of the prism. Default: Chamfer angle is halfway between the endcap and side face.
// from_end = If true, chamfer is measured along the side face from the ends of the prism, instead of inset from the edge. Default: `false`.
// from_end1 = If true, chamfer on the bottom end of the prism is measured along the side face from the end of the prism, instead of inset from the edge. Default: `false`.
// from_end2 = If true, chamfer on the top end of the prism is measured along the side face from the end of the prism, instead of inset from the edge. Default: `false`.
// rounding = The radius of the rounding on the ends of the prism. Default: none.
// rounding1 = The radius of the rounding on the bottom end of the prism.
// rounding2 = The radius of the rounding on the top end of the prism.
// realign = If true, rotate the prism by half the angle of one face so that face0's normal points in the X+ direction. Default: false
// teardrop = If given as a number, rounding around the bottom edge of the prism won't exceed this many degrees from vertical. If true, the limit angle is 45 degrees. Default: `false`
// clip_angle = If given as a number, rounding around the bottom edge of the prism won't exceed this many degrees from vertical, with the rounding stopping at the bottom of the prism. Default: (no clipping)
// texture = A texture name string, or a rectangular array of scalar height values (0.0 to 1.0), or a VNF tile that defines the texture to apply to vertical surfaces. See {{texture()}} for what named textures are supported.
// tex_size = An optional 2D target size (2-vector or scalar) for the textures. Actual texture sizes are scaled somewhat to fit evenly on the available surface. Default: `[5,5]`
// tex_reps = If given instead of tex_size, a scalar or 2-vector giving the number of texture tile repetitions in the horizontal and vertical directions.
// tex_inset = If numeric, lowers the texture into the surface by the specified proportion, e.g. 0.5 would lower it half way into the surface. If `true`, insets by exactly its full depth. Default: `false`
// tex_rot = Rotate texture by specified angle, which must be a multiple of 90 degrees. Default: 0
// tex_depth = Specify texture depth; if negative, invert the texture. Default: 1.
// tex_samples = Minimum number of "bend points" to have in VNF texture tiles. Default: 8
// style = {{vnf_vertex_array()}} style used to triangulate heightfield textures. Default: "min_edge"
// 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 after anchor. See [spin](attachments.scad#subsection-spin). Default: `0`
// orient = Vector to rotate top toward, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
// Example: Simple prism
// regular_prism(5,r=10,h=25);
// Example: With end rounding
// regular_prism(5,r=10,h=25,rounding=3,$fn=32);
// Example: With teardrop end rounding
// regular_prism(5,r=10,h=25,rounding=3,teardrop=40,$fn=32);
// Example: With clipped end rounding
// regular_prism(5,r=10,h=25,rounding=3,clip_angle=40,$fn=32);
// Example: By side length at bottom, inner radius at top, shallow chamfer
// regular_prism(7, side1=10, ir2=7, height=20,chamfer2=2,chamfang2=20);
// Example: By angle and base radius
// regular_prism(4, r1=10, height=7, ang=45);
// Example: By angle and top radius
// regular_prism(4, r2=10, height=7, ang=45);
// Example: By angle with height omitted; the specified 70 deg agle appears at the bottom in this case
// regular_prism(4, r1=10, r2=7, ang=70);
// Example: By angle with height omitted; we interchanged r1 and r2 and now the specified 70 deg angle is at the top
// regular_prism(4, r1=7, r2=10, ang=70);
// Example: With shift
// regular_prism(4, d=12, h=10, shift=[12,7]);
// Example: Attaching child to face
// regular_prism(5, d1=15, d2=10, h=20)
// recolor("lightblue")
// attach("face1",BOT) regular_prism(n=4,r1=3,r2=1,h=3);
// Example: Attaching child to edge
// regular_prism(5, d1=15, d2=10, h=20)
// recolor("lightblue")
// attach("edge2",RIGHT) cuboid([4,4,20]);
// Example: Placing child on top along an edge of a regular prism is possible with the top_edge anchors, but you cannot use {{align()}} or {{attach()}}, so you must manually anchor and spin the child by half of the polygon angle (180/n) to get to face0 and then 360/n more for each subsequent face. If you set `realign=true` then you don't need the initial angle for face0.
// regular_prism(5, d1=25, d2=20, h=15, realign=false) color("lightblue"){
// position("top_edge1") prismoid([5,5],[2,2],h=3,spin=-360/5*1.5,anchor=RIGHT+BOT);
// position("top_edge3") prismoid([5,5],[2,2],h=3,spin=-360/5*3.5,anchor=RIGHT+BOT);
// }
// Example: Textured prism
// regular_prism(5, side=25, h=50, texture="diamonds", tex_size=[5,5], style="concave");
module regular_prism(n,
h, r, center,
l, length, height,
r1,r2,ir,ir1,ir2,or,or1,or2,side,side1,side2,
d, d1, d2,id,id1,id2,od,od1,od2,ang,
chamfer, chamfer1, chamfer2,
chamfang, chamfang1, chamfang2,
rounding, rounding1, rounding2,
realign=false, shift=[0,0],
teardrop=false, clip_angle,
from_end, from_end1, from_end2,
texture, tex_size=[5,5], tex_reps,
tex_inset=false, tex_rot=0,
tex_depth, tex_samples,
tex_taper, style,
anchor, spin=0, orient=UP
)
{
vnf_anchors_ovr = regular_prism(n=n,h=h,r=r,center=center, l=l,length=length,height=height,
r1=r1,r2=r2,ir=ir,ir1=ir1,ir2=ir2,or=or,or1=or1,or2=or2,side=side,side1=side1,side2=side2,
d=d,d1=d1,d2=d2,id=id,id1=id1,id2=id2,od=od,od1=od1,od2=od2,ang=ang,
chamfer=chamfer, chamfer1=chamfer1, chamfer2=chamfer2,
chamfang=chamfang,chamfang1=chamfang1,chamfang2=chamfang2,
rounding=rounding,rounding1=rounding1, rounding2=rounding2,
realign=realign, shift=shift,
teardrop=teardrop, clip_angle=clip_angle,
from_end=from_end, from_end1=from_end1, from_end2=from_end2,