From d097be435bd881bd2d102cdb8d6cafa110b87c14 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Tue, 5 Jan 2021 23:29:10 -0500 Subject: [PATCH 1/4] Add bezier endpoint, tweak _bezcorners to properly produce that endpoint. doc tweak for polyhedra. --- beziers.scad | 18 ++++++++++-------- polyhedra.scad | 2 ++ rounding.scad | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/beziers.scad b/beziers.scad index 0549a2d..e754183 100644 --- a/beziers.scad +++ b/beziers.scad @@ -238,19 +238,20 @@ function bezier_curvature(curve, u) = ]; - // Function: bezier_curve() // Usage: -// bezier_curve(curve, n); +// bezier_curve(curve, n, [endpoint]); // Description: -// Takes a list of bezier curve control points, and a count of path points to generate. The points -// returned will be along the curve, starting at the first control point, then about every `1/n`th -// of the way along the curve, ending about `1/n`th of the way *before* the final control point. -// The distance between the points will *not* be equidistant. The degree of the curve, N, is one +// Takes a list of bezier curve control points and generates n points along the bezier path. +// Points start at the first control point and are sampled every `1/n`th +// of the way along the bezier parameter, ending *before* the final control point by default. +// The distance between the points will *not* be equidistant. If you wish to add the +// endpoint you can set `endpoint` to true. The degree of the bezier curve is one // less than the number of points in `curve`. // Arguments: // curve = The list of endpoints and control points for this bezier segment. // n = The number of points to generate along the bezier curve. +// endpoint = if true then add the endpoint (an extra point, giving n+1 points output). Default: False // Example(2D): Quadratic (Degree 2) Bezier. // bez = [[0,0], [30,30], [80,0]]; // move_copies(bezier_curve(bez, 8)) sphere(r=1.5, $fn=12); @@ -263,8 +264,9 @@ function bezier_curvature(curve, u) = // bez = [[0,0], [5,15], [40,20], [60,-15], [80,0]]; // move_copies(bezier_curve(bez, 8)) sphere(r=1.5, $fn=12); // trace_bezier(bez, N=len(bez)-1); -function bezier_curve(curve,n) = bezier_points(curve, [0:1/n:(n-0.5)/n]); - +function bezier_curve(curve,n,endpoint) = [each bezier_points(curve, [0:1/n:(n-0.5)/n]), + if (endpoint) curve[len(curve)-1] + ]; // Function: bezier_segment_closest_point() // Usage: diff --git a/polyhedra.scad b/polyhedra.scad index 0ea06cb..4bfb2f7 100644 --- a/polyhedra.scad +++ b/polyhedra.scad @@ -121,6 +121,7 @@ function _unique_groups(m) = [ // // Arguments: // name = Name of polyhedron to create. +// --- // index = Index to select from polyhedron list. Default: 0. // type = Type of polyhedron: "platonic", "archimedean", "catalan". // faces = Number of faces. @@ -564,6 +565,7 @@ _stellated_polyhedra_ = [ // // Arguments: // name = Name of polyhedron to create. +// --- // index = Index to select from polyhedron list. Default: 0. // type = Type of polyhedron: "platonic", "archimedean", "catalan". // faces = Number of faces. diff --git a/rounding.scad b/rounding.scad index c07664c..62f481c 100644 --- a/rounding.scad +++ b/rounding.scad @@ -308,7 +308,7 @@ function _bezcorner(points, parm) = ] : _smooth_bez_fill(points,parm), N = max(3,$fn>0 ?$fn : ceil(bezier_segment_length(P)/$fs)) ) - bezier_curve(P,N); + bezier_curve(P,N,endpoint=true); function _chamfcorner(points, parm) = let( From 1614c235e19f6fdf22d0b1bc545176777837cfd4 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Tue, 5 Jan 2021 23:37:00 -0500 Subject: [PATCH 2/4] fixed arc point count --- rounding.scad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rounding.scad b/rounding.scad index 62f481c..958db31 100644 --- a/rounding.scad +++ b/rounding.scad @@ -329,7 +329,7 @@ function _circlecorner(points, parm) = start = points[1]+prev*d, end = points[1]+next*d ) // 90-angle is half the angle of the circular arc - arc(max(3,(90-angle)/180*segs(r)), cp=center, points=[start,end]); + arc(max(3,ceil((90-angle)/180*segs(r))), cp=center, points=[start,end]); // Used by offset_sweep and convex_offset_extrude: From b1a8056c51896247461141571ae3fa226a29a7da Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Tue, 5 Jan 2021 23:39:07 -0500 Subject: [PATCH 3/4] Check N=integer --- shapes2d.scad | 1 + 1 file changed, 1 insertion(+) diff --git a/shapes2d.scad b/shapes2d.scad index 7a94b71..e3cfb3a 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -381,6 +381,7 @@ function arc(N, r, angle, d, cp, points, width, thickness, start, wedge=false, l assert(is_bool(endpoint)) !endpoint ? assert(!wedge, "endpoint cannot be false if wedge is true") slice(arc(N,r,angle,d,cp,points,width,thickness,start,wedge,long,cw,ccw,true),0,-2) : + assert(is_integer(N), "Number of points must be an integer") // First try for 2D arc specified by width and thickness is_def(width) && is_def(thickness)? ( assert(!any_defined([r,cp,points]) && !any([cw,ccw,long]),"Conflicting or invalid parameters to arc") From 9f8e9b8ba2d6533fd873fecd7a77ad87c0b6a434 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Tue, 5 Jan 2021 23:48:19 -0500 Subject: [PATCH 4/4] handle $fn case for arc --- shapes2d.scad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shapes2d.scad b/shapes2d.scad index e3cfb3a..91e1ab2 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -381,7 +381,7 @@ function arc(N, r, angle, d, cp, points, width, thickness, start, wedge=false, l assert(is_bool(endpoint)) !endpoint ? assert(!wedge, "endpoint cannot be false if wedge is true") slice(arc(N,r,angle,d,cp,points,width,thickness,start,wedge,long,cw,ccw,true),0,-2) : - assert(is_integer(N), "Number of points must be an integer") + assert(is_undef(N) || is_integer(N), "Number of points must be an integer") // First try for 2D arc specified by width and thickness is_def(width) && is_def(thickness)? ( assert(!any_defined([r,cp,points]) && !any([cw,ccw,long]),"Conflicting or invalid parameters to arc")