diff --git a/README.md b/README.md index 78295dd5..c345184c 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,5 @@ I've been using OpenSCAD for years and created some funny things. Some of them i - [bend](https://openhome.cc/eGossip/OpenSCAD/lib-bend.html) - Path + - [circle_path](https://openhome.cc/eGossip/OpenSCAD/lib-circle_path.html) - [bezier](https://openhome.cc/eGossip/OpenSCAD/lib-bezier.html) diff --git a/docs/images/lib-circle_path-1.JPG b/docs/images/lib-circle_path-1.JPG new file mode 100644 index 00000000..61336abd Binary files /dev/null and b/docs/images/lib-circle_path-1.JPG differ diff --git a/docs/lib-circle_path.md b/docs/lib-circle_path.md new file mode 100644 index 00000000..bcdbd915 --- /dev/null +++ b/docs/lib-circle_path.md @@ -0,0 +1,27 @@ +# circle_path + +Sometimes you need all points on the path of a circle. Here's the function. Its `$fa`, `$fs` and `$fn` parameters are consistent with the `circle` module. + +## Parameters + +- `radius` : The radius of the circle. +- `$fa`, `$fs`, `$fn` : Check [the circle module](https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Using_the_2D_Subsystem#circle) for more details. + +## Examples + + $fn = 24; + + points = circle_path(radius = 50); + polygon(points); + + leng = len(points); + step_angle = 360 / leng; + for(i = [0:leng - 1]) { + translate(points[i]) + rotate([90, 0, 90 + i * step_angle]) + linear_extrude(1, center = true) + text("A", valign = "center", halign = "center"); + } + +![circle_path](images/lib-circle_path-1.JPG) + diff --git a/src/circle_path.scad b/src/circle_path.scad new file mode 100644 index 00000000..30a53bbd --- /dev/null +++ b/src/circle_path.scad @@ -0,0 +1,23 @@ +/** +* circle_path.scad +* +* Sometimes you need all points on the path of a circle. Here's +* the function. Its $fa, $fs and $fn parameters are consistent +* with the circle module. +* +* @copyright Justin Lin, 2017 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib-circle_path.html +* +**/ + +function _frags(radius) = $fn > 0 ? + ($fn >= 3 ? $fn : 3) : + max(min(360 / $fa, radius * 2 * 3.14159 / $fs), 5); + +function circle_path(radius) = + [ + for(a = [0 : 360 / _frags(radius) : 360 - 360 / _frags(radius)]) + [radius * cos(a), radius * sin(a)] + ];