diff --git a/src/_impl/_shape_star_impl.scad b/src/_impl/_shape_star_impl.scad new file mode 100644 index 00000000..08f956e1 --- /dev/null +++ b/src/_impl/_shape_star_impl.scad @@ -0,0 +1,20 @@ +function __outer_points_shape_star(r1, r2, n) = + let( + a = 360 / n + ) + [for(i = 0; i < n; i = i + 1) [r1 * cos(90 + a * i), r1 * sin(90 + a * i)]]; + +function __inner_points_shape_star(r1, r2, n) = + let ( + a = 360 / n, + half_a = a / 2 + ) + [for(i = 0; i < n; i = i + 1) [r2 * cos(90 + a * i + half_a), r2 * sin(90 + a * i + half_a)]]; + +function _shape_star_impl(r1, r2, n) = + let( + outer_points = __outer_points_shape_star(r1, r2, n), + inner_points = __inner_points_shape_star(r1, r2, n), + leng = len(outer_points) + ) + [for(i = 0; i < leng; i = i + 1) each [outer_points[i], inner_points[i]]]; \ No newline at end of file diff --git a/src/shape_star.scad b/src/shape_star.scad new file mode 100644 index 00000000..1d94d989 --- /dev/null +++ b/src/shape_star.scad @@ -0,0 +1,13 @@ +/** +* shape_star.scad +* +* @copyright Justin Lin, 2021 +* @license https://opensource.org/licenses/lgpl-3.0.html +* +* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-shape_star.html +* +**/ + +use <_impl/_shape_star_impl.scad>; + +function shape_star(outerRadius = 1, innerRadius = 0.381966, n = 5) = _shape_star_impl(outerRadius, innerRadius, n); \ No newline at end of file