diff --git a/README.md b/README.md index 0dfd0e90..3e385cb2 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Some modules may depend on other modules. For example, the `polyline2d` module d - [polyline3d](https://openhome.cc/eGossip/OpenSCAD/lib-polyline3d.html) - [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) - Transformation - [along_with](https://openhome.cc/eGossip/OpenSCAD/lib-along_with.html) diff --git a/docs/images/lib-polysections-1.JPG b/docs/images/lib-polysections-1.JPG new file mode 100644 index 00000000..05408847 Binary files /dev/null and b/docs/images/lib-polysections-1.JPG differ diff --git a/docs/images/lib-polysections-2.JPG b/docs/images/lib-polysections-2.JPG new file mode 100644 index 00000000..784c00be Binary files /dev/null and b/docs/images/lib-polysections-2.JPG differ diff --git a/docs/images/lib-polysections-3.JPG b/docs/images/lib-polysections-3.JPG new file mode 100644 index 00000000..41373606 Binary files /dev/null and b/docs/images/lib-polysections-3.JPG differ diff --git a/docs/images/lib-polysections-4.JPG b/docs/images/lib-polysections-4.JPG new file mode 100644 index 00000000..f2b0125a Binary files /dev/null and b/docs/images/lib-polysections-4.JPG differ diff --git a/docs/images/lib-polysections-5.JPG b/docs/images/lib-polysections-5.JPG new file mode 100644 index 00000000..8d6e176e Binary files /dev/null and b/docs/images/lib-polysections-5.JPG differ diff --git a/docs/images/lib-polysections-6.JPG b/docs/images/lib-polysections-6.JPG new file mode 100644 index 00000000..8e5eb917 Binary files /dev/null and b/docs/images/lib-polysections-6.JPG differ diff --git a/docs/images/lib-polysections-7.JPG b/docs/images/lib-polysections-7.JPG new file mode 100644 index 00000000..7c07bd52 Binary files /dev/null and b/docs/images/lib-polysections-7.JPG differ diff --git a/docs/images/lib-polysections-8.JPG b/docs/images/lib-polysections-8.JPG new file mode 100644 index 00000000..c9758160 Binary files /dev/null and b/docs/images/lib-polysections-8.JPG differ diff --git a/docs/images/lib-polysections-9.JPG b/docs/images/lib-polysections-9.JPG new file mode 100644 index 00000000..5e0e1037 Binary files /dev/null and b/docs/images/lib-polysections-9.JPG differ diff --git a/docs/lib-polysections.md b/docs/lib-polysections.md new file mode 100644 index 00000000..b40502f8 --- /dev/null +++ b/docs/lib-polysections.md @@ -0,0 +1,145 @@ +# polysections + +Crosscutting a tube-like shape at different points gets several cross-sections. This module can operate reversely. It uses cross-sections to construct a tube-like shape. For example, imagine that you have the following cross-sections: + +![polysections](images/lib-polysections-1.JPG) + +This module can use them to construct the following model: + +![polysections](images/lib-polysections-2.JPG) + +Looks like extruding along the path? Yes, it can perform the task; however, it's more flexible. + +You can also view it as a better polyline3d module if you want. If you have only the points of a path, using `polyline3d` or `hull_polyline3d` is a simple solution. If you know the cross-sections along a path, you can use `polysections` to do more. + +When using this module, you should use points to represent each cross-section. You need to provide indexes of triangles, too. This module provides two prepared triangles indexes. One is `"RADIAL"`. For example, if you have a cross-section such as: + +![polysections](images/lib-polysections-3.JPG) + +When using `"RADIAL"` (default), the module will cut them into triangles from the first point to each remaining point: + +![polysections](images/lib-polysections-4.JPG) + +If your cross-sections are hollow, you may use `"HOLLOW"`. For example: + +![polysections](images/lib-polysections-5.JPG) + +When using `"HOLLOW"`, the above shape will be cut into triangles such as: + +![polysections](images/lib-polysections-6.JPG) + +You can cut triangles by yourself, for example, the indexes of the above triangles is: + + [ + [0, 3, 4], + [0, 4, 1], + [1, 4, 5], + [1, 5, 2], + [2, 5, 3], + [2, 3, 0] + ] + +Triangles may be defined in any order. + +## Parameters + +- `sections` : A list of cross-sections. Each cross-section is represented by a list of points. See the example below. +- `triangles` : `"RADIAL"` (default), `"HOLLOW"` or user-defined indexes. See example below. + +## Examples + + include ; + include ; + + section1 = [ + [10, 0, 0], + [15, 10, 0], + [18, 9, 0], + [20, 0, 0] + ]; + + // spin section1 + sections = [ + for(i = [0:55]) + [ + for(p = section1) + let(pt = rotate_p(p, [90, 0, -10 * i])) + [pt[0], pt[1] , pt[2] + i] + ] + ]; + + polysections(sections); + +![polysections](images/lib-polysections-7.JPG) + + include ; + include ; + + section1 = [ + // 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] + ]; + + // spin section1 + sections = [ + for(i = [0:55]) + [ + for(p = section1) + let(pt = rotate_p(p, [90, 0, -10 * i])) + [pt[0], pt[1] , pt[2] + i] + ] + ]; + + polysections(sections, "HOLLOW"); + +![polysections](images/lib-polysections-8.JPG) + + include ; + include ; + + section1 = [ + // outer + [10, 0, 0], + [15, 10, 0], + [30, 0, 0], + // inner + [12, 1, 0], + [15, 8, 0], + [26, 1, 0], + ]; + + // spin section1 + sections = [ + for(i = [0:55]) + [ + for(p = section1) + let(pt = rotate_p(p, [90, 0, -10 * i])) + [pt[0], pt[1] , pt[2] + i] + ] + ]; + + polysections( + sections = sections, + triangles = [ + [0, 3, 4], + [0, 4, 1], + [1, 4, 5], + [1, 5, 2], + [2, 5, 3], + [2, 3, 0] + ] + ); + +![polysections](images/lib-polysections-9.JPG) + + + + diff --git a/src/polysections.scad b/src/polysections.scad index c55d0dc9..72043133 100644 --- a/src/polysections.scad +++ b/src/polysections.scad @@ -1,3 +1,16 @@ +/** +* polysections.scad +* +* Crosscutting a tube-like shape at different points gets several cross-sections. +* This module can operate reversely. It uses cross-sections to construct a tube-like shape. +* +* @copyright Justin Lin, 2017 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib-polysections.html +* +**/ + module polysections(sections, triangles = "RADIAL") { module tri_sections(tri1, tri2) { polyhedron( @@ -40,6 +53,7 @@ module polysections(sections, triangles = "RADIAL") { module two_sections(section1, section2) { for(idx = tris()) { + // hull is for preventing from WARNING: Object may not be a valid 2-manifold hull() tri_sections( [ section1[idx[0]],