diff --git a/README.md b/README.md index 3e385cb2..48e1dc0b 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Some modules may depend on other modules. For example, the `polyline2d` module d - [hull_polyline3d](https://openhome.cc/eGossip/OpenSCAD/lib-hull_polyline3d.html) - [function_grapher](https://openhome.cc/eGossip/OpenSCAD/lib-function_grapher.html) - [polysections](https://openhome.cc/eGossip/OpenSCAD/lib-polysections.html) + - [path_extrude](https://openhome.cc/eGossip/OpenSCAD/lib-path_extrude.html) - Transformation - [along_with](https://openhome.cc/eGossip/OpenSCAD/lib-along_with.html) diff --git a/docs/images/lib-path_extrude-1.JPG b/docs/images/lib-path_extrude-1.JPG new file mode 100644 index 00000000..7de7cadb Binary files /dev/null and b/docs/images/lib-path_extrude-1.JPG differ diff --git a/docs/images/lib-path_extrude-2.JPG b/docs/images/lib-path_extrude-2.JPG new file mode 100644 index 00000000..ea071070 Binary files /dev/null and b/docs/images/lib-path_extrude-2.JPG differ diff --git a/docs/images/lib-path_extrude-3.JPG b/docs/images/lib-path_extrude-3.JPG new file mode 100644 index 00000000..f56f9728 Binary files /dev/null and b/docs/images/lib-path_extrude-3.JPG differ diff --git a/docs/lib-path_extrude.md b/docs/lib-path_extrude.md new file mode 100644 index 00000000..9945b8c4 --- /dev/null +++ b/docs/lib-path_extrude.md @@ -0,0 +1,127 @@ +# path_extrude + +It extrudes a 2D shape along a path. This module is suitable for a path created by a continuous function. + +It depends on the rotate_p function and the polysections module. Remember to include "rotate_p.scad" and "polysections.scad". + +When using this module, you should use points to represent the 2D shape. You need to provide indexes of triangles, too. This module provides two prepared triangles indexes. One is `"RADIAL"`. See [polysections](https://openhome.cc/eGossip/OpenSCAD/lib-polysections.html) for details. + +## Parameters + +- `shape_pts` : A list of points represent a shape. See the example below. +- `path_pts` : A list of points represent the path. +- `triangles` : `"RADIAL"` (default), `"HOLLOW"` or user-defined indexes. See example below. + +## Examples + + include ; + include ; + include ; + include ; + + t_step = 0.05; + width = 2; + + p0 = [0, 0, 0]; + p1 = [40, 60, 35]; + p2 = [-50, 70, 0]; + p3 = [20, 150, -35]; + p4 = [30, 50, -3]; + + shape_pts = [ + [10, 0, 0], + [15, 10, 0], + [18, 9, 0], + [20, 0, 0] + ]; + + path_pts = bezier_curve(t_step, + [p0, p1, p2, p3, p4] + ); + + path_extrude(shape_pts, path_pts); + +![path_extrude](images/lib-path_extrude-1.JPG) + + include ; + include ; + include ; + include ; + + t_step = 0.05; + width = 2; + + p0 = [0, 0, 0]; + p1 = [40, 60, 35]; + p2 = [-50, 70, 0]; + p3 = [20, 150, -35]; + p4 = [30, 50, -3]; + + shape_pts = [ + // outer + [10, 0, 0], + [15, 10, 0], + [18, 9, 0], + [20, 0, 0], + // inner + [12, 2, 0], + [15, 7, 0], + [17, 7, 0], + [18, 2, 0] + ]; + + path_pts = bezier_curve(t_step, + [p0, p1, p2, p3, p4] + ); + + path_extrude(shape_pts, path_pts, triangles = "HOLLOW"); + +![path_extrude](images/lib-path_extrude-2.JPG) + + include ; + include ; + include ; + include ; + + t_step = 0.05; + width = 2; + + p0 = [0, 0, 0]; + p1 = [40, 60, 35]; + p2 = [-50, 70, 0]; + p3 = [20, 150, -35]; + p4 = [30, 50, -3]; + + shape_pts = [ + // outer + [10, 0, 0], + [15, 10, 0], + [30, 0, 0], + // inner + [12, 1, 0], + [15, 8, 0], + [26, 1, 0], + ]; + + path_pts = bezier_curve(t_step, + [p0, p1, p2, p3, p4] + ); + + path_extrude( + shape_pts, + path_pts, + triangles = [ + [0, 3, 4], + [0, 4, 1], + [1, 4, 5], + [1, 5, 2], + [2, 5, 3], + [2, 3, 0] + ] + ); + +![path_extrude](images/lib-path_extrude-3.JPG) + + + + diff --git a/src/path_extrude.scad b/src/path_extrude.scad index 5e820cdc..30eaf4dc 100644 --- a/src/path_extrude.scad +++ b/src/path_extrude.scad @@ -1,8 +1,23 @@ -module path_extrude(shape_pts, points, triangles = "RADIAL") { +/** +* path_extrude.scad +* +* It extrudes a 2D shape along a path. +* This module is suitable for a path created by a continuous function. +* It depends on the rotate_p function and the polysections module. +* Remember to include "rotate_p.scad" and "polysections.scad". +* +* @copyright Justin Lin, 2017 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib-path_extrude.html +* +**/ + +module path_extrude(shape_pts, path_pts, triangles = "RADIAL") { function first_section() = let( - p1 = points[0], - p2 = points[1], + p1 = path_pts[0], + p2 = path_pts[1], dx = p2[0] - p1[0], dy = p2[1] - p1[1], dz = p2[2] - p1[2], @@ -30,12 +45,12 @@ module path_extrude(shape_pts, points, triangles = "RADIAL") { ]; - len_pts = len(points); + len_path_pts = len(path_pts); function path_extrude_inner(index) = - index == len_pts ? [] : + index == len_path_pts ? [] : concat( - [section(points[index - 1], points[index])], + [section(path_pts[index - 1], path_pts[index])], path_extrude_inner(index + 1) );