From 40c4079be5dddc43ae93b8f15aafbf3caec029e0 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Mon, 17 Jan 2022 11:21:42 -0500 Subject: [PATCH 1/3] A couple more examples --- rounding.scad | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/rounding.scad b/rounding.scad index 7be2503..68a03a8 100644 --- a/rounding.scad +++ b/rounding.scad @@ -44,6 +44,8 @@ include // For circular rounding you can also use the `radius` parameter, which sets a circular rounding // radius. // . +// For chamfers you can use the `flat` parameter, which sets the length of the chamfer edge. +// . // The `"smooth"` method rounding also has a parameter that specifies how smooth the curvature match // is. This parameter, `k`, ranges from 0 to 1, with a default of 0.5. Larger values give a more // abrupt transition and smaller ones a more gradual transition. If you set the value much higher @@ -105,6 +107,7 @@ include // radius = rounding radius, only compatible with `method="circle"`. Can be a number or vector. // cut = rounding cut distance, compatible with all methods. Can be a number or vector. // joint = rounding joint distance, compatible with `method="chamfer"` and `method="smooth"`. Can be a number or vector. +// flat = length of the flat edge created by chamfering, compatible with `method="chamfer"`. Can be a number of vector. // k = continuous curvature smoothness parameter for `method="smooth"`. Can be a number or vector. Default: 0.5 // closed = if true treat the path as a closed polygon, otherwise treat it as open. Default: true. // verbose = if true display rounding scale factors that show how close roundovers are to overlapping. Default: false @@ -259,6 +262,23 @@ include // cut=chamfcut), // radius=radii); // stroke(path2, closed=true); +// Example(2D): Specifying by corner index. Use {{list_set()}} to construct the full chamfer cut list. +// path = star(47, ir=25, or=50); // long path, lots of corners +// chamfind = [8, 28, 60]; // But only want 3 chamfers +// chamfcut = list_set([],chamfind,[10,13,15],minlen=len(path)-1); +// rpath = round_corners(path, cut=chamfcut, method="chamfer"); +// polygon(rpath); +// Example(2D): Two-pass to chamfer and round by index. Use {{repeat_entries()}} to correct for first pass chamfers. +// $fn=32; +// path = star(47, ir=25, or=50); // long path, lots of corners +// chamfind = [8, 28, 60]; // But only want 3 chamfers +// roundind = [7,9,27,29,59,61]; // And 6 roundovers +// chamfcut = list_set([],chamfind,[10,13,15],minlen=len(path)-1); +// roundcut = list_set([],roundind,repeat(8,6),minlen=len(path)-1); +// dups = list_set([], chamfind, repeat(2,len(chamfind)), dflt=1, minlen=len(path)-1); +// rpath1 = round_corners(path, cut=chamfcut, method="chamfer"); +// rpath2 = round_corners(rpath1, cut=repeat_entries(roundcut,dups)); +// polygon(rpath2); module round_corners(path, method="circle", radius, cut, joint, flat, k, closed=true, verbose=false) {no_module();} function round_corners(path, method="circle", radius, cut, joint, flat, k, closed=true, verbose=false) = assert(in_list(method,["circle", "smooth", "chamfer"]), "method must be one of \"circle\", \"smooth\" or \"chamfer\"") From d81eb6d0e0d15e70d5b38530f82146409c1787d4 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Mon, 17 Jan 2022 22:34:50 -0500 Subject: [PATCH 2/3] change "flat" to "chamfer". 2 move examples --- rounding.scad | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rounding.scad b/rounding.scad index 68a03a8..2f89b94 100644 --- a/rounding.scad +++ b/rounding.scad @@ -230,9 +230,9 @@ include // path_len = path_segment_lengths(path,closed=true); // halflen = [for(i=idx(path)) min(select(path_len,i-1,i))/2]; // polygon(round_corners(path,joint = halflen, method="circle",verbose=true)); -// Example(2D): Chamfering, specifying the flats +// Example(2D): Chamfering, specifying the chamfer length // path = star(5, step=2, d=100); -// path2 = round_corners(path, method="chamfer", flat=5); +// path2 = round_corners(path, method="chamfer", chamfer=5); // polygon(path2); // Example(2D): Chamfering, specifying the cut // path = star(5, step=2, d=100); @@ -279,19 +279,19 @@ include // rpath1 = round_corners(path, cut=chamfcut, method="chamfer"); // rpath2 = round_corners(rpath1, cut=repeat_entries(roundcut,dups)); // polygon(rpath2); -module round_corners(path, method="circle", radius, cut, joint, flat, k, closed=true, verbose=false) {no_module();} -function round_corners(path, method="circle", radius, cut, joint, flat, k, closed=true, verbose=false) = +module round_corners(path, method="circle", radius, cut, joint, chamfer, k, closed=true, verbose=false) {no_module();} +function round_corners(path, method="circle", radius, cut, joint, chamfer, k, closed=true, verbose=false) = assert(in_list(method,["circle", "smooth", "chamfer"]), "method must be one of \"circle\", \"smooth\" or \"chamfer\"") let( default_k = 0.5, - size=one_defined([radius, cut, joint, flat], "radius,cut,joint,flat"), + size=one_defined([radius, cut, joint, chamfer], "radius,cut,joint,chamfer"), path = force_path(path), size_ok = is_num(size) || len(size)==len(path) || (!closed && len(size)==len(path)-2), k_ok = is_undef(k) || (method=="smooth" && (is_num(k) || len(k)==len(path) || (!closed && len(k)==len(path)-2))), measure = is_def(radius) ? "radius" : is_def(cut) ? "cut" : is_def(joint) ? "joint" - : "flat" + : "chamfer" ) assert(is_path(path,[2,3]), "input path must be a 2d or 3d path") assert(len(path)>2,str("Path has length ",len(path),". Length must be 3 or more.")) @@ -299,7 +299,7 @@ function round_corners(path, method="circle", radius, cut, joint, flat, k, close assert(k_ok,method=="smooth" ? str("Input k must be a number or list with length ",len(path), closed?"":str(" or ",len(path)-2)) : "Input k is only allowed with method=\"smooth\"") assert(method=="circle" || measure!="radius", "radius parameter allowed only with method=\"circle\"") - assert(method=="chamfer" || measure!="flat", "flat parameter allowed only with method=\"chamfer\"") + assert(method=="chamfer" || measure!="chamfer", "chamfer parameter allowed only with method=\"chamfer\"") let( parm = is_num(size) ? repeat(size, len(path)) : len(size) Date: Tue, 18 Jan 2022 23:11:22 -0500 Subject: [PATCH 3/3] changed "chamfer" to "length" added figures for circle and chamfer --- rounding.scad | 61 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/rounding.scad b/rounding.scad index 2f89b94..aeef8e6 100644 --- a/rounding.scad +++ b/rounding.scad @@ -44,7 +44,7 @@ include // For circular rounding you can also use the `radius` parameter, which sets a circular rounding // radius. // . -// For chamfers you can use the `flat` parameter, which sets the length of the chamfer edge. +// For chamfers you can use the `length` parameter, which sets the length of the chamfer edge. // . // The `"smooth"` method rounding also has a parameter that specifies how smooth the curvature match // is. This parameter, `k`, ranges from 0 to 1, with a default of 0.5. Larger values give a more @@ -84,7 +84,28 @@ include // This guarantees a specific output length. It also means that if // you set `joint` nonzero on a flat "corner", with collinear points, you will get $fn points at that "corner." // -// Figure(2D,Med,NoAxes): +// Figure(2D,Med,NoAxes): Parameters of a "circle" roundover +// h = 18; +// w = 12.6; +// strokewidth = .3; +// example = [[0,0],[w,h],[2*w,0]]; +// stroke(example, width=strokewidth*1.5); +// textangle = 90-vector_angle(example)/2; +// theta = vector_angle(example)/2; +// color("green"){ stroke([[w,h], [w,h-18*(1-sin(theta))/cos(theta)]], width=strokewidth, endcaps="arrow2"); +// translate([w-1.75,h-7])scale(.1)rotate(textangle)text("cut",size=14); } +// ll=lerp([w,h], [0,0],18/norm([w,h]-[0,0]) ); +// color("blue"){ stroke(_shift_segment([[w,h], ll], -.7), width=strokewidth,endcaps="arrow2"); +// translate([w/2-1.3,h/2+.6]) scale(.1)rotate(textangle)text("joint",size=14);} +// color("red")stroke( +// select(round_corners(example, joint=18, method="circle",$fn=64,closed=false),1,-2), +// width=strokewidth); +// r=18*tan(theta); +// color("black"){ +// stroke([ll, [w,h-r-18*(1-sin(theta))/cos(theta)]], width=strokewidth, endcaps="arrow2"); +// translate([w/1.6,0])text("radius", size=1.4); +// } +// Figure(2D,Med,NoAxes): Parameters of a "smooth" roundover // h = 18; // w = 12.6; // strokewidth = .3; @@ -92,7 +113,6 @@ include // stroke(example, width=strokewidth*1.5); // textangle = 90-vector_angle(example)/2; // color("green"){ stroke([[w,h], [w,h-cos(vector_angle(example)/2) *3/8*h]], width=strokewidth, endcaps="arrow2"); -// //translate([w-.3,h-4.4])scale(.1)rotate(90)text("cut",size=12); } // translate([w-1.75,h-5.5])scale(.1)rotate(textangle)text("cut",size=14); } // ll=lerp([w,h], [0,0],18/norm([w,h]-[0,0]) ); // color("blue"){ stroke(_shift_segment([[w,h], ll], -.7), width=strokewidth,endcaps="arrow2"); @@ -100,6 +120,27 @@ include // color("red")stroke( // select(round_corners(example, joint=18, method="smooth",closed=false),1,-2), // width=strokewidth); +// Figure(2D,Med,NoAxes): Parameters of "chamfer" +// h = 18; +// w = 12.6; +// strokewidth = .3; +// example = [[0,0],[w,h],[2*w,0]]; +// stroke(example, width=strokewidth*1.5); +// textangle = 90-vector_angle(example)/2; +// color("black"){ +// stroke(fwd(1, +// select(round_corners(example, joint=18, method="chamfer",closed=false),1,-2)), +// width=strokewidth,endcaps="arrow2"); +// translate([w,.3])text("length", size=1.4,halign="center"); +// } +// color("green"){ stroke([[w,h], [w,h-18*cos(vector_angle(example)/2)]], width=strokewidth, endcaps="arrow2"); +// translate([w-1.75,h-5.5])scale(.1)rotate(textangle)text("cut",size=14); } +// ll=lerp([w,h], [0,0],18/norm([w,h]-[0,0]) ); +// color("blue"){ stroke(_shift_segment([[w,h], ll], -.7), width=strokewidth,endcaps="arrow2"); +// translate([w/2-1.3,h/2+.6]) rotate(textangle)text("joint",size=1.4);} +// color("red")stroke( +// select(round_corners(example, joint=18, method="chamfer",closed=false),1,-2), +// width=strokewidth); // Arguments: // path = list of 2d or 3d points defining the path to be rounded. // method = rounding method to use. Set to "chamfer" for chamfers, "circle" for circular rounding and "smooth" for continuous curvature 4th order bezier rounding. Default: "circle" @@ -232,7 +273,7 @@ include // polygon(round_corners(path,joint = halflen, method="circle",verbose=true)); // Example(2D): Chamfering, specifying the chamfer length // path = star(5, step=2, d=100); -// path2 = round_corners(path, method="chamfer", chamfer=5); +// path2 = round_corners(path, method="chamfer", length=5); // polygon(path2); // Example(2D): Chamfering, specifying the cut // path = star(5, step=2, d=100); @@ -279,19 +320,19 @@ include // rpath1 = round_corners(path, cut=chamfcut, method="chamfer"); // rpath2 = round_corners(rpath1, cut=repeat_entries(roundcut,dups)); // polygon(rpath2); -module round_corners(path, method="circle", radius, cut, joint, chamfer, k, closed=true, verbose=false) {no_module();} -function round_corners(path, method="circle", radius, cut, joint, chamfer, k, closed=true, verbose=false) = +module round_corners(path, method="circle", radius, cut, joint, length, k, closed=true, verbose=false) {no_module();} +function round_corners(path, method="circle", radius, cut, joint, length, k, closed=true, verbose=false) = assert(in_list(method,["circle", "smooth", "chamfer"]), "method must be one of \"circle\", \"smooth\" or \"chamfer\"") let( default_k = 0.5, - size=one_defined([radius, cut, joint, chamfer], "radius,cut,joint,chamfer"), + size=one_defined([radius, cut, joint, length], "radius,cut,joint,length"), path = force_path(path), size_ok = is_num(size) || len(size)==len(path) || (!closed && len(size)==len(path)-2), k_ok = is_undef(k) || (method=="smooth" && (is_num(k) || len(k)==len(path) || (!closed && len(k)==len(path)-2))), measure = is_def(radius) ? "radius" : is_def(cut) ? "cut" : is_def(joint) ? "joint" - : "chamfer" + : "length" ) assert(is_path(path,[2,3]), "input path must be a 2d or 3d path") assert(len(path)>2,str("Path has length ",len(path),". Length must be 3 or more.")) @@ -299,7 +340,7 @@ function round_corners(path, method="circle", radius, cut, joint, chamfer, k, cl assert(k_ok,method=="smooth" ? str("Input k must be a number or list with length ",len(path), closed?"":str(" or ",len(path)-2)) : "Input k is only allowed with method=\"smooth\"") assert(method=="circle" || measure!="radius", "radius parameter allowed only with method=\"circle\"") - assert(method=="chamfer" || measure!="chamfer", "chamfer parameter allowed only with method=\"chamfer\"") + assert(method=="chamfer" || measure!="length", "length parameter allowed only with method=\"chamfer\"") let( parm = is_num(size) ? repeat(size, len(path)) : len(size)