From 3dc1877dbdfb460a5a8457c500824dbcb0587e80 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sat, 6 May 2017 13:50:49 +0800 Subject: [PATCH] added two shapes --- src/shape_pentagram.scad | 22 ++++++++++++++++++++++ src/shape_square.scad | 30 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/shape_pentagram.scad create mode 100644 src/shape_square.scad diff --git a/src/shape_pentagram.scad b/src/shape_pentagram.scad new file mode 100644 index 00000000..685355e0 --- /dev/null +++ b/src/shape_pentagram.scad @@ -0,0 +1,22 @@ +function shape_pentagram(r) = + [ + // shape points + [ + [0, 1], [-0.224514, 0.309017], + [-0.951057, 0.309017], [-0.363271, -0.118034], + [-0.587785, -0.809017], [0, -0.381966], + [0.587785, -0.809017], [0.363271, -0.118034], + [0.951057, 0.309017], [0.224514, 0.309017] + ] * r, + // triangles + [ + [0, 1, 9], + [2, 3, 1], + [4, 5, 3], + [6, 7, 5], + [8, 9, 7], + [1, 3, 5], + [1, 5, 7], + [1, 7, 9] + ] + ]; \ No newline at end of file diff --git a/src/shape_square.scad b/src/shape_square.scad new file mode 100644 index 00000000..f07499b8 --- /dev/null +++ b/src/shape_square.scad @@ -0,0 +1,30 @@ +function shape_square(size, corner_r = 0) = + let( + frags = $fn > 0 ? + ($fn >= 3 ? $fn : 3) : + max(min(360 / $fa, corner_r * 6.28318 / $fs), 5), + remain = frags % 4, + corner_frags = (remain / 4) > 0.5 ? frags - remain + 4 : frags - remain, + step_a = 360 / corner_frags, + x = len(size) == undef ? size : size[0], + y = len(size) == undef ? size : size[1], + half_x = x / 2, + half_y = y / 2, + half_w = half_x - corner_r, + half_h = half_y - corner_r, + shape_pts = concat( + [[half_x, -half_h], [half_x, half_h]], + [for(a = [step_a:step_a:90 - step_a]) [corner_r * cos(a) + half_w, corner_r * sin(a) + half_h]], + [[half_w, half_y], [-half_w, half_y]], + [for(a = [90 + step_a:step_a:180 - step_a]) [corner_r * cos(a) - half_w, corner_r * sin(a) + half_h]], + [[-half_x, half_h], [-half_x, -half_h]], + [for(a = [180 + step_a:step_a:270 - step_a]) [corner_r * cos(a) - half_w, corner_r * sin(a) - half_h]], + [[-half_w, -half_y], [half_w, -half_y]], + [for(a = [270 + step_a:step_a:360 - step_a]) [corner_r * cos(a) + half_w, corner_r * sin(a) - half_h]] + ), + triangles = [for(i = [1:len(shape_pts) - 2]) [0, i, i + 1]] + ) + [ + shape_pts, + triangles + ]; \ No newline at end of file