-
Notifications
You must be signed in to change notification settings - Fork 0
/
openscad_pvc.scad
2005 lines (1894 loc) · 93 KB
/
openscad_pvc.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: openscad_pvc.scad
// Modules and functions to create PVC pipe models within OpenSCAD. Models have their
// dimensions and sizes pulled from existing specifications, organized by PVC schedule
// and size, so they should be sized the same as parts found in a hardware store.
// PVC parts modeled here come with simple BOSL2 attachable endpoints, so joining parts
// together relatively easy when constructing pipe layouts or new component parts.
//
// Includes:
// include <openscad_pvc.scad>
//
// CommonCode:
// $fn = 100;
// pvc_a = pvc_spec_lookup(schedule=40, dn="DN20");
// pvc_b = pvc_spec_lookup(schedule=40, dn="DN10");
//
//
include <BOSL2/std.scad>
include <BOSL2/threading.scad>
include <object_common_functions.scad>
// Section: PVC Specification Selection
// To have consistent dimensions for parts and components when modeling PVC, you have to
// know the diameter and threading information for the size of PVC you're working with.
// Those dimensions are driven not only by the diameter of the pipe you're using, but
// the schedule rating for that pipe. There's dozens of sizes across the PVC schedules,
// and rather than make you look it all up, *those dimensions are pre-compiled and
// provided here.*
// .
// Selecting the specification you want is made easy with `pvc_spec_lookup()`, which
// gives you a PVC object - a self-contained block of dimension information that you can
// pass to the part modules below as an argument. If you're working with multiple sizes
// of PVC pipe, that's ok: you can lookup and use as many different specifications within
// your .scad as you need.
// .
// In its most common usage, you call `pvc_spec_lookup()` to get the specs for
// a pipe of a particular size and schedule, then use those specs to create one or
// more parts to join together, something akin to:
// ```
// pvc = pvc_spec_lookup(40, name="1/4");
// pvc_elbow(pvc)
// attach("A", "B")
// pvc_pipe(pvc);
// ```
//
// Function: pvc_spec_lookup()
// Synopsis: Look up a PVC schedule specification
// Usage:
// pvc = pvc_spec_lookup(schedule, <name=undef>, <dn=undef>, <od=undef>, <wall=undef>);
//
// Description:
// Given a PVC schedule `schedule` and one or more named selectors, search through the `PVC_Specs` list
// constant and find the PVC object whose attributes match the schedule and selectors, and
// return the PVC object `pvc`.
// .
// The `pvc` object is then suitable for use throughout the modules in this library.
// .
// It is possible to call `pvc_spec_lookup()` with valid arguments and have no matching PVC object returned.
// For example, `pvc_spec_lookup(40, name="1/8")` should correctly return the schedule-40 pipe spec for DN8,
// a 1/8-inch-diameter pipe; however, `pvc_spec_lookup(120, name="1/8")` will return an error, because schedule-120
// doesn't have a 1/8-inch-diameter pipe. In these cases, `pvc_spec_lookup()` will throw an assertion error.
// .
// It may be possible to call `pvc_spec_lookup()` with valid arguments and have multiple matching PVC objects returned.
// For example, `pvc_spec_lookup(40, wall=2.4)` may return two different small-diameter piping specifications.
// In these cases, `pvc_spec_lookup()` will throw an assertion error.
//
// Arguments:
// schedule = A PVC schedule, one of `PVC_KNOWN_SCHEDULES`, as a number. No default
// ---
// name = The nominal "name" of the PVC size (eg, `3/8`, `1`, `2 1/2`), as a character string. Default: `undef`
// dn = The "DN" specifier of the PVC size (eg, `DN10`, `DN125`), as a character string. Default: `undef`
// od = The outer-diameter of the PVC, in `mm` (eg, `10.3`). Default: `undef`
// wall = The wall thickness of the PVC, in `mm` (eg, `2.41`). Default: `undef`
/// tl = The thread-length of the PVC specification, in `mm` (eg, `4.3`). Default: `undef`
/// pitch = The thread pitch of the PVC specification, in `mm` (eg, `1.1`). Default: `undef`
//
// Continues:
// It is an error to call `pvc_spec_lookup()` with a schedule that isn't listed in `PVC_KNOWN_SCHEDULES`.
// .
// It is an error to call `pvc_spec_lookup()` without at least *one* of `name`, `dn`, `od`, or `wall` defined.
//
// Example: a basic lookup example using the nominal PVC size
// pvc = pvc_spec_lookup(40, name="3/4");
// echo( obj_debug_obj(pvc) );
// // ...yields:
// // ECHO: "0: _toc_: PVC
// // 1: schedule (i): 40
// // 2: name (s): 3/4
// // 3: od (i): 26.7
// // 4: wall (i): 2.87
// // 5: dn (s): DN20
// // 6: tl (i: 10): undef
// // 7: pitch (i: 0.9407): undef"
//
// Example: a basic lookup example using the "DN" of the specification
// pvc = pvc_spec_lookup(40, dn="DN20");
// echo( obj_debug_obj(pvc) );
// // ...yields:
// // ECHO: "0: _toc_: PVC
// // 1: schedule (i): 40
// // 2: name (s): 3/4
// // 3: od (i): 26.7
// // 4: wall (i): 2.87
// // 5: dn (s): DN20
// // 6: tl (i: 10): undef
// // 7: pitch (i: 0.9407): undef"
//
// Example(3D): lookup a basic specification, and use that object to make a pipe that is 30mm long:
// pvc = pvc_spec_lookup(40, dn="DN20");
// pvc_pipe(pvc, 30);
//
function pvc_spec_lookup(schedule, name=undef, dn=undef, od=undef, wall=undef, tl=undef, pitch=undef) =
assert(in_list(schedule, PVC_KNOWN_SCHEDULES),
str("pvc_spec_lookup(): 'schedule' is a required argument, and must be one of ", PVC_KNOWN_SCHEDULES))
assert(_defined([name, dn, od, wall, tl, pitch]),
str("pvc_spec_lookup(): at least one of 'name', 'dn', 'od', or 'wall' must be specified."))
let(
selectors = list_remove_values(
[
["schedule", schedule],
(_defined(name)) ? ["name", str(name)] : undef,
(_defined(dn)) ? ["dn", str(dn)] : undef,
(_defined(od)) ? ["od", od] : undef,
(_defined(wall)) ? ["wall", wall] : undef,
(_defined(tl)) ? ["tl", tl] : undef,
(_defined(pitch)) ? ["pitch", pitch] : undef
],
undef,
all=true)
)
assert(len(selectors) > 1,
str("pvc_spec_lookup(): no sufficent selectors could be gleaned."))
let(
speclist = obj_select_by_attrs_values(PVC_Specs, selectors)
)
assert(len(speclist) == 1,
str("pvc_spec_lookup(): exactly one specification was expected, got ",
len(speclist),
" instead. ",
(len(speclist) < 1)
? "The specification you are looking for may not exist."
: "If more than one spec was found, set additional selectors to narrow the return list."
))
speclist[0];
// Section: PVC Component Part Modules
// These are modules that produce PVC parts such as pipes, elbows, and tees.
// .
// All of the part modules require at least one PVC object. See the above function
// `pvc_spec_lookup()` for details on how to select a PVC object with which
// to work.
// .
// In all cases, they provide BOSL2-attaching and positioning. If you're unfamiliar with how
// attachables and anchoring works within BOSL2, a good (but dense) starting point can
// be found at https://github.com/revarbat/BOSL2/wiki/Tutorial-Attachments . The
// common module arguments `anchor`, `spin`, and `orient` all work the same way, and
// they work in the manner described in that attachments tutorial.
// .
// In their most simple form, parts are joined by attaching one to another. For example,
// creating a simple flange-pipe-elbow-cap layout is as simple as:
// ```
// pvc = pvc_spec_lookup(schedule=40, dn="DN20");
// pvc_flange(pvc)
// attach("B", "A")
// pvc_pipe(pvc, 30)
// attach("B", "A")
// pvc_elbow(pvc, 90)
// attach("B", "A")
// pvc_cap(pvc);
// ```
// ...yielding something that looks like:
// Figure(3D):
// pvc_flange(pvc_a)
// attach("B", "A")
// pvc_pipe(pvc_a, 30)
// attach("B", "A")
// pvc_elbow(pvc_a, 90)
// attach("B", "A")
// pvc_cap(pvc_a);
//
// Module: pvc_pipe()
// Synopsis: Create a PVC pipe model
// Usage:
// pvc_pipe(pvc, length);
// pvc_pipe(pvc, length, <ends=["spigot", "spigot"]>, <anchor=CENTER>, <spin=0>, <orient=UP>);
//
// Description:
// Given a PVC object `pvc` and a length `length`, create a PVC pipe `length` long, with the
// dimensions provided in the `pvc` object.
// .
// The pipe model will have two named anchors, `A`, and `B`. When oriented `UP` (the default),
// `A` will be the endpoint at the bottom of the pipe, and `B` will be at its top.
// Anchors are inset one-half of the PVC's thread-length, making joining with other
// parts simple (eg, `pvc_pipe(p, 10) attach("A", "A") pvc_elbow(pvc)`).
//
/// Figure(Spin,Anim,NoAxes):
/// pvc_pipe(pvc_a, 30);
//
// Arguments:
// pvc = An instantiated PVC specification
// length = The length of the pipe
// ---
// ends = A list of the two end types, `A` and `B`. Default: `["spigot", "spigot"]`
// anchor = Translate so anchor point is at origin `[0,0,0]`. Default: `PVC_DEFAULT_ANCHOR`
// spin = Rotate this many degrees around the Z axis after anchoring. Default: `PVC_DEFAULT_SPIN`
// orient = Vector direction to which the model should point after spin. Default: `PVC_DEFAULT_ORIENT`
//
// Named Anchors:
// A = One of the two endpoints of the pipe, positioned at its bottom, oriented downwards
// B = One of the two endpoints of the pipe, positioned at its top, oriented upwards
// Figure: Available named anchors
// expose_anchors() pvc_pipe(pvc_a, 30) show_anchors(std=false, s=40);
//
// Continues:
// It is not an error to specify end types other than "spigot" for pipes; however, it's
// not really a thing that happens a lot in the real world, y'know? You don't really
// see a lot of threaded pipes: you see pipes that are mated to parts that have threads.
// `pvc_pipe()` won't throw an error if one of your ends isn't a spigot, but I'd try to avoid it.
//
// Example: a basic pipe
// pvc_pipe(pvc_a, 30);
//
// Example: a basic pipe, forward-oriented:
// pvc_pipe(pvc_a, 30, orient=FWD);
//
// Todo:
// When the merge at https://github.com/openscad/openscad/pull/4185 is released to general-availability, reenable the animated spin of the model in Figure-1 here, and throughout the other part modules in this library.
//
module pvc_pipe(pvc, length, ends=[],
anchor=PVC_DEFAULT_ANCHOR, spin=PVC_DEFAULT_SPIN, orient=PVC_DEFAULT_ORIENT) {
od = pvc_od(pvc);
id = pvc_id(pvc);
tl = pvc_tl(pvc);
wall = pvc_wall(pvc);
transition_len = tl * 0.1;
truncated_len = length - (tl * 2);
assert(truncated_len >= 0,
str("pvc_pipe(): the length of the pipe is too short: ",
truncated_len));
ends_ = list_apply_defaults(ends, ["spigot", "spigot"]);
ep_a_od = (ends_[0] == "socket") ? pvc_socket_od(pvc) : pvc_od(pvc);
ep_b_od = (ends_[1] == "socket") ? pvc_socket_od(pvc) : pvc_od(pvc);
ep_a_id = (ends_[0] == "socket") ? pvc_socket_id(pvc) : pvc_id(pvc);
ep_b_id = (ends_[1] == "socket") ? pvc_socket_id(pvc) : pvc_id(pvc);
anchors = [
named_anchor("A", apply(up(tl/2) * down(length/2), CENTER), DOWN, 0),
named_anchor("B", apply(down(tl/2) * up(length/2), CENTER), UP, 0)
];
attachable(anchor, spin, orient, d=od, h=length, anchors=anchors) {
diff("pvc_rem__full")
tube(od=od, wall=wall, l=truncated_len, anchor=CENTER) {
attach(BOTTOM, "_j_down")
pvc_part_component(pvc, end=ends_[0], length=0); // A
attach(TOP, "_j_down")
pvc_part_component(pvc, end=ends_[1], length=0); // B
attach(CENTER, CENTER)
tag("pvc_rem__full")
cylinder(d=id, h=length);
}
children();
}
}
// Module: pvc_elbow()
// Synopsis: Create a PVC elbow model
// Usage:
// pvc_elbow(pvc, angle);
// pvc_elbow(pvc, angle, <ends=["socket", "socket"]>, <anchor=CENTER>, <spin=0>, <orient=UP>);
//
// Description:
// Given a PVC object `pvc`, and a bending number of degrees `angle`, create a
// PVC elbow component. `angle` can be any reasonable number of degrees including `180`,
// though beyond that and the viability of the elbow is questionable.
// .
// The elbow will have two named anchors `A` and `B`. When oriented `UP` (the default),
// `A` will be the endpoint at the bottom of the elbow, and `B` will be at whatever
// angle the elbow outputs.
// The `ends` list argument specifies what endtypes will be created for the `A` and `B`
// pipe ends, respectively. If `ends` is unspecified, or if any of the positional
// list elements are `undef`, then those unspecified ends will be a socket.
//
/// Figure(Spin,Anim,NoAxes):
/// pvc_elbow(pvc_a, 45);
//
// Arguments:
// pvc = An instantiated PVC specification
// angle = The angle in degrees to bend the elbow
// ---
// ends = A list of the two end types, `A` and `B`. Default: `["socket", "socket"]`
// anchor = Translate so anchor point is at origin `[0,0,0]`. Default: `PVC_DEFAULT_ANCHOR`
// spin = Rotate this many degrees around the Z axis after anchoring. Default: `PVC_DEFAULT_SPIN`
// orient = Vector direction to which the model should point after spin. Default: `PVC_DEFAULT_ORIENT`
//
// Named Anchors:
// A = One of the two endpoints of the pipe, positioned at its bottom, oriented downwards
// B = One of the two endpoints of the pipe, angled to the right, oriented at `angle` degrees
// Figure: Available named anchors
// expose_anchors() pvc_elbow(pvc_a, 45) show_anchors(std=false, s=40);
//
// Continues:
// Because of the odd shape for this model, the cardinal anchoring points for `pvc_elbow` won't
// reflect the full envelope of the model; don't assume anchoring `RIGHT` or `TOP` will be at the models
// rightmost or topmost position.
//
// Example: a basic elbow
// pvc_elbow(pvc_a, 45);
//
// Example: an 90-degree elbow with female threads
// pvc_elbow(pvc_a, 90, ends=["fipt", "fipt"]);
//
module pvc_elbow(pvc, angle, ends=[],
anchor=PVC_DEFAULT_ANCHOR, spin=PVC_DEFAULT_SPIN, orient=PVC_DEFAULT_ORIENT) {
ends_ = list_apply_defaults(ends, ["socket", "socket"]);
od = pvc_od(pvc);
id = pvc_id(pvc);
tl = pvc_tl(pvc);
segment_len = tl + 1;
curved_region = right(od/2, p=difference( circle(d=od), circle(d=id) ));
anchors = [
named_anchor("A", [0, 0, -1 * segment_len/2 + tl/2], DOWN, 0),
// translating the anchor point for 'B' looks a bit nuts; here's whats happening:
// we start at the center of the lower pipe segment, and move up() half the length of the
// segment to the center of the top of the pipe (or, the center of the bottom of the
// sweep'd segment). From there, we rotate `angle` degrees, using a pivot point that
// that is the right+top edge of the lower pipe. That rotation puts us at the center
// of the bottom of the upper pipe. From there, we move up() half the length of the segment
// again. To get the anchor in the center of the threaded length, we have to then rotate
// using the base of the upper pipe as a pivot: so, we re-calculate all those moves
// again to get the yrot() `cp`, and rotate `angle` degrees again.
// For those of you asking "why don't you just create a sphere and angle pipes and
// and anchors from that?", my answer is, because it's hella ugly.
named_anchor("B",
apply(
yrot(angle, cp=apply(
yrot(angle, cp=apply(up(segment_len/2) * right(od/2), CENTER))
* up(segment_len/2),
CENTER))
* up(segment_len/2)
* yrot(angle, cp=apply(up(segment_len/2) * right(od/2), CENTER))
* up(segment_len/2),
CENTER),
apply(yrot(angle), UP), 0),
];
attachable(anchor, spin, orient, d=od, h=segment_len, anchors=anchors) {
diff("pvc_rem__full")
union() {
pvc_part_component(pvc, end=ends_[0], length=1, anchor=CENTER, orient=DOWN);
right(od/2)
zrot(180)
up(segment_len/2)
rotate_sweep(curved_region, angle, spin=0, orient=FWD, anchor=CENTER);
up(segment_len/2)
right(od/2)
yrot(angle)
tag("pvc_rem__full")
sphere(d=0.0001)
attach(TOP, "_j_down")
left(od/2)
tag("")
pvc_part_component(pvc, length=1, end=ends_[1]);
}
children();
}
}
// Module: pvc_wye()
// Synopsis: Create a PVC wye model
// Usage:
// pvc_wye(pvc);
// pvc_wye(pvc, <ends=["socket", "socket", "socket"]>, <anchor=CENTER>, <spin=0>, <orient=UP>);
//
// Description:
// Given a PVC object, create a wye PVC part: essentially, a pipe with two endpoints, and a
// segment of pipe jutting out at 45-degrees from the center ending in a third endpoint.
// .
// The wye will have three named anchors, `A`, `B`, `C`. When oriented `UP` (the default),
// `A` will be the endpoint at the bottom of the wye, `B` will be at its top, and `C` will
// be the extension angling to the right.
// The `ends` list argument specifies what endtypes will be created for `A`, `B`, `C` endtypes,
// respectively. Absent endtypes from `ends` will default to "socket".
//
/// Figure(Spin,Anim,NoAxes):
/// pvc_wye(pvc_a);
//
// Arguments:
// pvc = An instantiated PVC specification
// ---
// ends = A list of the three end types, `A`, `B`, & `C`. Default: `["socket", "socket", "socket"]`
// anchor = Translate so anchor point is at origin `[0,0,0]`. Default: `PVC_DEFAULT_ANCHOR`
// spin = Rotate this many degrees around the Z axis after anchoring. Default: `PVC_DEFAULT_SPIN`
// orient = Vector direction to which the model should point after spin. Default: `PVC_DEFAULT_ORIENT`
//
// Named Anchors:
// A = One of the two endpoints of the main pipe, positioned at its bottom, oriented downwards
// B = One of the two endpoints of the main pipe, positioned at its top, oriented upwards
// C = The right-hand out-jutting endpoint, angled to the right, oriented upwards at 45-degrees
// Figure: Available named anchors
// expose_anchors() pvc_wye(pvc_a) show_anchors(std=false, s=40);
//
// Continues:
// Because of the odd shape for this model, the cardinal anchoring points for `pvc_wye()` won't
// reflect the full envelope of the model; don't assume anchoring `RIGHT` or `TOP` will be at the models
// rightmost or topmost position.
//
// Example: a simple wye
// pvc_wye(pvc_a);
//
module pvc_wye(pvc, ends=[],
anchor=PVC_DEFAULT_ANCHOR, spin=PVC_DEFAULT_SPIN, orient=PVC_DEFAULT_ORIENT) {
ends_ = list_apply_defaults(ends, ["socket", "socket", "socket"]);
od = pvc_od(pvc);
id = pvc_id(pvc);
tl = pvc_tl(pvc);
part_addl = tl * 4;
segment_len = tl + part_addl;
total_part_height = sum([
segment_len,
tl,
part_addl - tl * 2
]);
anchors = [
named_anchor("A", apply(up(tl/2) * down(part_addl - tl) * down(tl), CENTER), DOWN, 0),
named_anchor("B", apply(up(part_addl + tl/2) * down(tl), CENTER), UP, 0),
named_anchor("C", apply(yrot(45, cp=apply(down(tl), CENTER)) * up(part_addl + tl/2) * down(tl), CENTER), UP+RIGHT, 0),
];
attachable(anchor, spin, orient, d=od, h=total_part_height, anchors=anchors) {
down(tl)
diff("pvc_rem__full") {
tag("pvc_rem__full")
sphere(d=0.001, anchor=CENTER) {
attach(BOTTOM, "_j_down")
tag("") pvc_part_component(pvc, length=part_addl - tl * 2, end=ends_[0]); // A
attach(TOP, "_j_down")
tag("") pvc_part_component(pvc, length=part_addl, end=ends_[1]); // B
attach(RIGHT+TOP, "_j_down")
tag("") pvc_part_component(pvc, length=part_addl, end=ends_[2]); // C
}
}
children();
}
}
// Module: pvc_tee()
// Synopsis: Create a PVC tee model
// Usage:
// pvc_tee(pvc);
// pvc_tee(pvc, <ends=["socket", "socket", "socket"]>, <anchor=CENTER>, <spin=0>, <orient=UP>);
//
// Description:
// Given a PVC object `pvc`, create a PVC tee component. A tee is essentially a length of pipe
// with a outspout extending to the right at 90-degrees.
// .
// The tee will have three named anchors, `A`, `B`, `C`. When oriented `UP` (the default),
// `A` will be the endpoint at the bottom of the tee, `B` will be at its top, and `C` will
// be the extension to the right.
// The `ends` list argument specifies what endtypes will be created for `A`, `B`, `C` endtypes,
// respectively. Absent endtypes from `ends` will default to "socket".
//
/// Figure(Spin,Anim,NoAxes):
/// pvc_tee(pvc_a);
//
// Arguments:
// pvc = An instantiated PVC specification
// ---
// ends = A list of the three end types, `A`, `B`, & `C`. Default: `["socket", "socket", "socket"]`
// anchor = Translate so anchor point is at origin `[0,0,0]`. Default: `PVC_DEFAULT_ANCHOR`
// spin = Rotate this many degrees around the Z axis after anchoring. Default: `PVC_DEFAULT_SPIN`
// orient = Vector direction to which the model should point after spin. Default: `PVC_DEFAULT_ORIENT`
//
// Named Anchors:
// A = One of the two endpoints of the main pipe, positioned at its bottom, oriented downwards
// B = One of the two endpoints of the main pipe, positioned at its top, oriented upwards
// C = The right-hand out-jutting endpoint, angled to the right, oriented rightwards
// Figure: Available named anchors
// expose_anchors() pvc_tee(pvc_a) show_anchors(std=false, s=40);
//
// Continues:
// Because of the odd shape for this model, the cardinal anchoring points for `pvc_tee()` won't
// reflect the full envelope of the model; don't assume anchoring `RIGHT` or `LEFT` will be at the models
// rightmost or leftmost position.
//
// Example: a simple tee
// pvc_tee(pvc_a);
//
// Example: a tee with a variety of end types
// pvc_tee(pvc_a, ends=["socket", "mipt", "fipt"]);
//
module pvc_tee(pvc, ends=[],
anchor=PVC_DEFAULT_ANCHOR, spin=PVC_DEFAULT_SPIN, orient=PVC_DEFAULT_ORIENT) {
ends_ = list_apply_defaults(ends, ["socket", "socket", "socket"]);
od = pvc_od(pvc);
id = pvc_id(pvc);
tl = pvc_tl(pvc);
tee_pipe_len = sum([ tl, pvc_socket_od(pvc) ]);
total_pipe_len = tee_pipe_len * 2;
total_tee_height = sum([ tl, od/2, od/2, tl ]);
anchors = [
named_anchor("A", [0, 0, -1 * total_tee_height/2 + tl/2], DOWN, 0),
named_anchor("B", [0, 0, total_tee_height/2 - tl/2], UP, 0),
named_anchor("C", [tl/2 + od/2, 0, 0], RIGHT, 0)
];
attachable(anchor, spin, orient, d=od, h=total_tee_height, anchors=anchors) {
diff("pvc_rem__full", "pvc_keep__full")
pvc_part_component(pvc, end=ends_[0], length=od/2, anchor=BOTTOM) { // A
attach("_j_down", "_j_down")
pvc_part_component(pvc, end=ends_[1], length=od/2); // B
attach("_j_right", "_j_down")
pvc_part_component(pvc, length=od/2, end=ends_[2]); // C
}
children();
}
}
// Module: pvc_corner()
// Synopsis: Create a PVC corner model
// Usage:
// pvc_corner(pvc);
// pvc_corner(pvc, <ends=["socket", "socket", "socket"]>, <anchor=CENTER>, <spin=0>, <orient=UP>);
//
// Description:
// Given a PVC object, create a corner part. A corner is three endpoints at 90-degrees from
// each other, pointing forward, upwards, and rightwards.
// .
// The corner will have three named anchors, `A`, `B`, `C`. When oriented `UP` (the default),
// `A` will be the endpoint at the front of the corner, `B` will be at its top, and `C` will
// be pointing to the right.
// The `ends` list argument specifies what endtypes will be created for `A`, `B`, `C` endtypes,
// respectively. Absent endtypes from `ends` will default to "socket".
//
/// Figure(Spin,Anim,NoAxes):
/// pvc_corner(pvc_a);
//
// Arguments:
// pvc = An instantiated PVC specification
// ---
// ends = A list of the three end types, `A`, `B`, & `C`. Default: `["socket", "socket", "socket"]`
// anchor = Translate so anchor point is at origin `[0,0,0]`. Default: `PVC_DEFAULT_ANCHOR`
// spin = Rotate this many degrees around the Z axis after anchoring. Default: `PVC_DEFAULT_SPIN`
// orient = Vector direction to which the model should point after spin. Default: `PVC_DEFAULT_ORIENT`
//
// Named Anchors:
// A = One of the three endpoints of the corner, positioned at its front, oriented forwards
// B = One of the three endpoints of the corner, positioned at its top, oriented upwards
// C = One of the three endpoints of the corner, position to the right, oriented rightwards
// Figure: Available named anchors
// expose_anchors() pvc_corner(pvc_a) show_anchors(std=false, s=40);
//
// Continues:
// Because of the odd shape for this model, the cardinal anchoring points for `pvc_corner()` won't
// reflect the full envelope of the model; don't assume anchoring `RIGHT` or `TOP` will be at the models
// rightmost or topmost position.
//
// Example: a simple corner
// pvc_corner(pvc_a);
//
module pvc_corner(pvc, ends=[],
anchor=PVC_DEFAULT_ANCHOR, spin=PVC_DEFAULT_SPIN, orient=PVC_DEFAULT_ORIENT) {
ends_ = list_apply_defaults(ends, ["socket", "socket", "socket"]);
od = pvc_od(pvc);
id = pvc_id(pvc);
tl = pvc_tl(pvc);
tee_pipe_len = sum([ tl, od/2 ]);
total_pipe_height = sum([ tee_pipe_len, od/2 ]);
anchors = [
named_anchor("A",
apply( back(tl/2) * fwd(tee_pipe_len) * up(od/2) * down(total_pipe_height/2), CENTER),
FWD, 0),
named_anchor("B", // NOTE: 'B' is not perfect, because total_pipe_height is not 100% accurate.
apply( down(tl/2) * up(total_pipe_height/2), CENTER),
UP, 0),
named_anchor("C",
apply( left(tl/2) * right(tee_pipe_len) * up(od/2) * down(total_pipe_height/2), CENTER),
RIGHT, 0)
];
attachable(anchor, spin, orient, d=od, h=total_pipe_height, anchors=anchors) {
down(total_pipe_height/2)
diff("pvc_rem__full") {
sphere(d=od, anchor=BOTTOM) {
attach(CENTER, CENTER)
tag("pvc_rem__full")
sphere(d=id);
attach(TOP, "_j_down", overlap=od/2)
pvc_part_component(pvc, length=od/2, end=ends_[1]); // B
attach(RIGHT, "_j_down", overlap=od/2)
pvc_part_component(pvc, length=od/2, end=ends_[2]); // C
attach(FWD, "_j_down", overlap=od/2)
pvc_part_component(pvc, length=od/2, end=ends_[0]); // A
}
}
children();
}
}
// Module: pvc_side_outlet_tee()
// Synopsis: Create a PVC side-outlet tee model
// Usage:
// pvc_side_outlet_tee(pvc);
// pvc_side_outlet_tee(pvc, <ends=["socket", "socket", "socket", "socket"]>, <anchor=CENTER>, <spin=0>, <orient=UP>);
//
// Description:
// Given a PVC object `pvc`, create a PVC tee component. A tee is essentially a length of pipe
// with a out-spout extending to the right at 90-degrees; a side outlet tee is a tee with an
// out-spout extending forward at 90-degrees.
// .
// The tee will have four named anchors, `A`, `B`, `C`, `D`. When oriented `UP` (the default),
// `A` will be the endpoint at the bottom of the tee, `B` will be at its top, and `C` will
// be the extension to the right, and `D` will be the extension facing forward.
// The `ends` list argument specifies what endtypes will be created for `A`, `B`, `C`, `D` endtypes,
// respectively. Absent endtypes from `ends` will default to "socket".
//
/// Figure(Spin,Anim,NoAxes):
/// pvc_side_outlet_tee(pvc_a);
//
// Arguments:
// pvc = An instantiated PVC specification
// ---
// ends = A list of the four end types, `A`, `B`, `C`, & `D`. Default: `["socket", "socket", "socket", "socket"]`
// anchor = Translate so anchor point is at origin `[0,0,0]`. Default: `PVC_DEFAULT_ANCHOR`
// spin = Rotate this many degrees around the Z axis after anchoring. Default: `PVC_DEFAULT_SPIN`
// orient = Vector direction to which the model should point after spin. Default: `PVC_DEFAULT_ORIENT`
//
// Named Anchors:
// A = One of the two endpoints of the main pipe, positioned at its bottom, oriented downwards
// B = One of the two endpoints of the main pipe, positioned at its top, oriented upwards
// C = The right-hand out-jutting endpoint, angled to the right, oriented rightwards
// D = The forwad-facing out-jutting endpoint, angled to forward, oriented forwards
// Figure: Available named anchors
// expose_anchors() pvc_side_outlet_tee(pvc_a) show_anchors(std=false, s=40);
//
// Continues:
// Because of the odd shape for this model, the cardinal anchoring points for `pvc_side_outlet_tee()` won't
// reflect the full envelope of the model; don't assume anchoring `RIGHT` or `FWD` will be at the models
// rightmost or foremost position.
//
// Example: a simple tee
// pvc_side_outlet_tee(pvc_a);
//
// Example: a tee with a variety of end types
// pvc_side_outlet_tee(pvc_a, ends=["socket", "mipt", "fipt"]);
//
module pvc_side_outlet_tee(pvc, ends=[],
anchor=PVC_DEFAULT_ANCHOR, spin=PVC_DEFAULT_SPIN, orient=PVC_DEFAULT_ORIENT) {
ends_ = list_apply_defaults(ends, ["socket", "socket", "socket", "socket"]);
od = pvc_socket_od(pvc);
id = pvc_socket_id(pvc);
tl = pvc_tl(pvc);
h_tl = tl/2;
tee_pipe_len = sum([ tl, od/2 ]);
total_pipe_height = tee_pipe_len * 2;
anchors = [
named_anchor("A", apply(down(tee_pipe_len - h_tl), CENTER), DOWN, 0),
named_anchor("B", apply(up(tee_pipe_len - h_tl), CENTER), UP, 0),
named_anchor("C", apply(right(tee_pipe_len - h_tl), CENTER), RIGHT, 0),
named_anchor("D", apply(fwd(tee_pipe_len - h_tl), CENTER), FWD, 0)
];
attachable(anchor, spin, orient, d=od, h=total_pipe_height, anchors=anchors) {
up(total_pipe_height/2)
diff("pvc_rem__full")
pvc_part_component(pvc, length=od/2, end=ends_[1], anchor=TOP) { // B
attach("_j_down", "_j_down")
pvc_part_component(pvc, length=od/2, end=ends_[0]); // A
attach("_j_right", "_j_down")
pvc_part_component(pvc, length=od/2, end=ends_[2]); // C
attach("_j_fwd", "_j_down")
pvc_part_component(pvc, length=od/2, end=ends_[3]); // D
}
children();
}
}
// Module: pvc_cross()
// Synopsis: Create a PVC cross model
// Usage:
// pvc_cross(pvc);
// pvc_cross(pvc, <ends=["socket", "socket", "socket", "socket"]>, <anchor=CENTER>, <spin=0>, <orient=UP>);
//
// Description:
// Given a PVC object `pvc`, create a PVC cross component. A cross is essentially two lengths of pipe
// joined together in their center at right angles, with four outlets.
// .
// The cross will have four named anchors, `A`, `B`, `C`, `D`. When oriented `UP` (the default),
// `A` will be the endpoint at the bottom of the cross, `B` will be at its top, and `C` will
// be to the right, and `D` will be to the left.
// The `ends` list argument specifies what endtypes will be created for `A`, `B`, `C`, `D` endtypes,
// respectively. Absent endtypes from `ends` will default to "socket".
//
/// Figure(Spin,Anim,NoAxes):
/// pvc_cross(pvc_a);
//
// Arguments:
// pvc = An instantiated PVC specification
// ---
// ends = A list of the four end types, `A`, `B`, `C`, & `D`. Default: `["socket", "socket", "socket", "socket"]`
// anchor = Translate so anchor point is at origin `[0,0,0]`. Default: `PVC_DEFAULT_ANCHOR`
// spin = Rotate this many degrees around the Z axis after anchoring. Default: `PVC_DEFAULT_SPIN`
// orient = Vector direction to which the model should point after spin. Default: `PVC_DEFAULT_ORIENT`
//
// Named Anchors:
// A = One of the two endpoints of the main pipe, positioned at its bottom, oriented downwards
// B = One of the two endpoints of the main pipe, positioned at its top, oriented upwards
// C = The right-hand out-jutting endpoint, angled to the right, oriented rightwards
// D = The left-hand out-jutting endpoint, angled to the left, oriented leftwards
// Figure: Available named anchors
// expose_anchors() pvc_cross(pvc_a) show_anchors(std=false, s=40);
//
// Continues:
// Because of the odd shape for this model, the cardinal anchoring points for `pvc_cross()` won't
// reflect the full envelope of the model; don't assume anchoring `RIGHT` or `FWD` will be at the models
// rightmost or foremost position.
//
// Example: a simple tee
// pvc_cross(pvc_a);
//
// Example: a tee with a variety of end types
// pvc_cross(pvc_a, ends=["socket", "mipt", "fipt", "spigot"]);
//
module pvc_cross(pvc, ends=[],
anchor=PVC_DEFAULT_ANCHOR, spin=PVC_DEFAULT_SPIN, orient=PVC_DEFAULT_ORIENT) {
ends_ = list_apply_defaults(ends, ["socket", "socket", "socket", "socket"]);
od = pvc_od(pvc);
tl = pvc_tl(pvc);
h_tl = tl / 2;
tee_pipe_length = sum([ tl, od/2 ]);
total_pipe_height = tee_pipe_length * 2;
h_total_pipe_height = total_pipe_height / 2;
anchors = [
named_anchor("A", apply(down(h_total_pipe_height - h_tl), CENTER), DOWN, 0),
named_anchor("B", apply(up(h_total_pipe_height - h_tl), CENTER), UP, 0),
named_anchor("C", apply(right(h_total_pipe_height - h_tl), CENTER), RIGHT, 0),
named_anchor("D", apply(left(h_total_pipe_height - h_tl), CENTER), LEFT, 0)
];
attachable(anchor, spin, orient, d=od, h=total_pipe_height, anchors=anchors) {
up(total_pipe_height/2)
diff("pvc_rem__full")
pvc_part_component(pvc, length=od/2, end=ends_[1], anchor=TOP) { // B
attach("_j_down", "_j_down")
pvc_part_component(pvc, length=od/2, end=ends_[0]); // A
attach("_j_right", "_j_down")
pvc_part_component(pvc, length=od/2, end=ends_[2]); // C
attach("_j_left", "_j_down")
pvc_part_component(pvc, length=od/2, end=ends_[3]); // D
}
children();
}
}
// Module: pvc_six_way_joint()
// Synopsis: Create a PVC six-way joint model
// Usage:
// pvc_six_way_joint(pvc);
// pvc_six_way_joint(pvc, <ends=["socket", ...]>, <anchor=CENTER>, <spin=0>, <orient=UP>);
//
// Description:
// Given a PVC object `pvc`, create a PVC six-way joint component. A six-way is essentially three lengths of pipe
// joined together in their center at right angles, with six outlets.
// .
// The cross will have four named anchors, `A`, `B`, `C`, `D`, `E`, `F`. When oriented `UP` (the default),
// `A` will be the endpoint at the bottom of the cross, `B` will be at its top, `C` will
// be to the right, `D` will be to the left, `E` will be facing forwards, and `F` will be facing backwards.
// The `ends` list argument specifies what endtypes will be created for `A`, `B`, `C`, `D`, `E`, `F` endtypes,
// respectively. Absent endtypes from `ends` will default to "socket".
//
/// Figure(Spin,Anim,NoAxes):
/// pvc_six_way_joint(pvc_a);
//
// Arguments:
// pvc = An instantiated PVC specification
// ---
// ends = A list of the six end types, `A`, `B`, `C`, `D`, `E`, & `F`. Default: `["socket", ...]`
// anchor = Translate so anchor point is at origin `[0,0,0]`. Default: `PVC_DEFAULT_ANCHOR`
// spin = Rotate this many degrees around the Z axis after anchoring. Default: `PVC_DEFAULT_SPIN`
// orient = Vector direction to which the model should point after spin. Default: `PVC_DEFAULT_ORIENT`
//
// Named Anchors:
// A = One of the six endpoints of the joint, positioned at its bottom, oriented downwards
// B = One of the six endpoints of the joint, positioned at its top, oriented upwards
// C = The right-hand out-jutting endpoint, angled to the right, oriented rightwards
// D = The left-hand out-jutting endpoint, angled to the left, oriented leftwards
// E = The foward-facing out-jutting endpoint, oriented forwards
// F = The backward-facing out-jutting endpoint, oriented backwards
// Figure: Available named anchors
// expose_anchors() pvc_six_way_joint(pvc_a) show_anchors(std=false, s=40);
//
// Continues:
// Because of the odd shape for this model, the cardinal anchoring points for `pvc_six_way_joint()` won't
// reflect the full envelope of the model; don't assume anchoring `RIGHT` or `FWD` will be at the models
// rightmost or foremost position.
//
// Example: a simple tee
// pvc_six_way_joint(pvc_a);
//
// Example: a tee with a variety of end types
// pvc_six_way_joint(pvc_a, ends=["socket", "mipt", "fipt", "spigot"]);
//
module pvc_six_way_joint(pvc, ends=[],
anchor=PVC_DEFAULT_ANCHOR, spin=PVC_DEFAULT_SPIN, orient=PVC_DEFAULT_ORIENT) {
ends_ = list_apply_defaults(ends, ["socket", "socket", "socket", "socket", "socket", "socket"]);
od = pvc_od(pvc);
tl = pvc_tl(pvc);
part_len_addl = od/2 + 2;
tee_pipe_len = tl + part_len_addl;
total_pipe_len = tee_pipe_len * 2;
anchors = [
named_anchor("A", apply(up(tl/2) * down(tee_pipe_len), CENTER), DOWN, 0),
named_anchor("B", apply(down(tl/2) * up(tee_pipe_len), CENTER), UP, 0),
named_anchor("C", apply(left(tl/2) * right(tee_pipe_len), CENTER), RIGHT, 0),
named_anchor("D", apply(right(tl/2) * left(tee_pipe_len), CENTER), LEFT, 0),
named_anchor("E", apply(back(tl/2) * fwd(tee_pipe_len), CENTER), FWD, 0),
named_anchor("F", apply(fwd(tl/2) * back(tee_pipe_len), CENTER), BACK, 0),
];
attachable(anchor, spin, orient, d=od, h=total_pipe_len, anchors=anchors) {
diff("pvc_rem__full")
pvc_part_component(pvc, length=part_len_addl, end=ends_[1], anchor="_j_down") { // B
attach("_j_down", "_j_down")
pvc_part_component(pvc, length=part_len_addl, end=ends_[0]); // A
attach("_j_down", "_j_right")
pvc_part_component(pvc, length=part_len_addl, end=ends_[2]); // C
attach("_j_down", "_j_left")
pvc_part_component(pvc, length=part_len_addl, end=ends_[3]); // D
attach("_j_down", "_j_fwd")
pvc_part_component(pvc, length=part_len_addl, end=ends_[4]); // E
attach("_j_down", "_j_back")
pvc_part_component(pvc, length=part_len_addl, end=ends_[5]); // F
}
children();
}
}
// Module: pvc_coupling()
// Synopsis: Create a PVC coupling model
// Usage:
// pvc_coupling(pvc);
// pvc_coupling(pvc, <ends=["socket", "socket"]>, <anchor=CENTER>, <spin=0>, <orient=UP>);
//
// Description:
// Given a PVC object `pvc`, create a PVC coupler. A coupler is a part that joins two
// lengths of pipes or two parts, usually with socket or fipt ends.
// .
// The coupler will have two named anchors `A` and `B`. When oriented `UP` (the default),
// `A` will be the endpoint at the bottom of the coupler, and `B` will be at its top.
// The `ends` list argument specifies what endtypes will be created for the `A` and `B`
// pipe ends, respectively. If `ends` is unspecified, or if any of the positional
// list elements are `undef`, then those unspecified ends will be a socket.
//
/// Figure(Spin,Anim,NoAxes):
/// pvc_coupling(pvc_a);
//
// Arguments:
// pvc = An instantiated PVC specification
// ---
// ends = A list of the two end types, `A` and `B`. Default: `["socket", "socket"]`
// anchor = Translate so anchor point is at origin `[0,0,0]`. Default: `PVC_DEFAULT_ANCHOR`
// spin = Rotate this many degrees around the Z axis after anchoring. Default: `PVC_DEFAULT_SPIN`
// orient = Vector direction to which the model should point after spin. Default: `PVC_DEFAULT_ORIENT`
//
// Named Anchors:
// A = One of the two endpoints of the coupling, positioned at its bottom, oriented downwards
// B = One of the two endpoints of the coupling, positioned at its top, oriented upwards
// Figure: Available named anchors
// expose_anchors() pvc_coupling(pvc_a) show_anchors(std=false, s=40);
//
// Continues:
// It's not an error to specify end types other than "socket" or "fipt" for couplers; however,
// it's not really a thing that happens a lot in the real world. A coupler with two "mipt"
// ends is a nipple (see `pvc_nipple()` below); and a coupler with two "spigot" ends is
// just a short length of pipe with no special ends. `pvc_coupler()` won't throw an error if
// the ends aren't a socket or fipt, but I'd try to avoid it.
//
// Example: a basic coupling
// pvc_coupling(pvc_a);
//
// Example: a coupling with female threading on each end
// pvc_coupling(pvc_a, ends=["fipt", "fipt"]);
//
module pvc_coupling(pvc, ends=[],
anchor=PVC_DEFAULT_ANCHOR, spin=PVC_DEFAULT_SPIN, orient=PVC_DEFAULT_ORIENT) {
// should we perhaps warn the caller if the coupler isn't socket/fipt?
ends_ = list_apply_defaults(ends, ["socket", "socket"]);
od = pvc_od(pvc);
tl = pvc_tl(pvc);
pipe_addl = 3;
pipe_len = sum([ tl, pipe_addl ]);
total_pipe_len = pipe_len * 2;
anchors = [
named_anchor("A", apply(up(tl/2) * down(pipe_len), CENTER), DOWN, 0),
named_anchor("B", apply(down(tl/2) * up(pipe_len), CENTER), UP, 0)
];
attachable(anchor, spin, orient, d=od, h=total_pipe_len, anchors=anchors) {
diff("pvc_rem__full")
pvc_part_component(pvc, length=pipe_addl, end=ends_[1], anchor=BOTTOM) // B
attach("_j_down", "_j_down")
pvc_part_component(pvc, length=pipe_addl, end=ends_[0]); // A
children();
}
}
// Module: pvc_cap()
// Synopsis: Create a PVC cap model
// Usage:
// pvc_cap(pvc);
// pvc_cap(pvc, <ends=["socket"]>, <anchor=CENTER>, <spin=0>, <orient=UP>);
//
// Description:
// Given a PVC object `pvc`, create a cap for a PVC endpoint. A cap covers an ending of pipe or other PVC part,
// wraping around the outside of the ending.
// .
// The cap model will have one named anchor, `A`. When oriented `UP` (the default), `A` will be the oriented
// upwards at the top of the cap.
// Anchors are inset on-half of the PVC's thread-lengh, making joining with other parts simple
// (eg, `pvc_pipe(pvc) attach("A", "A") pvc_cap(pvc)`).
//
/// Figure(Spin,Anim,NoAxes):
/// pvc_cap(pvc_a);
//
// Arguments:
// pvc = An instantiated PVC specification
// ---
// ends = A list of the single end type, `A`. Default: `["socket"]`
// anchor = Translate so anchor point is at origin `[0,0,0]`. Default: `PVC_DEFAULT_ANCHOR`
// spin = Rotate this many degrees around the Z axis after anchoring. Default: `PVC_DEFAULT_SPIN`
// orient = Vector direction to which the model should point after spin. Default: `PVC_DEFAULT_ORIENT`
//
// Named Anchors:
// A = The endpoint of the cap, positioned at its top, oriented upwards
// Figure: Available named anchors
// expose_anchors() pvc_cap(pvc_a) show_anchors(std=false, s=40);
//
// Continues:
// It is an error to specify an end type other than "fipt" or "socket" for caps. If you need
// something to block a pipe or part ending that doesn't fit outside of the pipe's outer-diameter,
// look at `pvc_plug()`.
// .
// The argument `ends` accepts a list-argument of end types, keeping the argument type
// consistent with other PVC part modules, though it only considers the first element in
// that list.
//
// Example: a basic cap
// pvc_cap(pvc_a);
//
// Example: capping a pipe
// pvc_pipe(pvc_a, 30)
// attach("B", "A")
// pvc_cap(pvc_a);
//
// Todo:
// a cap perhaps doesn't need to have the same wall thickness as the pipe it's being attached to.
// caps probably also have a slightly domed top. :shrug:
//
module pvc_cap(pvc, ends=[],
anchor=PVC_DEFAULT_ANCHOR, spin=PVC_DEFAULT_SPIN, orient=PVC_DEFAULT_ORIENT) {
ends_ = list_apply_defaults(ends, ["socket"]);
assert(in_list(ends_[0], ["fipt", "socket"]),
"pvc_cap(): Only 'fipt' and 'socket' are allowable end types for PVC caps");
od = (ends_[0] == "socket") ? pvc_od(pvc) + (pvc_wall(pvc)/3)*2 : pvc_od(pvc);
tl = pvc_tl(pvc);
pipe_addl = 1;
wall = pvc_wall(pvc);
total_pipe_len = sum([ tl, pipe_addl, wall ]);
anchors = [
named_anchor("A", apply(down(tl/2) * up(total_pipe_len/2), CENTER), UP, 0)
];
attachable(anchor, spin, orient, d=od, h=total_pipe_len, anchors=anchors) {
up(total_pipe_len/2)
diff("pvc_rem__full")
pvc_part_component(pvc, length=pipe_addl, end=ends_[0], anchor=TOP) // A
attach(BOTTOM, TOP)
cylinder(d=od, h=wall);
children();
}
}