diff --git a/rounding.scad b/rounding.scad index 4eef0bb..266318e 100644 --- a/rounding.scad +++ b/rounding.scad @@ -26,9 +26,9 @@ include // // Usage: // round_corners(path, [method], [radius], [cut], [joint], [closed], [verbose]); -// +// // Description: -// Takes a 2D or 3D path as input and rounds each corner +// Takes a 2D or 3D path as input and rounds each corner // by a specified amount. The rounding at each point can be different and some points can have zero // rounding. The `round_corners()` function supports three types of corner treatment: chamfers, circular rounding, // and continuous curvature rounding using 4th order bezier curves. Circular rounding can produce a @@ -37,11 +37,11 @@ include // // You select the type of rounding using the `method` option, which should be `"smooth"` to // get continuous curvature rounding, `"circle"` to get circular rounding, or `"chamfer"` to get chamfers. The default is circle -// rounding. Each method has two options you can use to specify the amount of rounding. +// rounding. Each method has two options you can use to specify the amount of rounding. // All of the rounding methods accept the cut option. This mode specifies the distance from the unrounded corner to the rounded tip, so how // much of the corner to "cut" off. This can be easier to understand than setting a circular radius, which can be // unexpectedly extreme when the corner is very sharp. It also allows a systematic specification of -// corner treatments that are the same size for all three methods. +// corner treatments that are the same size for all three methods. // // For circular rounding you can also use the `radius` parameter, which sets a circular rounding // radius. For chamfers and smooth rounding you can speicfy the `joint` parameter, which specifies the distance @@ -57,14 +57,14 @@ include // // If you select curves that are too large to fit the function will fail with an error. You can set `verbose=true` to // get a message showing a list of scale factors you can apply to your rounding paramets so that the -// roundovers will fit on the curve. If the scale factors are larger than one +// roundovers will fit on the curve. If the scale factors are larger than one // then they indicate how much you can increase the curve sizes before collisions will occur. // // The parameters `radius`, `cut`, `joint` and `k` can be numbers, which round every corner using the same parameters, or you // can specify a list to round each corner with different parameters. If the curve is not closed then the first and last points // of the curve are not rounded. In this case you can specify a full list of points anyway, and the endpoint values are ignored, -// or you can specify a list that has length len(path)-2, omitting the two dummy values. - +// or you can specify a list that has length len(path)-2, omitting the two dummy values. +// // Examples: // * `method="circle", radius=2`: // Rounds every point with circular, radius 2 roundover @@ -93,15 +93,15 @@ include // color("blue")translate([w/2-1.1,h/2+.6]) scale(.1)rotate(90-vector_angle(example)/2)text("joint"); // // Arguments: -// path = list of 2d or 3d points defining the path to be rounded. +// 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" // 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. +// 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. // 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 -// +// // Example(Med2D): Standard circular roundover with radius the same at every point. Compare results at the different corners. // shape = [[0,0], [10,0], [15,12], [6,6], [6, 12], [-3,7]]; // polygon(round_corners(shape, radius=1)); @@ -124,7 +124,7 @@ include // polygon(round_corners(shape, radius = radii), $fn=128); // color("red") down(.1) polygon(shape); // Example(Med2D): Continuous curvature rounding, different at every corner, with varying smoothness parameters as well, and `$fs` set very small -// shape = [[0,0], [10,0], [15,12], [6,6], [6, 12], [-3,7]]; +// shape = [[0,0], [10,0], [15,12], [6,6], [6, 12], [-3,7]]; // cuts = [1.5,0,2,0.3, 1.2, 0]; // k = [0.6, 0.5, 0.5, 0.7, 0.3, 0.5]; // polygon(round_corners(shape, method="smooth", cut=cuts, k=k, $fs=0.1)); @@ -134,21 +134,19 @@ include // polygon(round_corners(shape, method="chamfer", cut=1)); // color("red") down(.1) polygon(shape); // Example(Med3D): 3D printing test pieces to display different curvature shapes. You can see the discontinuity in the curvature on the "C" piece in the rendered image. -// $fn=96; // ten = square(50); // cut = 5; -// linear_extrude(height=14){ +// linear_extrude(height=14) { // translate([25,25,0])text("C",size=30, valign="center", halign="center"); // translate([85,25,0])text("5",size=30, valign="center", halign="center"); // translate([85,85,0])text("3",size=30, valign="center", halign="center"); // translate([25,85,0])text("7",size=30, valign="center", halign="center"); // } -// linear_extrude(height=13) -// { +// linear_extrude(height=13) { // polygon(round_corners(ten, cut=cut), $fn=96*4); -// translate([60,0,0])polygon(round_corners(ten, method="smooth", cut=cut)); -// translate([60,60,0])polygon(round_corners(ten, method="smooth", cut=cut, k=0.32)); -// translate([0,60,0])polygon(round_corners(ten, method="smooth", cut=cut, k=0.7)); +// translate([60,0,0])polygon(round_corners(ten, method="smooth", cut=cut, $fn=96)); +// translate([60,60,0])polygon(round_corners(ten, method="smooth", cut=cut, k=0.32, $fn=96)); +// translate([0,60,0])polygon(round_corners(ten, method="smooth", cut=cut, k=0.7, $fn=96)); // } // Example(Med2D): Rounding a path that is not closed in a three different ways. // $fs=.1; @@ -196,7 +194,7 @@ include // // Try changing the value to see the effect. // rpath = round_corners(path3d, joint=rounding, k=1, method="smooth", closed=false); // path_sweep( regular_ngon(n=36, or=.1), rpath); -function round_corners(path, method="circle", radius, cut, joint, k, closed=true, verbose=false) = +function round_corners(path, method="circle", radius, cut, joint, 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, @@ -220,7 +218,7 @@ function round_corners(path, method="circle", radius, cut, joint, k, closed=true parm = is_num(size) ? repeat(size, len(path)) : len(size)