From 2f6671e56dd31e0d8337a65f1c059284db54290e Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Mon, 24 Jun 2019 00:32:13 -0700 Subject: [PATCH] Long overdue path and bezier function and module name cleanups. --- beziers.scad | 120 ++++++------------------------------- examples/fractal_tree.scad | 2 +- paths.scad | 50 ++++------------ roundcorners.scad | 6 +- threading.scad | 2 +- wiring.scad | 2 +- 6 files changed, 35 insertions(+), 147 deletions(-) diff --git a/beziers.scad b/beziers.scad index 661853f..1b07acd 100644 --- a/beziers.scad +++ b/beziers.scad @@ -442,9 +442,9 @@ module bezier_polygon(bezier, splinesteps=16, N=3) { } -// Module: linear_extrude_bezier() +// Module: linear_sweep_bezier() // Usage: -// linear_extrude_bezier(bezier, height, [splinesteps], [N], [center], [convexity], [twist], [slices], [scale]); +// linear_sweep_bezier(bezier, height, [splinesteps], [N], [center], [convexity], [twist], [slices], [scale]); // Description: // Takes a closed 2D bezier path, centered on the XY plane, and // extrudes it linearly upwards, forming a solid. @@ -468,8 +468,8 @@ module bezier_polygon(bezier, splinesteps=16, N=3) { // [ 5, 10], [ 0, 10], [-5, 10], // [ 25, -15], [-10, 0] // ]; -// linear_extrude_bezier(bez, height=20, splinesteps=32); -module linear_extrude_bezier(bezier, height=100, splinesteps=16, N=3, center=undef, convexity=undef, twist=undef, slices=undef, scale=undef, anchor=UP, spin=0, orient=UP) { +// linear_sweep_bezier(bez, height=20, splinesteps=32); +module linear_sweep_bezier(bezier, height=100, splinesteps=16, N=3, center=undef, convexity=undef, twist=undef, slices=undef, scale=undef, anchor=UP, spin=0, orient=UP) { maxx = max([for (pt = bezier) abs(pt[0])]); maxy = max([for (pt = bezier) abs(pt[1])]); orient_and_anchor([maxx*2,maxy*2,height], orient, anchor, spin=spin, chain=true) { @@ -481,45 +481,9 @@ module linear_extrude_bezier(bezier, height=100, splinesteps=16, N=3, center=und } -// Module: revolve_bezier() +// Module: rotate_sweep_bezier() // Usage: -// revolve_bezier(bezier, [splinesteps], [N], [convexity], [angle]) -// Description: -// Takes a closed 2D bezier and rotates it around the X axis, forming a solid. -// Arguments: -// bezier = array of 2D points for the bezier path to rotate. -// splinesteps = number of segments to divide each bezier segment into. default=16 -// N = number of points in each bezier segment. default=3 (cubic) -// convexity = max number of walls a line could pass through, for preview. default=10 -// angle = Degrees of sweep to make. Default: 360 -// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` -// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` -// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` -// Example(FlatSpin): -// path = [ -// [ 0, 10], [ 50, 0], [ 50, 40], -// [ 95, 40], [100, 40], [100, 45], -// [ 95, 45], [ 66, 45], [ 0, 20], -// [ 0, 12], [ 0, 12], [ 0, 10], -// [ 0, 10] -// ]; -// revolve_bezier(path, splinesteps=32, $fn=180); -module revolve_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=360, anchor=CENTER, spin=0, orient=RIGHT) -{ - maxx = max([for (pt = bezier) abs(pt[0])]); - maxy = max([for (pt = bezier) abs(pt[1])]); - orient_and_anchor([maxx*2,maxx*2,maxy*2], orient, anchor, spin=spin, geometry="cylinder", chain=true) { - rotate_extrude(convexity=convexity, angle=angle) { - xrot(180) zrot(-90) bezier_polygon(bezier, splinesteps, N); - } - } -} - - - -// Module: rotate_extrude_bezier() -// Usage: -// rotate_extrude_bezier(bezier, [splinesteps], [N], [convexity], [angle]) +// rotate_sweep_bezier(bezier, [splinesteps], [N], [convexity], [angle]) // Description: // Takes a closed 2D bezier and rotates it around the Z axis, forming a solid. // Behaves like rotate_extrude(), except for beziers instead of shapes. @@ -540,8 +504,8 @@ module revolve_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=360, anch // [ 0, 12], [ 0, 12], [ 0, 10], // [ 0, 10] // ]; -// rotate_extrude_bezier(path, splinesteps=32, $fn=180); -module rotate_extrude_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=360, anchor=CENTER, spin=0, orient=UP) +// rotate_sweep_bezier(path, splinesteps=32, $fn=180); +module rotate_sweep_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=360, anchor=CENTER, spin=0, orient=UP) { maxx = max([for (pt = bezier) abs(pt[0])]); maxy = max([for (pt = bezier) abs(pt[1])]); @@ -553,75 +517,29 @@ module rotate_extrude_bezier(bezier, splinesteps=16, N=3, convexity=10, angle=36 } - -// Module: revolve_bezier_solid_to_axis() +// Module: bezier_path_extrude() // Usage: -// revolve_bezier_solid_to_axis(bezier, [splinesteps], [N], [convexity], [angle]); +// bezier_path_extrude(bezier, [splinesteps], [N], [convexity], [clipsize]) ... // Description: -// Takes a 2D bezier and rotates it around the X axis, forming a solid. -// Arguments: -// bezier = array of points for the bezier path to rotate. -// splinesteps = number of segments to divide each bezier segment into. default=16 -// N = number of points in each bezier segment. default=3 (cubic) -// convexity = max number of walls a line could pass through, for preview. default=10 -// angle = Degrees of sweep to make. Default: 360 -// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` -// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` -// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` -// Example(FlatSpin): -// path = [ [0, 10], [33, 10], [66, 40], [100, 40] ]; -// revolve_bezier_solid_to_axis(path, splinesteps=32, $fn=72); -module revolve_bezier_solid_to_axis(bezier, splinesteps=16, N=3, convexity=10, angle=360, anchor=CENTER, spin=0, orient=RIGHT) { - revolve_bezier(bezier=bezier_close_to_axis(bezier), splinesteps=splinesteps, N=N, convexity=convexity, angle=angle, anchor=anchor, spin=spin, orient=orient); -} - - -// Module: revolve_bezier_offset_shell() -// Usage: -// revolve_bezier_offset_shell(bezier, offset, [splinesteps], [N], [convexity], [angle]); -// Description: -// Takes a 2D bezier and rotates it around the X axis, into a hollow shell. -// Arguments: -// bezier = array of points for the bezier path to rotate. -// offset = the thickness of the created shell. -// splinesteps = number of segments to divide each bezier segment into. default=16 -// N = number of points in each bezier segment. default=3 (cubic) -// convexity = max number of walls a line could pass through, for preview. default=10 -// angle = degrees of sweep to make. Default: 360 -// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` -// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` -// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `RIGHT` -// Example(FlatSpin): -// path = [ [0, 10], [33, 10], [66, 40], [100, 40] ]; -// revolve_bezier_offset_shell(path, offset=1, splinesteps=32, $fn=72); -module revolve_bezier_offset_shell(bezier, offset=1, splinesteps=16, N=3, convexity=10, angle=360, anchor=CENTER, spin=0, orient=RIGHT) { - revolve_bezier(bezier=bezier_offset(offset, bezier), splinesteps=splinesteps, N=N, anchor=anchor, spin=spin, orient=orient); -} - - -// Module: extrude_2d_shapes_along_bezier() -// Usage: -// extrude_2d_shapes_along_bezier(bezier, [splinesteps], [N], [convexity], [clipsize]) ... -// Description: -// Extrudes 2D children along a bezier path. +// Extrudes 2D shape children along a bezier path. // Arguments: // bezier = array of points for the bezier path to extrude along. // splinesteps = number of segments to divide each bezier segment into. default=16 // Example(FR): // path = [ [0, 0, 0], [33, 33, 33], [66, -33, -33], [100, 0, 0] ]; -// extrude_2d_shapes_along_bezier(path) difference(){ +// bezier_path_extrude(path) difference(){ // circle(r=10); // fwd(10/2) circle(r=8); // } -module extrude_2d_shapes_along_bezier(bezier, splinesteps=16, N=3, convexity=10, clipsize=1000) { +module bezier_path_extrude(bezier, splinesteps=16, N=3, convexity=10, clipsize=1000) { path = slice(bezier_polyline(bezier, splinesteps, N), 0, -1); - extrude_2d_shapes_along_3dpath(path, convexity=convexity, clipsize=clipsize) children(); + path_extrude(path, convexity=convexity, clipsize=clipsize) children(); } -// Module: extrude_bezier_along_bezier() +// Module: bezier_sweep_bezier() // Usage: -// extrude_bezier_along_bezier(bezier, path, [pathsteps], [bezsteps], [bezN], [pathN]); +// bezier_sweep_bezier(bezier, path, [pathsteps], [bezsteps], [bezN], [pathN]); // Description: // Takes a closed 2D bezier path, centered on the XY plane, and // extrudes it perpendicularly along a 3D bezier path, forming a solid. @@ -641,11 +559,11 @@ module extrude_2d_shapes_along_bezier(bezier, splinesteps=16, N=3, convexity=10, // [ 25, -15], [-10, 0] // ]; // path = [ [0, 0, 0], [33, 33, 33], [90, 33, -33], [100, 0, 0] ]; -// extrude_bezier_along_bezier(bez, path, pathsteps=32, bezsteps=16); -module extrude_bezier_along_bezier(bezier, path, pathsteps=16, bezsteps=16, bezN=3, pathN=3) { +// bezier_sweep_bezier(bez, path, pathsteps=32, bezsteps=16); +module bezier_sweep_bezier(bezier, path, pathsteps=16, bezsteps=16, bezN=3, pathN=3) { bez_points = simplify2d_path(bezier_polyline(bezier, bezsteps, bezN)); path_points = simplify3d_path(path3d(bezier_polyline(path, pathsteps, pathN))); - extrude_2dpath_along_3dpath(bez_points, path_points); + path_sweep(bez_points, path_points); } diff --git a/examples/fractal_tree.scad b/examples/fractal_tree.scad index 60f3320..690efd3 100644 --- a/examples/fractal_tree.scad +++ b/examples/fractal_tree.scad @@ -9,7 +9,7 @@ module leaf(s) { [-1.5,-1], [0,0] ]; xrot(90) - linear_extrude_bezier( + linear_sweep_bezier( scale_points(path, [s,s]/2), height=0.02 ); diff --git a/paths.scad b/paths.scad index 7687402..b527d93 100644 --- a/paths.scad +++ b/paths.scad @@ -169,37 +169,7 @@ module extrude_from_to(pt1, pt2, convexity=undef, twist=undef, scale=undef, slic -// Module: extrude_2d_hollow() -// Description: -// Similar to linear_extrude(), except the result is a hollow shell. -// Arguments: -// wall = thickness of shell wall. -// height = height of extrusion. -// twist = degrees of twist, from bottom to top. -// slices = how many slices to use when making extrusion. -// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` -// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` -// orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` -// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=BOTTOM`. -// Example: -// extrude_2d_hollow(wall=2, height=100, twist=90, slices=50) -// circle(r=40, $fn=6); -module extrude_2d_hollow(wall=2, height=50, twist=90, slices=60, center=undef, anchor=BOTTOM, spin=0, orient=UP) -{ - orient_and_anchor([0.01,0.01,height], orient, anchor, spin=spin, center=center) { - linear_extrude(height=height, twist=twist, slices=slices, center=true) { - difference() { - children(); - offset(r=-wall) { - children(); - } - } - } - } -} - - -// Module: extrude_2dpath_along_spiral() +// Module: spiral_sweep() // Description: // Takes a closed 2D polyline path, centered on the XY plane, and // extrudes it along a 3D spiral path of a given radius, height and twist. @@ -214,8 +184,8 @@ module extrude_2d_hollow(wall=2, height=50, twist=90, slices=60, center=undef, a // center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=BOTTOM`. // Example: // poly = [[-10,0], [-3,-5], [3,-5], [10,0], [0,-30]]; -// extrude_2dpath_along_spiral(poly, h=200, r=50, twist=1080, $fn=36); -module extrude_2dpath_along_spiral(polyline, h, r, twist=360, center=undef, anchor=BOTTOM, spin=0, orient=UP) { +// spiral_sweep(poly, h=200, r=50, twist=1080, $fn=36); +module spiral_sweep(polyline, h, r, twist=360, center=undef, anchor=BOTTOM, spin=0, orient=UP) { pline_count = len(polyline); steps = ceil(segs(r)*(twist/360)); @@ -264,7 +234,7 @@ module extrude_2dpath_along_spiral(polyline, h, r, twist=360, center=undef, anch } -// Module: extrude_2dpath_along_3dpath() +// Module: path_sweep() // Description: // Takes a closed 2D path `polyline`, centered on the XY plane, and extrudes it perpendicularly along a 3D path `path`, forming a solid. // Arguments: @@ -278,8 +248,8 @@ module extrude_2dpath_along_spiral(polyline, h, r, twist=360, center=undef, anch // [for (a=[30:30:180]) [50*cos(a)+50, 50*sin(a), 20*sin(a)]], // [for (a=[330:-30:180]) [50*cos(a)-50, 50*sin(a), 20*sin(a)]] // ); -// extrude_2dpath_along_3dpath(shape, path, ang=140); -module extrude_2dpath_along_3dpath(polyline, path, ang=0, convexity=10) { +// path_sweep(shape, path, ang=140); +module path_sweep(polyline, path, ang=0, convexity=10) { pline_count = len(polyline); path_count = len(path); @@ -311,7 +281,7 @@ module extrude_2dpath_along_3dpath(polyline, path, ang=0, convexity=10) { -// Module: extrude_2d_shapes_along_3dpath() +// Module: path_extrude() // Description: // Extrudes 2D children along a 3D polyline path. This may be slow. // Arguments: @@ -320,8 +290,8 @@ module extrude_2dpath_along_3dpath(polyline, path, ang=0, convexity=10) { // clipsize = increase if artifacts are left. Default: 1000 // Example(FlatSpin): // path = [ [0, 0, 0], [33, 33, 33], [66, 33, 40], [100, 0, 0], [150,0,0] ]; -// extrude_2d_shapes_along_3dpath(path) circle(r=10, $fn=6); -module extrude_2d_shapes_along_3dpath(path, convexity=10, clipsize=100) { +// path_extrude(path) circle(r=10, $fn=6); +module path_extrude(path, convexity=10, clipsize=100) { function polyquats(path, q=Q_Ident(), v=[0,0,1], i=0) = let( v2 = path[i+1] - path[i], ang = vector_angle(v,v2), @@ -394,7 +364,7 @@ module trace_polyline(pline, showpts=false, N=1, size=1, color="yellow") { } } if (N!=3) { - extrude_2dpath_along_3dpath(circle(d=size,$fn=sides), path3d(pline)); + path_sweep(circle(d=size,$fn=sides), path3d(pline)); } else { for (i = [0:1:len(pline)-2]) { if (N!=3 || (i%N) != 1) { diff --git a/roundcorners.scad b/roundcorners.scad index 24f6e31..b0bcb1f 100644 --- a/roundcorners.scad +++ b/roundcorners.scad @@ -141,9 +141,9 @@ include // [0.941085, 5.30548, 4.46753], [1.86054, 9.81574, 6.49753], [6.93818, 7.21163, 5.79453]]; // list2= [[1.07907, 4.74091, 6.90039], [8.77585, 4.42248, 6.65185], [5.94714, 9.17137, 6.15642], // [0.66266, 6.9563, 5.88423], [6.56454, 8.86334, 9.95311], [5.42015, 4.91874, 3.86696]]; -// extrude_2dpath_along_3dpath(regular_ngon(n=36,or=.1),round_corners(list1,closed=false, curve="smooth", type="cut", all=.65)); +// path_sweep(regular_ngon(n=36,or=.1),round_corners(list1,closed=false, curve="smooth", type="cut", all=.65)); // right(6) -// extrude_2dpath_along_3dpath(regular_ngon(n=36,or=.1),round_corners(list2,closed=false, curve="circle", type="cut", all=.75)); +// path_sweep(regular_ngon(n=36,or=.1),round_corners(list2,closed=false, curve="circle", type="cut", all=.75)); // Example(FlatSpin): Rounding a spiral with increased rounding along the length // // Construct a square spiral path in 3d // square = [[0,0],[1,0],[1,1],[0,1]]; @@ -155,7 +155,7 @@ include // rounding = [for(i=rvect) [i]]; // Needed because zip removes a list level // path3d = zip([spiral,z,rounding]); // rpath = round_corners(path3d, curve="smooth", type="joint",closed=false); -// extrude_2dpath_along_3dpath( regular_ngon(n=36, or=.1), rpath); +// path_sweep( regular_ngon(n=36, or=.1), rpath); function round_corners(path, curve, type, all=undef, closed=true) = let( default_curvature = 0.5, // default curvature for "smooth" curves diff --git a/threading.scad b/threading.scad index df33518..5a46db0 100644 --- a/threading.scad +++ b/threading.scad @@ -56,7 +56,7 @@ module thread_helix(base_d, pitch, thread_depth=undef, thread_angle=15, twist=72 idir = internal? -1 : 1; orient_and_anchor([2*r, 2*r, h], orient, anchor, spin=spin, chain=true) { difference() { - extrude_2dpath_along_spiral(pline, h=h, r=base_d/2, twist=twist*dir, $fn=segs(base_d/2), anchor=CENTER); + spiral_sweep(pline, h=h, r=base_d/2, twist=twist*dir, $fn=segs(base_d/2), anchor=CENTER); down(h/2) right(r) right(internal? thread_depth : 0) zrot(higbee*dir*idir) fwd(dir*pitch/2) cube([3*thread_depth/cos(higbee), pitch, pitch], center=true); up(h/2) zrot(twist*dir) right(r) right(internal? thread_depth : 0) zrot(-higbee*dir*idir) back(dir*pitch/2) cube([3*thread_depth/cos(higbee), pitch, pitch], center=true); } diff --git a/wiring.scad b/wiring.scad index 5652a6b..ca4352e 100644 --- a/wiring.scad +++ b/wiring.scad @@ -96,7 +96,7 @@ module wiring(path, wires, wirediam=2, rounding=10, wirenum=0, bezsteps=12) { for (i = [0:1:wires-1]) { extpath = [for (j = [0:1:n-1]) let(a=j*360/n) [r*cos(a)+offsets[i][0], r*sin(a)+offsets[i][1]]]; color(colors[(i+wirenum)%len(colors)]) { - extrude_2dpath_along_3dpath(extpath, poly); + path_sweep(extpath, poly); } } }