/ examples / triangle_splice.scad
triangle_splice.scad
 1  use <polyline2d.scad>
 2  
 3  tri_side_leng = 20;
 4  tris_per_line = 10;
 5  lines = 3;
 6  line_width = 1;
 7  
 8  points = [[10, -6], [-6.5, -6], [-3, 0], [0, 0]];
 9  // points = [[0, 0], [1.5, 2.5], [1.5, -6], [-4, -6], [-6.5, 0]];
10  triangle_splice(tri_side_leng, tris_per_line, lines, line_width) 
11      triangle_pattern(points, line_width);
12  
13  
14  module triangle_pattern(points, line_width) {
15      polyline2d(points, line_width);
16      rotate([0, 0, 120]) polyline2d(points, line_width);
17      rotate([0, 0, 240]) polyline2d(points, line_width);
18  }
19  
20  module triangle_splice_one_line(tri_leng, tris, line_width) {
21      half_leng = tri_leng / 2;
22      height = half_leng * sqrt(3);
23      hd3 = height / 3;
24      
25      for(i = [0 : tris - 1]) {
26          x_offset = half_leng * i;
27          is_even = i % 2 == 0;
28          translate([x_offset, is_even ? 0 : hd3, 0]) 
29          mirror([0, is_even ? 0 : 1, 0])
30              children();    
31      }
32  
33  }
34  
35  module triangle_splice(length, tris_per_line, lines, line_width = 1) {
36      half_leng = length / 2;
37      height = half_leng * sqrt(3);
38      hd3 = height / 3;
39      
40      for(i = [0 : lines - 1]) {
41          is_even = i % 2 == 0;
42          hoffset = height * i;
43          translate([0, is_even ? hoffset : hoffset + hd3]) 
44          mirror([0, is_even ? 0 : 1, 0])
45          triangle_splice_one_line(length, tris_per_line, line_width) 
46              children();
47      }
48  }