diff --git a/README.md b/README.md index f26a068c..42ff18c6 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I ## Documentation - 2D - - [pie](https://openhome.cc/eGossip/OpenSCAD/lib-pie.html) - - [arc](https://openhome.cc/eGossip/OpenSCAD/lib-arc.html) + - [arc](https://openhome.cc/eGossip/OpenSCAD/lib-arc.html) + - [pie](https://openhome.cc/eGossip/OpenSCAD/lib-pie.html) - [ellipse](https://openhome.cc/eGossip/OpenSCAD/lib-ellipse.html) - [rounded_square](https://openhome.cc/eGossip/OpenSCAD/lib-rounded_square.html) - [line2d](https://openhome.cc/eGossip/OpenSCAD/lib-line2d.html) @@ -80,7 +80,8 @@ Too many dependencies? Because OpenSCAD doesn't provide namespace management, I - [sphere_spiral_extrude](https://openhome.cc/eGossip/OpenSCAD/lib-sphere_spiral_extrude.html) - Shape - - [shape_ellipse](https://openhome.cc/eGossip/OpenSCAD/lib-shape_ellipse.html) + - [shape_pie](https://openhome.cc/eGossip/OpenSCAD/lib-shape_pie.html) + - [shape_ellipse](https://openhome.cc/eGossip/OpenSCAD/lib-shape_ellipse.html) - [shape_square](https://openhome.cc/eGossip/OpenSCAD/lib-shape_square.html) - [shape_pentagram](https://openhome.cc/eGossip/OpenSCAD/lib-shape_pentagram.html) diff --git a/docs/images/lib-shape_pie-1.JPG b/docs/images/lib-shape_pie-1.JPG new file mode 100644 index 00000000..07ac8015 Binary files /dev/null and b/docs/images/lib-shape_pie-1.JPG differ diff --git a/docs/lib-shape_pie.md b/docs/lib-shape_pie.md new file mode 100644 index 00000000..3cfa0ea4 --- /dev/null +++ b/docs/lib-shape_pie.md @@ -0,0 +1,35 @@ +# shape_pie + +Returns shape points and triangle indexes of a pie (circular sector) shape. They can be used with xxx_extrude modules of dotSCAD. The shape points can be also used with the built-in polygon module. + +## Parameters + +- `radius` : The radius of the circle. +- `angles` : A 2 element vector which defines the central angle. The first element of the vector is the beginning angle in degrees, and the second element is the ending angle. +- `$fa`, `$fs`, `$fn` : Check [the circle module](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#circle) for more details. + +## Examples + + include ; + + shape_pts_tris = shape_pie(10, [45, 315], $fn = 24); + +![shape_pie](images/lib-shape_pie-1.JPG) + +include ; +include ; +include ; +include ; +include ; +include ; + +shape_pts_tris = shape_pie(10, [45, 315], $fn = 8); + +helix_extrude(shape_pts_tris[0], + radius = 40, + levels = 5, + level_dist = 20, + triangles = shape_pts_tris[1] +); + +![shape_pie](images/lib-shape_pie-2.JPG) diff --git a/src/shape_pie.scad b/src/shape_pie.scad new file mode 100644 index 00000000..4876d473 --- /dev/null +++ b/src/shape_pie.scad @@ -0,0 +1,40 @@ +/** +* shape_pie.scad +* +* Returns shape points and triangle indexes of a pie (circular sector) shape. +* They can be used with xxx_extrude modules of dotSCAD. +* The shape points can be also used with the built-in polygon module. +* +* @copyright Justin Lin, 2017 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib-shape_pie.html +* +**/ + +include <__private__/__frags.scad>; + +function shape_pie(radius, angles) = + let( + frags = __frags(radius), + a_step = 360 / frags, + leng = radius * cos(a_step / 2), + m = floor(angles[0] / a_step) + 1, + n = floor(angles[1] / a_step), + edge_r_begin = leng / cos((m - 0.5) * a_step - angles[0]), + edge_r_end = leng / cos((n + 0.5) * a_step - angles[1]), + shape_pts = concat( + [[0, 0], edge_r_begin * [cos(angles[0]), sin(angles[0])]], + [ + for(i = [m:n]) + let(a = a_step * i) + radius * [cos(a), sin(a)] + ], + [edge_r_end * [cos(angles[1]), sin(angles[1])]] + ), + triangles = [for(i = [1:len(shape_pts) - 2]) [0, i, i + 1]] + ) + [ + shape_pts, + triangles + ]; \ No newline at end of file