diff --git a/docs/images/lib3x-rails2sections-1.JPG b/docs/images/lib3x-rails2sections-1.JPG new file mode 100644 index 00000000..bb8c1716 Binary files /dev/null and b/docs/images/lib3x-rails2sections-1.JPG differ diff --git a/docs/images/lib3x-rails2sections-2.JPG b/docs/images/lib3x-rails2sections-2.JPG new file mode 100644 index 00000000..a0a3e8c6 Binary files /dev/null and b/docs/images/lib3x-rails2sections-2.JPG differ diff --git a/docs/lib3x-rails2sections.md b/docs/lib3x-rails2sections.md new file mode 100644 index 00000000..ca9aec95 --- /dev/null +++ b/docs/lib3x-rails2sections.md @@ -0,0 +1,65 @@ +# rails2sections + +It returns all cross-sections described by rails. Combined with the `sweep` module, you can describe a more complex model. + +Rails should be indexed count-clockwisely. + +## Parameters + +- `rails` : A list of rails used to describe the surface of the model. + +## Examples + + use ; + use ; + use ; + + rails = [ + [[5, 0, 5], [15, 10, 10], [25, 20, 5]], + [[-5, 0, 5], [-15, 10, 10], [-25, 20, 5]], + [[-5, 0, -5], [-15, 10, -10], [-25, 20, -5]], + [[5, 0, -5], [15, 10, -10], [25, 20, -5]] + ]; + + sections = rails2sections(rails); + + sweep(sections); + + #for(path = rails) { + hull_polyline3d(path, 0.5); + } + +![rails2sections](images/lib3x-rails2sections-1.JPG) + + use ; + use ; + use ; + use ; + + t_step = 0.05; + + rails = [ + bezier_curve(t_step, + [[1.25, 0, 5], [5, 20, 5], [16, 20, -2], [18, 20, 10], [30, 15, 8]] + ), + bezier_curve(t_step, + [[-1.25, 0, 5], [0, 20, 5], [16, 22, -2], [18, 20, 10], [30, 25, 8]] + ), + bezier_curve(t_step, + [[-1.25, 0, -5], [0, 20, -5], [16, 20, 1], [18, 27, -3], [20, 27, -5]] + ), + bezier_curve(t_step, + [[1.25, 0, -5], [5, 20, -5], [16, 20, 1], [18, 17.5, -3], [20, 17.5, -5]] + ) + ]; + + + sections = rails2sections(rails); + + sweep(sections); + + #for(path = rails) { + hull_polyline3d(path, 0.5); + } + +![rails2sections](images/lib3x-rails2sections-2.JPG) diff --git a/src/rails2sections.scad b/src/rails2sections.scad new file mode 100644 index 00000000..67009c9b --- /dev/null +++ b/src/rails2sections.scad @@ -0,0 +1,22 @@ +/** +* rails2sections.scad +* +* @copyright Justin Lin, 2021 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-rails2sections.html +* +**/ + +function rails2sections(rails) = + let( + leng_rail = len(rails[0]), + leng_rails = len(rails) + ) + [ + for(i = 0; i < leng_rail; i = i + 1) + [ + for(j = 0; j < leng_rails; j = j + 1) + rails[j][i] + ] + ]; \ No newline at end of file