From 2e4d6b40371974534c3896b11c6f2277fe2d4843 Mon Sep 17 00:00:00 2001 From: Rock Storm Date: Tue, 2 Oct 2018 18:31:37 +0100 Subject: [PATCH] regular_shapes: Avoid the circle trick As is stated in the very own manual of OpenSCAD [1], generating polygons using the circle function is a trick that should be avoided. [1] https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/2D_Primitives#regular_polygon --- regular_shapes.scad | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/regular_shapes.scad b/regular_shapes.scad index 667d272..54d61fd 100644 --- a/regular_shapes.scad +++ b/regular_shapes.scad @@ -33,7 +33,11 @@ module reg_polygon(sides,radius) if(sides<2) square([radius,0]); if(sides==3) triangle(radius); if(sides==4) square([dia(radius),dia(radius)],center=true); - if(sides>4) circle(r=radius,$fn=sides); + if(sides>4) { + angles=[ for (i = [0:sides-1]) i*(360/sides) ]; + coords=[ for (th=angles) [radius*cos(th), radius*sin(th)] ]; + polygon(coords); + } } module pentagon(radius)