-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnodes_graph.scad
984 lines (820 loc) · 21.6 KB
/
nodes_graph.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
/* Nodes and Graph (derivative of nodes_edges.scad), lots of ways to use this big but
* useful mess:
*
* Circular Rays - Partial circle with rays extending from the center to the periphery.
* If RingCount is > 1, some inner rings are skipped to allow creation
* of hollow circles or semi-circles.
*
* Grid Rays - A rectangle of nodes, with diagonal, vertical, horizontal edges or
* some combo.
*
* Fringe - A rectangle with triangles hanging down.
*
* Hexagon - Hexagon with interior goodness.
*
* This code is powerful yet messy. TODO:
*
* --> Fix Fringe to have proper args
*
* --> Implement separate triangle pattern
*
* --> Move more parameters to "_" and never use them in modules
*
* --> Render edges that overlap (mostly in Axial) together so that the
* pattern on top looks better.
*/
// Pattern
_Pattern = "Circular"; // [Circular, Grid, Fringe, Hexagon]
// Node radius
_NodeSize = 7.5;
// Node shape (0 for circle, , 4 for square, 6 for hexagon)
_NodeShape = 0; // [0, 4, 6]
// Node magnet holes
_NodeMagnetHole = "None"; // [None, 2.7 mm, 4.7 mm, 12 mm]
// Node height
_NodeHeight = 3;
// Percentage of full length for edges
EdgeLengthFactor = 1.0;
// Minimum length to bother creating an edge
EdgeMinLength = 5;
// Rim thickness
RimThickness = 0.5;
// Node rim height
NodeRimHeight = 3.4;
// Edge rim height
EdgeRimHeight = 3.4;
// Edge height
EdgeHeight = 3.0;
// Edge width
EdgeWidth = 5.0;
/* ************************************************************** */
/* [Circular Rays] */
// Draw ring center
_CircRayCenter = true;
// Angular step between rays
_CircRayStep = 45;
// Degrees of rays
_CircRayLimit = 360;
// First ring
_CircStartRing = 1;
// Ring count
_CircRingCount = 5;
// Ring spacing
_CircRingSpace = 20;
// Inside quads
_CircInsideQuads = true;
// Quad Inset
_CircQuadInset = 7;
// Half-nodes at start and end
_CircHalfNodes = false;
// Half-edges at start and end
_CircHalfEdges = false;
/* ************************************************************** */
/* [Grid Rays] */
// Number of rows
_GridRows = 4;
// Number of columns
_GridCols = 8;
// Step between rows
_GridRowStep = 30;
// Step between columns
_GridColStep = 50;
// Options for interior edges:
// Forward diagonal
// Backward diagonal
// X-aligned
// Y-aligned
// Forward diagonal edges
_GridFwdDiagonalEdges = false;
// Backward diagonal edges
_GridBwdDiagonalEdges = false;
// X edges
_GridXEdges = true;
// Y edges
_GridYEdges = true;
// Half nodes, first row
_GridHalfNodesFirst = false;
// Half nodes, last row
_GridHalfNodesLast = false;
// Half edges, first row
_GridHalfEdgesFirst = false;
// Half edges, last row
_GridHalfEdgesLast = false;
/* ************************************************************** */
/* [Fringe] */
// Number of vertical columns (must be even)
_FringeCols = 8;
// Rows in top of fringe
_FringeRows = 2;
// Width of each column
_FringeColSpace = 30;
// Height of each triangular fringe
_FringeTriangeHeight = 120;
/* ************************************************************** */
/* [Hexagon] */
// Base width
_HexBaseWidth = 100;
// Inside triangles
_HexInsideTriangles = true;
// Triangle inset
_HexTriangleInset = 7;
/* ************************************************************** */
/* End of customization */
module __Customizer_Limit__ () {}
//
// Map all of the possible values for _NodeMagnetHole into a diameter and a height:
//
function MagnetDiameter(MagnetHole) =
(MagnetHole == "None") ? 0 :
(MagnetHole == "2.7 mm") ? 2.7 :
(MagnetHole == "4.7 mm") ? 4.7 :
(MagnetHole == "12 mm") ? 12 :
0;
function MagnetHeight(MagnetHole) =
(MagnetHole == "None") ? 0 :
(MagnetHole == "2.7 mm") ? 2 :
(MagnetHole == "4.7 mm") ? 2 :
(MagnetHole == "12 mm") ? 2.4 :
0;
//
// Hole:
//
// Render a magnet hole.
//
module Hole(MagnetHole)
{
Diameter = MagnetDiameter(MagnetHole);
Height = MagnetHeight(MagnetHole);
if (Diameter != 0)
{
FullDiameter = 1.1 * Diameter; // Add some wiggle room
linear_extrude(Height)
{
circle(FullDiameter);
}
}
}
//
// NodeGuts:
//
// Render the elements that make up a node.
//
module NodeGuts(NodeShape, Radius, Height, RimHeight)
{
union()
{
/* Node */
linear_extrude(Height)
{
circle(Radius, $fn=NodeShape);
}
/* Rim */
for (dd = [0 : 1.5 : 3])
{
linear_extrude(RimHeight)
{
difference()
{
circle(Radius - dd, $fn=NodeShape);
offset(delta=-RimThickness)
{
circle(Radius - dd, $fn=NodeShape);
}
}
}
}
}
}
//
// Node:
//
// Render a node, with a rim and optional hole for magnet.
//
// PlusX must be true to render the part of the node at X > 0
// MinuxX must be true to render the part of the node at X < 0
//
module Node(NodeShape, Radius, Height, RimHeight, MagnetHole, PlusX=true, MinusX=true)
{
// Node rotation
NodeRotation = (_NodeShape == 0) ? 0 : /* Circle */
(_NodeShape == 4) ? 45 : /* Square */
(_NodeShape == 6) ? 30 : /* Hexagon */
0;
difference()
{
/* Matter */
rotate([0, 0, NodeRotation])
{
NodeGuts(NodeShape, Radius, Height, RimHeight);
}
/* Antimatter magnet hole */
translate([0, 0, 0.4])
{
Hole(MagnetHole);
}
/* Optionally remove +Y half */
if (!PlusX)
{
translate([-Radius, 0, 0])
{
cube([2 * Radius, Radius, Height + RimHeight]);
}
}
/* Optionally remove -Y half */
if (!MinusX)
{
translate([-Radius, -Radius, 0])
{
cube([2 * Radius, Radius, Height + RimHeight]);
}
}
}
}
//
// EdgeElement:
//
// Render the element that makes up the edge.
//
module EdgeElement(Length, Width)
{
square([Length, Width], center=true);
}
//
// Edge:
//
// Render an edge, with a rim, as long as edge is at least EdgeMinLength long.
//
module Edge(Length, Width, Height, RimHeight, PlusX, MinusX)
{
if (Length >= EdgeMinLength)
{
difference()
{
/* Matter */
union()
{
/* Edge */
{
linear_extrude(Height)
{
EdgeElement(Length, Width);
}
}
/* Rim */
for (dd = [0 : 1.6 : 3.2])
{
linear_extrude(RimHeight)
{
difference()
{
EdgeElement(Length - dd, Width - dd);
offset(delta=-RimThickness)
{
EdgeElement(Length - dd, Width - dd);
}
}
}
}
}
/* Antimatter */
/* Optionally remove +X half */
if (!PlusX)
{
translate([-Length / 2, 0, 0])
{
cube([Length, Width / 2, RimHeight]);
}
}
/* Optionally remove -X half */
if (!MinusX)
{
translate([-Length / 2, -Width / 2, 0])
{
cube([Length, Width / 2, RimHeight]);
}
}
}
}
}
//
// ConnectNodesWithEdge:
//
// Connect two nodes using an edge.
//
module ConnectNodesWithEdge(FromX, FromY, ToX, ToY, EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize, PlusX=true, MinusX=true)
{
// Compute angle for edge
DeltaX = (ToX - FromX);
DeltaY = (ToY - FromY);
Theta = atan2(DeltaY, DeltaX);
// Compute edge length, base then adjust for node side
BaseEdgeLength = sqrt((DeltaX * DeltaX) + (DeltaY * DeltaY));
EdgeLength = (BaseEdgeLength - (2.5 * NodeSize)) * EdgeLengthFactor;
// Compute center of edge
EdgeCenterX = FromX + (DeltaX / 2);
EdgeCenterY = FromY + (DeltaY / 2);
// Render edge
translate([EdgeCenterX, EdgeCenterY, 0])
{
rotate([0, 0, Theta])
{
Edge(EdgeLength, EdgeWidth, EdgeHeight, EdgeRimHeight, PlusX, MinusX);
}
}
}
//
// TriangleElement:
//
// Render the element that makes up the triangle.
//
module TriangleElement(Points)
{
polygon(Points);
}
//
// Triangle:
//
// Triangle inset from the given points, styled like an edge.
//
module Triangle(X0, Y0, X1, Y1, X2, Y2, Inset, Height, RimHeight)
{
TrianglePoints =
[
[X0, Y0],
[X1, Y1],
[X2, Y2]
];
union()
{
/* Triangle */
linear_extrude(Height)
{
offset(-Inset)
{
TriangleElement(TrianglePoints);
}
}
/* Rim */
for (dd = [0 : 1.5 : 3])
{
linear_extrude(RimHeight)
{
difference()
{
offset(delta= (-Inset - dd))
{
TriangleElement(TrianglePoints);
}
offset(delta= (-Inset - dd - RimThickness))
{
TriangleElement(TrianglePoints);
}
}
}
}
}
}
//
// QuadElement:
//
// Render the element that makes up the quadrilateral.
//
module QuadElement(Points)
{
polygon(Points);
}
//
// Quad:
//
// Quadrilateral inset from the given points, styled like an edge.
//
module Quad(X0, Y0, X1, Y1, X2, Y2, X3, Y3, Inset, Height, RimHeight)
{
QuadPoints =
[
[X0, Y0],
[X1, Y1],
[X2, Y2],
[X3, Y3],
];
union()
{
/* Quad */
linear_extrude(Height)
{
offset(-Inset)
{
QuadElement(QuadPoints);
}
}
/* Rim */
for (dd = [0 : 1.5 : 3])
{
linear_extrude(RimHeight)
{
difference()
{
offset(delta= (-Inset - dd))
{
QuadElement(QuadPoints);
}
offset(delta= (-Inset - dd - RimThickness))
{
QuadElement(QuadPoints);
}
}
}
}
}
}
//
// CircularRays:
//
// Partial or full circle, with optional node at the center, then rings of nodes,
// connected radially and cicularly, with optional quadrilaterals between nodes.
//
// If HalfNodes or HalfEdges is set, then the first and last nodes or edges in the ring
// are PlusX/MinusX half only. This makes it easier to print a pair of semi-circular rings that
// can be joined with straight pieces.
//
// TODO: Add parameters
//
module CircularRays(StartRing, RingCount, RingSpace, Step, Limit, Center, InsideQuads, QuadInset, NodeShape, NodeSize, NodeHeight, NodeMagnetHole, HalfNodes, HalfEdges)
{
if (Center)
{
// Render center node
Node(NodeShape, NodeSize, NodeHeight, NodeRimHeight, NodeMagnetHole);
}
// Concentric rings of nodes
for (Theta = [0 : Step : Limit])
{
for (Ring = [StartRing : RingCount])
{
RingX = cos(Theta) * Ring * RingSpace;
RingY = sin(Theta) * Ring * RingSpace;
translate([RingX, RingY, 0])
{
MinusXHalf =
(!HalfNodes)
||
(HalfNodes && (Theta > 0) && (Theta < Limit));
Node(NodeShape, NodeSize, NodeHeight, NodeRimHeight, NodeMagnetHole, true, MinusXHalf);
}
}
}
if (Center)
{
// Radial edges from center to first ring
for (Theta = [0 : Step : Limit])
{
RingX = cos(Theta) * RingSpace;
RingY = sin(Theta) * RingSpace;
ConnectNodesWithEdge(0, 0, RingX, RingY, EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
}
}
// Radial edges from subsequent rings outward
for (Theta = [0 : Step : Limit])
{
for (Ring = [StartRing : RingCount - 1])
{
RingFromX = cos(Theta) * Ring * RingSpace;
RingFromY = sin(Theta) * Ring * RingSpace;
RingToX = cos(Theta) * (Ring + 1) * RingSpace;
RingToY = sin(Theta) * (Ring + 1) * RingSpace;
//
// Hacky, special-cased (half-circle only) hiding of half-edges (PluX or MinusX):
//
// 1. Hide MinusXHalf if HalfEdges set and Theta is 0
//
// 2. Hide PlusXHalf if HalfEdges set and Theta is 180
//
ShowMinusXHalf = (Theta != 0 && HalfEdges) || !HalfEdges;
ShowPlusXHalf = (Theta != 180 && HalfEdges) || !HalfEdges;
ConnectNodesWithEdge(RingFromX, RingFromY, RingToX, RingToY, EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize, ShowPlusXHalf, ShowMinusXHalf);
}
}
// Circular edges within a ring
for (Ring = [StartRing : RingCount])
{
for (Theta = [0 : Step : Limit - 1])
{
RingFromX = cos(Theta) * Ring * RingSpace;
RingFromY = sin(Theta) * Ring * RingSpace;
RingToX = cos(Theta + Step) * Ring * RingSpace;
RingToY = sin(Theta + Step) * Ring * RingSpace;
ConnectNodesWithEdge(RingFromX, RingFromY, RingToX, RingToY, EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
}
}
if (InsideQuads)
{
// Quadrilaterals between nodes
for (Theta1 = [0 : Step : Limit - 1])
{
for (Ring = [StartRing : RingCount - 1])
{
Theta2 = (Theta1 + Step) % 360;
RingX0 = cos(Theta1) * (Ring + 1) * RingSpace;
RingY0 = sin(Theta1) * (Ring + 1) * RingSpace;
RingX1 = cos(Theta2) * (Ring + 1) * RingSpace;
RingY1 = sin(Theta2) * (Ring + 1) * RingSpace;
RingX2 = cos(Theta2) * Ring * RingSpace;
RingY2 = sin(Theta2) * Ring * RingSpace;
RingX3 = cos(Theta1) * Ring * RingSpace;
RingY3 = sin(Theta1) * Ring * RingSpace;
Quad(RingX0, RingY0, RingX1, RingY1, RingX2, RingY2, RingX3, RingY3, QuadInset, EdgeHeight, EdgeRimHeight);
}
}
}
}
//
// GridRays:
//
// Grid of nodes, connected on the axes and optional:
//
// FwdDiagonalEdges
// BwdDiagonalEdges
// XEdges
// YEdges
//
// Optional half edges and half nodes, for first and last row.
//
function GridPointX(i, ColStep) = i * ColStep;
function GridPointY(i, RowStep) = i * RowStep;
module GridRays(Rows, Cols, RowStep, ColStep, NodeShape, NodeSize, NodeHeight, NodeMagnetHole, FwdDiagonalEdges, BwdDiagonalEdges, XEdges, YEdges, HalfNodesFirst, HalfNodesLast, HalfEdgesFirst, HalfEdgesLast)
{
// Render grid of nodes
for (x = [0 : Cols - 1])
{
for (y = [0 : Rows - 1])
{
translate([GridPointX(x, ColStep), GridPointY(y, RowStep), 0])
{
MinusX = (y != 0) || (y == 0 && !HalfNodesFirst);
PlusX = (y != (Rows - 1)) || (y == (Rows - 1) && !HalfNodesLast);
Node(NodeShape, NodeSize, NodeHeight, NodeRimHeight, NodeMagnetHole, PlusX, MinusX);
}
}
}
// Render edges along X axis
if (XEdges)
{
for (x = [0 : Cols - 2])
{
for (y = [0 : Rows - 1])
{
MinusX = (y != 0) || (y == 0 && !HalfEdgesFirst);
PlusX = (y != (Rows - 1)) || (y == (Rows - 1) && !HalfEdgesLast);
ConnectNodesWithEdge(GridPointX(x, ColStep), GridPointY(y, RowStep), GridPointX(x + 1, ColStep), GridPointY(y, RowStep),
EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize, PlusX, MinusX);
}
}
}
// Render edges along Y axis
if (YEdges)
{
for (y = [0 : Rows - 2])
{
for (x = [0 : Cols - 1])
{
ConnectNodesWithEdge(GridPointX(x, ColStep), GridPointY(y, RowStep), GridPointX(x, ColStep), GridPointY(y + 1, RowStep),
EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
}
}
}
// Render forward diagonal edges
if (FwdDiagonalEdges)
{
for (x = [0 : Cols - 2])
{
for (y = [0 : Rows - 2])
{
ConnectNodesWithEdge(GridPointX(x, ColStep), GridPointY(y, RowStep), GridPointX(x + 1, ColStep), GridPointY(y + 1, RowStep),
EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
}
}
}
// Render backward diagonal edges
if (BwdDiagonalEdges)
{
for (x = [1 : Cols - 1])
{
for (y = [0 : Rows - 2])
{
ConnectNodesWithEdge(GridPointX(x, ColStep), GridPointY(y, RowStep), GridPointX(x - 1, ColStep), GridPointY(y + 1, RowStep),
EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
}
}
}
}
//
// Fringe:
//
// A horizontal grid (FringeCols x FringeRows, then triangles of FringeTriangleHeight dropping down.
// TODO - Fix to add ColSpace and RowSpace properly.
//
module Fringe(FringeCols, FringeRows, FringeColSpace, FringeTriangleHeight, NodeShape, NodeSize, NodeHeight, NodeRimHeight, NodeMagnetHole)
{
// Render grid of nodes for top
for (y = [0 : FringeRows - 1])
{
for (x = [0 : FringeCols - 1])
{
translate([GridPointX(x), GridPointY(y), 0])
{
Node(NodeShape, NodeSize, NodeHeight, NodeRimHeight, NodeMagnetHole);
}
}
}
// Render edges along top & bottom X axis
for (i = [0 : FringeCols - 2])
{
ConnectNodesWithEdge(GridPointX(i), GridPointY(0), GridPointX(i + 1), GridPointY(0),
EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
ConnectNodesWithEdge(GridPointX(i), GridPointY(FringeRows - 1),GridPointX(i + 1), GridPointY(FringeRows - 1),
EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
}
// Render edges along Y axis
for (i = [0 : FringeRows - 2])
{
for (j = [0 : FringeCols - 1])
{
ConnectNodesWithEdge(GridPointX(j), GridPointY(i), GridPointX(j), GridPointY(i + 1),
EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
}
}
TriangleCount = FringeCols / 2;
// Render triangles - apex and edges to the apex
for (t = [0 : TriangleCount - 1])
{
TriangleNodeIndex = t * 2;
// Triangle points
T0X = GridPointX(TriangleNodeIndex);
T0Y = GridPointY(FringeRows - 1);
T1X = GridPointX(TriangleNodeIndex + 1);
T1Y = GridPointY(FringeRows - 1);
T2X = T0X + (FringeColSpace / 2);
T2Y = T1Y + FringeTriangleHeight;
translate([T2X, T2Y, 0])
{
Node(NodeShape, NodeSize, NodeHeight, NodeRimHeight);
}
ConnectNodesWithEdge(T0X, T0Y, T2X, T2Y, EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
ConnectNodesWithEdge(T1X, T1Y, T2X, T2Y, EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
}
}
//
// Hexagon:
//
// Hexagon with interior goodies, with middle split on exterior edges, and optional
// interior triangle panels.
//
// Consult https://github.com/jeffbarr/OpenSCADObjects/blob/main/nodes_graph_hexagon_node_ids.jpg
// to see how X/Y, XX/YY, XXX/YYY, XI/YI, and NX/NY map to node coordinates.
//
module Hexagon(BaseWidth, InsideTriangles, TriangleInset, NodeShape, NodeSize, NodeHeight, NodeMagnetHole)
{
// Compute coordinates of each exterior node
X = [for (d = [0 : 60 : 359]) BaseWidth * cos(d)];
Y = [for (d = [0 : 60 : 359]) BaseWidth * sin(d)];
// Compute coordinates for mid-points of each exterior node
XX = [for (i = [0 : 5]) (X[i] + X[(i + 1) % 6]) / 2];
YY = [for (i = [0 : 5]) (Y[i] + Y[(i + 1) % 6]) / 2];
// Merge so that XXX and YYY are coordinates of all exterior nodes
XXX =
[
X[0], XX[0],
X[1], XX[1],
X[2], XX[2],
X[3], XX[3],
X[4], XX[4],
X[5], XX[5]
];
YYY =
[
Y[0], YY[0],
Y[1], YY[1],
Y[2], YY[2],
Y[3], YY[3],
Y[4], YY[4],
Y[5], YY[5]
];
// Compute coordinates for 4 interior nodes
XI =
[
X[1],
0,
X[2],
0
];
YI =
[
0,
Y[1] / 2,
0,
-Y[1] / 2
];
// Put all coordinates together, indices are "fixed" per the diagram
NX =
[
0,
XXX[0], XXX[1], XXX[2], XXX[3], XXX[4], XXX[5],
XXX[6], XXX[7], XXX[8], XXX[9], XXX[10], XXX[11],
XI[0], XI[1], XI[2], XI[3]
];
NY =
[
0,
YYY[0], YYY[1], YYY[2], YYY[3], YYY[4], YYY[5],
YYY[6], YYY[7], YYY[8], YYY[9], YYY[10], YYY[11],
YI[0], YI[1], YI[2], YI[3]
];
// Build list of nodes to render
Nodes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
// Build list of edges to render, as node indexes
Edges =
[
// Connect exterior nodes
[1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 1],
// Connect center node to interior nodes
[0, 13], [0, 14], [0, 15], [0, 16],
// Connect interior nodes to exterior nodes on X axis
[1, 13], [7, 15],
// Connect interior nodes to exterior nodes on Y axis
[4, 14], [10, 16],
// Connect interior nodes to each other
[13, 14], [14, 15], [15, 16], [16, 13],
// Connect interior nodes to top and bottom diagonals
[2, 13], [6, 15], [8, 15], [12, 13],
// Connect corner interior nodes to X axis
[3, 13], [5, 15], [9, 15], [11, 13],
// Connect corner interior nodes to Y axis
[3, 14], [5, 14], [9, 16], [11, 16]
];
// Render nodes
for (n = Nodes)
{
translate([NX[n], NY[n], 0])
{
Node(NodeShape, NodeSize, NodeHeight, NodeRimHeight, NodeMagnetHole);
}
}
// Render edges
for (e = Edges)
{
ConnectNodesWithEdge(NX[e[0]], NY[e[0]], NX[e[1]], NY[e[1]], EdgeWidth, EdgeHeight, EdgeRimHeight, NodeSize);
}
if (InsideTriangles)
{
// Build list of triangles as node indices
Triangles =
[
[0, 13, 14],
[0, 14, 15],
[0, 15, 16],
[0, 13, 16],
[1, 2, 13],
[1, 12, 13],
[2, 3, 13],
[3, 4, 14],
[3, 13, 14],
[4, 5, 14],
[5, 6, 15],
[5, 14, 15],
[6, 7, 15],
[7, 8, 15],
[8, 9, 15],
[9, 10, 16],
[9, 15, 16],
[10, 11, 16],
[11, 12, 13],
[11, 13, 16]
];
// Render triangles
for (t = Triangles)
{
Triangle(NX[t[0]], NY[t[0]], NX[t[1]], NY[t[1]], NX[t[2]], NY[t[2]], TriangleInset, EdgeHeight, EdgeRimHeight);
}
}
}
/* Render chosen pattern */
if (_Pattern == "Circular")
{
CircularRays(_CircStartRing,_CircRingCount, _CircRingSpace, _CircRayStep, _CircRayLimit, _CircRayCenter, _CircInsideQuads, _CircQuadInset, _NodeShape, _NodeSize, _NodeHeight, _NodeMagnetHole, _CircHalfNodes, _CircHalfEdges);
}
else if (_Pattern == "Grid")
{
GridRays(_GridRows, _GridCols, _GridRowStep, _GridColStep, _NodeShape, _NodeSize, _NodeHeight, _NodeMagnetHole, _GridFwdDiagonalEdges, _GridBwdDiagonalEdges, _GridXEdges, _GridYEdges, _GridHalfNodesFirst, _GridHalfNodesLast, _GridHalfEdgesFirst, _GridHalfEdgesLast);
}
else if (_Pattern == "Fringe")
{
Fringe(_FringeCols, _FringeRows, _FringeColSpace, _FringeTriangeHeight, _NodeShape, _NodeSize, _NodeHeight, NodeRimHeight, _NodeMagnetHole);
}
else if (_Pattern == "Hexagon")
{
Hexagon(_HexBaseWidth, _HexInsideTriangles, _HexTriangleInset, _NodeShape, _NodeSize, _NodeHeight, _NodeMagnetHole);
}
else
{
echo("Unknown pattern ", _Pattern);
}