From a994011f4d86af32ecc89ddad406e6f754629cd9 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Thu, 13 Oct 2022 19:00:45 -0400 Subject: [PATCH] add scale argument to path_sweep() --- skin.scad | 131 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 63 deletions(-) diff --git a/skin.scad b/skin.scad index 01095e7..1296aa8 100644 --- a/skin.scad +++ b/skin.scad @@ -1215,6 +1215,7 @@ module spiral_sweep(poly, h, r, turns=1, higbee, center, r1, r2, d, d1, d2, higb // normal = normal vector for initializing the incremental method, or for setting normals with method="manual". Default: UP if the path makes an angle lower than 45 degrees to the xy plane, BACK otherwise. // closed = path is a closed loop. Default: false // twist = amount of twist to add in degrees. For closed sweeps must be a multiple of 360/symmetry. Default: 0 +// scale = Amount to scale the profiles. If you give a scalar the scale starts at 1 and ends at your specified value. You can also give a vector of values, one for each path point. Default: 1 (no scaling) // symmetry = symmetry of the shape when closed=true. Allows the shape to join with a 360/symmetry rotation instead of a full 360 rotation. Default: 1 // last_normal = normal to last point in the path for the "incremental" method. Constrains the orientation of the last cross section if you supply it. // uniform = if set to false then compute tangents using the uniform=false argument, which may give better results when your path is non-uniformly sampled. This argument is passed to {{path_tangents()}}. Default: true @@ -1498,12 +1499,12 @@ module spiral_sweep(poly, h, r, turns=1, higbee, center, r1, r2, d, d1, d2, higb // method="manual", normal=UP); // } -module path_sweep(shape, path, method="incremental", normal, closed, twist=0, twist_by_length=true, +module path_sweep(shape, path, method="incremental", normal, closed, twist=0, twist_by_length=true, scale=1, symmetry=1, last_normal, tangent, uniform=true, relaxed=false, caps, style="min_edge", convexity=10, anchor="origin",cp="centroid",spin=0, orient=UP, atype="hull",profiles=false,width=1) { dummy = assert(is_region(shape) || is_path(shape,2), "shape must be a 2D path or region"); - vnf = path_sweep(shape, path, method, normal, closed, twist, twist_by_length, + vnf = path_sweep(shape, path, method, normal, closed, twist, twist_by_length, scale, symmetry, last_normal, tangent, uniform, relaxed, caps, style); if (profiles){ @@ -1523,10 +1524,10 @@ module path_sweep(shape, path, method="incremental", normal, closed, twist=0, tw } -function path_sweep(shape, path, method="incremental", normal, closed, twist=0, twist_by_length=true, +function path_sweep(shape, path, method="incremental", normal, closed, twist=0, twist_by_length=true, scale=1, symmetry=1, last_normal, tangent, uniform=true, relaxed=false, caps, style="min_edge", transforms=false, anchor="origin",cp="centroid",spin=0, orient=UP, atype="hull") = - is_1region(path) ? path_sweep(shape=shape,path=path[0], method=method, normal=normal, closed=default(closed,true), + is_1region(path) ? path_sweep(shape=shape,path=path[0], method=method, normal=normal, closed=default(closed,true), scale=scale, twist=twist, twist_by_length=twist_by_length, symmetry=symmetry, last_normal=last_normal, tangent=tangent, uniform=uniform, relaxed=relaxed, caps=caps, style=style, transforms=transforms, anchor=anchor, cp=cp, spin=spin, orient=orient, atype=atype) : @@ -1555,7 +1556,10 @@ function path_sweep(shape, path, method="incremental", normal, closed, twist=0, assert(!closed || !caps, "Cannot make closed shape with caps") assert(is_undef(normal) || (is_vector(normal) && len(normal)==3) || (is_path(normal) && len(normal)==len(path) && len(normal[0])==3), "Invalid normal specified") assert(is_undef(tangent) || (is_path(tangent) && len(tangent)==len(path) && len(tangent[0])==3), "Invalid tangent specified") + assert(is_num(scale) || is_vector(scale,len(path)), str("Incompatible or invalid scale: must be a scalar or vector of length ",len(path))) let( + scale = is_num(scale) ? lerpn(1,scale,len(path)) : scale, + scale_list = [for(s=scale) scale(s),if (closed) scale(scale[0])], tangents = is_undef(tangent) ? path_tangents(path,uniform=uniform,closed=closed) : [for(t=tangent) unit(t)], normal = is_path(normal) ? [for(n=normal) unit(n)] : is_def(normal) ? unit(normal) : @@ -1563,71 +1567,72 @@ function path_sweep(shape, path, method="incremental", normal, closed, twist=0, normals = is_path(normal) ? normal : repeat(normal,len(path)), pathfrac = twist_by_length ? path_length_fractions(path, closed) : [for(i=[0:1:len(path)]) i / (len(path)-(closed?0:1))], L = len(path), - transform_list = - method=="incremental" ? - let(rotations = - [for( i = 0, - ynormal = normal - (normal * tangents[0])*tangents[0], - rotation = frame_map(y=ynormal, z=tangents[0]) - ; - i < len(tangents) + (closed?1:0) ; - rotation = i