From d80b0cee3d83b0e26988acb9f8ef3245657db0d0 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Thu, 4 May 2017 13:47:42 +0800 Subject: [PATCH] added helix_extrude.scad --- src/helix_extrude.scad | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/helix_extrude.scad diff --git a/src/helix_extrude.scad b/src/helix_extrude.scad new file mode 100644 index 00000000..ca4f9ffa --- /dev/null +++ b/src/helix_extrude.scad @@ -0,0 +1,38 @@ +/** +* helix_extrude.scad +* +* Extrudes a 2D shape along a helix path. +* +* @copyright Justin Lin, 2017 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib-helix_extrude.html +* +**/ + +module helix_extrude(shape_pts, radius, levels, level_dist, vt_dir = "SPI_UP", rt_dir = "CT_CLK", twist = 0, scale = 1.0, triangles = "RADIAL") { + frags = $fn > 0 ? + ($fn >= 3 ? $fn : 3) : + max(min(360 / $fa, radius * 6.28318 / $fs), 5); + + v_dir = vt_dir == "SPI_UP" ? 1 : -1; + r_dir = rt_dir == "CT_CLK" ? 1 : -1; + + angle_step = 360 / frags * r_dir; + initial_angle = atan2(level_dist / frags, 6.28318 * radius / frags) * v_dir * r_dir; + + path_points = helix( + radius = radius, + levels = levels, + level_dist = level_dist, + vt_dir = vt_dir, + rt_dir = rt_dir + ); + + angles = [for(i = [0:len(path_points) - 1]) [90 + initial_angle, 0, angle_step * i]]; + + polysections( + cross_sections(shape_pts, path_points, angles, twist, scale), + triangles = triangles + ); +} \ No newline at end of file