/ src / surface / sf_torus.scad
sf_torus.scad
 1  /**
 2  * sf_torus.scad
 3  *
 4  * @copyright Justin Lin, 2020
 5  * @license https://opensource.org/licenses/lgpl-3.0.html
 6  *
 7  * @see https://openhome.cc/eGossip/OpenSCAD/lib3x-sf_torus.html
 8  *
 9  **/ 
10  
11  use <_impl/_sf_square_surfaces.scad>
12  use <sf_solidify.scad>
13  use <../ptf/ptf_torus.scad>
14  
15  module sf_torus(levels, radius, thickness, depth, angle = [360, 360], twist = 0, invert = false, convexity = 1) {
16      dp = is_undef(depth) ? thickness / 2 : depth;
17      surface = _sf_square_surfaces(levels, thickness, dp, invert);
18      rows = len(levels);
19      columns = len(levels[0]);
20      size = [columns - 1, rows - 1];
21  
22      R = radius[0];
23      r = radius[1];
24  
25      offset_z = invert ? thickness : 0;
26  
27      tr1 = [R, r + offset_z];
28      tr2 = [R + thickness, r];
29  
30      sf_solidify(
31          [
32              for(row = surface[0]) 
33              [
34                  for(p = row) ptf_torus(size, p, tr1, angle, twist)
35              ]
36          ],
37          [
38              for(row = surface[1]) 
39              [
40                  for(p = row) ptf_torus(size, p, tr2, angle, twist)
41              ]
42          ],
43          convexity = convexity
44      );
45  }