From fb7884f6e40520c65abb0b69e99d1ebd65e4d9e2 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 21 May 2017 20:37:26 +0800 Subject: [PATCH] considered angle not matching fn --- src/ring_extrude.scad | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/ring_extrude.scad b/src/ring_extrude.scad index e6411124..14619ddf 100644 --- a/src/ring_extrude.scad +++ b/src/ring_extrude.scad @@ -12,18 +12,26 @@ **/ include <__private__/__frags.scad>; +include <__private__/__ra_to_xy.scad>; module ring_extrude(shape_pts, radius, angle = 360, twist = 0, scale = 1.0, triangles = "SOLID") { - frags = __frags(radius); - - angle_step = 360 / frags; - as = [for(a = [0:angle_step:angle]) [90, 0, a]]; - angles = as[len(as) - 1][2] == angle ? as : concat(as, [[90, 0, angle]]); - pts = [for(a = angles) [radius * cos(a[2]), radius * sin(a[2])]]; + a_step = 360 / __frags(radius); + n = floor(angle / a_step); + + function end_r() = + radius * cos(a_step / 2) / cos((n + 0.5) * a_step - angle); + + angs = [for(a = [0:a_step:n * a_step]) [90, 0, a]]; + pts = [for(a = angs) __ra_to_xy(radius, a[2])]; + + is_angle_frag_end = angs[len(angs) - 1][2] == angle; + angles = is_angle_frag_end ? angs : concat(angs, [[90, 0, angle]]); + points = is_angle_frag_end ? pts : concat(pts, [__ra_to_xy(end_r(), angle)]); + polysections( - cross_sections(shape_pts, pts, angles, twist, scale), + cross_sections(shape_pts, points, angles, twist, scale), triangles = triangles ); } \ No newline at end of file