From bf9c1da41031e5d43ffcfd1dc1c5b809c2cf871a Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Wed, 22 May 2024 20:26:52 -0400 Subject: [PATCH 1/3] arc endpoint bugfix --- drawing.scad | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drawing.scad b/drawing.scad index 1a2b579..9b914b9 100644 --- a/drawing.scad +++ b/drawing.scad @@ -771,10 +771,12 @@ function arc(n, r, angle, d, cp, points, corner, width, thickness, start, wedge= assert(is_def(r) && r>0, "Arc radius invalid") let( n = is_def(n) ? n : max(3, ceil(segs(r)*abs(angle)/360)), - arcpoints = [for(i=[0:n-1]) let(theta = start + i*angle/(n-1)) r*[cos(theta),sin(theta)]+cp], - extra = wedge? [cp] : [] + arcpoints = [for(i=[0:n-1]) let(theta = start + i*angle/(n-1)) r*[cos(theta),sin(theta)]+cp] ) - concat(extra,arcpoints) + [ + if (wedge) cp, + each arcpoints + ] : is_def(corner)? assert(is_path(corner,[2,3]) && len(corner)==3,str("Point list is invalid")) assert(is_undef(cp) && !any([long,cw,ccw]), "Cannot use cp, long, cw, or ccw with corner") @@ -849,9 +851,17 @@ function arc(n, r, angle, d, cp, points, corner, width, thickness, start, wedge= theta_start = atan2(points[0].y-cp.y, points[0].x-cp.x), theta_end = atan2(points[1].y-cp.y, points[1].x-cp.x), angle = posmod(theta_end-theta_start, 360), - arcpts = arc(n,cp=cp,r=r,start=theta_start,angle=angle,wedge=wedge) + // Specify endpoints exactly; skip those endpoints when producing arc points + arcpts = [ if (wedge) cp, + points[0], + each arc(n,cp=cp,r=r,start=theta_start+angle/(n+1),angle=angle-2*angle/(n+1)), + points[1] + ] + ) - dir ? arcpts : wedge?reverse_polygon(arcpts):reverse(arcpts); + dir ? arcpts + : wedge ? reverse_polygon(arcpts) + : reverse(arcpts); module arc(n, r, angle, d, cp, points, corner, width, thickness, start, wedge=false, anchor=CENTER, spin=0) From f3b35eab0a087fc396d7ce8dc257a640f8eae4e8 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Wed, 22 May 2024 21:30:36 -0400 Subject: [PATCH 2/3] arc bugfix --- drawing.scad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drawing.scad b/drawing.scad index 9b914b9..6edae99 100644 --- a/drawing.scad +++ b/drawing.scad @@ -854,7 +854,7 @@ function arc(n, r, angle, d, cp, points, corner, width, thickness, start, wedge= // Specify endpoints exactly; skip those endpoints when producing arc points arcpts = [ if (wedge) cp, points[0], - each arc(n,cp=cp,r=r,start=theta_start+angle/(n+1),angle=angle-2*angle/(n+1)), + each arc(n-2,cp=cp,r=r,start=theta_start+angle/(n-1),angle=angle-2*angle/(n-1)), points[1] ] From 04437cc6a00d448708f4fd40efd7a8de5c3008df Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Wed, 22 May 2024 21:51:01 -0400 Subject: [PATCH 3/3] bugfix --- drawing.scad | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drawing.scad b/drawing.scad index 6edae99..1771188 100644 --- a/drawing.scad +++ b/drawing.scad @@ -852,15 +852,17 @@ function arc(n, r, angle, d, cp, points, corner, width, thickness, start, wedge= theta_end = atan2(points[1].y-cp.y, points[1].x-cp.x), angle = posmod(theta_end-theta_start, 360), // Specify endpoints exactly; skip those endpoints when producing arc points + // Generating the whole arc and clipping ends is the easiest way to ensure that we + // generate the proper number of points. arcpts = [ if (wedge) cp, points[0], - each arc(n-2,cp=cp,r=r,start=theta_start+angle/(n-1),angle=angle-2*angle/(n-1)), + each select(arc(n,cp=cp,r=r,start=theta_start,angle=angle),1,-2), points[1] ] ) dir ? arcpts - : wedge ? reverse_polygon(arcpts) + : wedge ? reverse_polygon(arcpts) // Keep the centerpoint at position 0 in the list : reverse(arcpts);