/ examples / wormhole.scad
wormhole.scad
 1  use <polyline_join.scad>
 2  
 3  length = 100;
 4  width = 50;
 5  depth = 40;
 6  thickness = 3;
 7  hole_r = 8;
 8  
 9  $fn = 24;
10  
11  wormhole(length, width, depth, thickness, hole_r);
12  
13  module wormhole(length, width, depth, thickness, hole_r) {
14      a_step = 360 / $fn;
15      r1 = depth / 2;
16      r2 = width / 4;
17      half_thickness = thickness / 2;
18  
19      plane = [
20          [length - r1, r1], 
21          each [for(a = [90:a_step:270]) r1 * [cos(a), sin(a)]], 
22          [length - r1, -r1]
23      ];
24  
25      difference() {
26          rotate([90, 0, 0])
27          linear_extrude(width, center = true)
28          polyline_join(plane)
29                  square(thickness, center = true);
30              
31          translate([(length - r1) / 2, 0])
32          linear_extrude(depth + thickness * 2, center = true)
33              circle(r2 + hole_r);
34      }
35  
36  
37      hole_profile = concat(
38          [for(a = [90:a_step:180]) r2 * [cos(a), sin(a)]], 
39          [[-r2, -(r1 - r2) + half_thickness]]
40      );
41      
42      module hole() {
43          translate([(length - r1) / 2, 0, r1 - r2])
44          rotate_extrude()
45          translate([r2 + half_thickness + hole_r, 0])
46          polyline_join(hole_profile)
47              square(thickness, center = true);
48      }
49  
50      hole();
51  
52      mirror([0, 0, 1])
53          hole() ;
54  }