/ src / ptf / ptf_torus.scad
ptf_torus.scad
 1  /**
 2  * ptf_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-ptf_torus.html
 8  *
 9  **/ 
10  
11  use <ptf_rotate.scad>
12  
13  function ptf_torus(size, point, radius, angle = [360, 360], twist = 0) =
14      let(
15          R = radius[0],
16          r = radius[1] + (is_undef(point.z) ? 0 : point.z),
17          A = angle[0],
18          a = angle[1],
19          ya = 180 - point.x * a / size.x + twist / size.y * point.y
20      ) 
21      ptf_rotate(
22          [r * cos(ya) + R + r, 0, r * sin(ya)], 
23          A / size.y * point.y
24      );