forked from BelfrySCAD/BOSL2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shapes3d.scad
4214 lines (4038 loc) · 215 KB
/
shapes3d.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: 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
//////////////////////////////////////////////////////////////////////
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
// 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.
// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=FRONT+LEFT+BOTTOM`.
// ---
// 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 towards, 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)
{
anchor = get_anchor(anchor, center, -[1,1,1], -[1,1,1]);
size = scalar_vec3(size);
attachable(anchor,spin,orient, size=size) {
_cube(size, center=true);
children();
}
}
function cube(size=1, center, anchor, spin=0, orient=UP) =
let(
siz = scalar_vec3(size)
)
assert(all_positive(siz), "All 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 = is_num(size)? unscaled * size :
is_vector(size,3)? [for (p=unscaled) v_mul(p,size)] :
assert(is_num(size) || is_vector(size,3)),
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=siz, p=verts), faces];
// Module: cuboid()
// Synopsis: Creates a cube with chamfering and roundovers.
// SynTags: Geom
// Topics: Shapes (3D), Attachable, VNF Generators
// 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
// only apply 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. If true, the limit angle is 45 degrees. Default: `false`
// 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 towards. 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: 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 Connectors
// cuboid(40) show_anchors();
module cuboid(
size=[1,1,1],
p1, p2,
chamfer,
rounding,
edges=EDGES_ALL,
except=[],
except_edges,
trimcorners=true,
teardrop=false,
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 {
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 {
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 {
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.
}
}
}
}
size = scalar_vec3(size);
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))
assert(all_nonnegative(size), "All components of size= must be >=0")
assert(is_undef(chamfer) || is_finite(chamfer),"chamfer must be a finite value")
assert(is_undef(rounding) || is_finite(rounding),"rounding must be a finite value")
assert(is_undef(rounding) || is_undef(chamfer), "Cannot specify nonzero value for both chamfer and rounding")
assert(teardrop==false || (is_finite(teardrop) && teardrop>0 && teardrop<=90), "teardrop must be either false or an angle number between 0 and 90")
assert(is_undef(p1) || is_vector(p1))
assert(is_undef(p2) || is_vector(p2))
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, "Rounding or chamfering too large for cuboid size in the X axis.")
assert(miny <= size.y, "Rounding or chamfering too large for cuboid size in the Y axis.")
assert(minz <= size.z, "Rounding 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], "Cannot 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], "Cannot use negative rounding with Z aligned edges.");
ard = abs(rounding);
cube(size, center=true);
// 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.
// 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 towards, 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. Note that 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 Connectors
// prismoid(size1=[50,30], size2=[20,20], h=20, shift=[15,5])
// show_anchors();
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, "shift must be a number or list of length 2")
assert(is_undef(size1) || is_num(size1) || len(size1)==2, "size1 must be a number or list of length 2")
assert(is_undef(size2) || is_num(size2) || len(size2)==2, "size2 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, "prismoid angles must be scalar or 2-vector, strictly between 0 and 180")
assert(yangOK, "prismoid angles must be scalar or 2-vector, strictly between 0 and 180")
assert(xang==[undef,undef] || shift.x==undef, "Cannot specify xang and a shift.x value together")
assert(yang==[undef,undef] || shift.y==undef, "Cannot specify yang and a shift.y value together")
assert(all_positive([h]) || is_undef(h), "h 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, "Height not given and specification does not determine prismoid height")
assert(hx==undef || hy==undef || approx(hx,hy),
str("X and Y angle specifications give rise to 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), "Insufficient information to define prismoid")
assert(is_vector(s2,2), "Insufficient information to define prismoid")
assert(all_nonnegative(concat(s1,s2)),"Degenerate prismoid geometry")
assert(s1.x+s2.x>0 && s1.y+s2.y>0, "Degenerate prismoid geometry")
assert(is_num(rounding) || is_vector(rounding,4), "rounding must be a number or 4-vector")
assert(is_undef(rounding1) || is_num(rounding1) || is_vector(rounding1,4), "rounding1 must be a number or 4-vector")
assert(is_undef(rounding2) || is_num(rounding2) || is_vector(rounding2,4), "rounding2 must be a number or 4-vector")
assert(is_num(chamfer) || is_vector(chamfer,4), "chamfer must be a number or 4-vector")
assert(is_undef(chamfer1) || is_num(chamfer1) || is_vector(chamfer1,4), "chamfer1 must be a number or 4-vector")
assert(is_undef(chamfer2) || is_num(chamfer2) || is_vector(chamfer2,4), "chamfer2 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), "chamfer/chamfer1 must be non-negative")
assert(all_nonnegative(chamfer2), "chamfer/chamfer2 must be non-negative")
assert(all_nonnegative(rounding1), "rounding/rounding1 must be non-negative")
assert(all_nonnegative(rounding2), "rounding/rounding2 must be non-negative")
assert(all_zero(v_mul(rounding1,chamfer1),0),
"rounding1 and chamfer1 (possibly inherited from rounding and chamfer) cannot both be nonzero at the same corner")
assert(all_zero(v_mul(rounding2,chamfer2),0),
"rounding2 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: octahedron()
// Synopsis: Creates an octahedron with axis-aligned points.
// SynTags: Geom, VNF
// Topics: Shapes (3D), Attachable, VNF Generators
// See Also: prismoid()
// Usage: As Module
// octahedron(size, ...) [ATTACHMENTS];
// Usage: As Function
// vnf = octahedron(size, ...);
// Description:
// When called as a module, creates an octahedron with axis-aligned points.
// When called as a function, creates a [VNF](vnf.scad) of an octahedron with axis-aligned points.
// Arguments:
// size = Width of the octahedron, tip to tip.
// ---
// 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 towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP`
// Example:
// octahedron(size=40);
// Example: Anchors
// octahedron(size=40) show_anchors();
module octahedron(size=1, anchor=CENTER, spin=0, orient=UP) {
vnf = octahedron(size=size);
attachable(anchor,spin,orient, vnf=vnf, extent=true) {
vnf_polyhedron(vnf, convexity=2);
children();
}
}
function octahedron(size=1, anchor=CENTER, spin=0, orient=UP) =
let(
size = scalar_vec3(size),
s = size/2,
vnf = [
[ [0,0,s.z], [s.x,0,0], [0,s.y,0], [-s.x,0,0], [0,-s.y,0], [0,0,-s.z] ],
[ [0,2,1], [0,3,2], [0,4,3], [0,1,4], [5,1,2], [5,2,3], [5,3,4], [5,4,1] ]
]
) reorient(anchor,spin,orient, vnf=vnf, extent=true, p=vnf);
// Function&Module: regular_prism()
// Synopsis: Creates a regular prism with roundovers and chamfering
// SynTags: Geom, VNF
// Topics: Textures, Rounding, Chamfers
// See Also: cyl(), rounded_prism(), texture(), linear_sweep(), EDGE(), FACE()
// Usage: Normal prisms
// regular_prism(n, h|l=|height=|length=, r, [center=], [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.
// .
// 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 vertical 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.
// When you use `shift`, which moves the top face of the prism, the spin for the side face and edges anchors will align
// the child with the edge or face direction. 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" is oriented in the X+ direction.
// .
// This module is very 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.
// 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 = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=DOWN`.
// ---
// 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
// 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 a face 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`
// 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 for the textures. Actual texture sizes will be scaled somewhat to evenly fit the available surface. Default: `[5,5]`
// tex_reps = If given instead of tex_size, a 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 towards, 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: 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: 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,
chamfer, chamfer1, chamfer2,
chamfang, chamfang1, chamfang2,
rounding, rounding1, rounding2,
realign=false, shift=[0,0],
teardrop=false,
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,
chamfer=chamfer, chamfer1=chamfer1, chamfer2=chamfer2,
chamfang=chamfang,chamfang1=chamfang1,chamfang2=chamfang2,
rounding=rounding,rounding1=rounding1, rounding2=rounding2,
realign=realign, shift=shift,
teardrop=teardrop,
from_end=from_end, from_end1=from_end1, from_end2=from_end2,
texture=texture, tex_size=tex_size, tex_reps=tex_reps,
tex_inset=tex_inset, tex_rot=tex_rot,
tex_depth=tex_depth, tex_samples=tex_samples,
tex_taper=tex_taper, style=style,
_return_anchors=true);
attachable(anchor=anchor, orient=orient, spin=spin, vnf=vnf_anchors_ovr[0], anchors=vnf_anchors_ovr[1],override=vnf_anchors_ovr[2]){
vnf_polyhedron(vnf_anchors_ovr[0],convexity=is_def(texture)?10:2);
children();
}
}
function 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,
chamfer, chamfer1, chamfer2,
chamfang, chamfang1, chamfang2,