diff --git a/drawing.scad b/drawing.scad index 85b686e..dea89a6 100644 --- a/drawing.scad +++ b/drawing.scad @@ -598,6 +598,8 @@ module dashed_stroke(path, dashpat=[3,3], width=1, closed=false) { // start = Start angle of arc. // wedge = If true, include centerpoint `cp` in output to form pie slice shape. // endpoint = If false exclude the last point (function only). Default: true +// anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). (Module only) Default: `CENTER` +// spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). (Module only) Default: `0` // Examples(2D): // arc(N=4, r=30, angle=30, wedge=true); // arc(r=30, angle=30, wedge=true); @@ -703,7 +705,7 @@ function arc(N, r, angle, d, cp, points, width, thickness, start, wedge=false, l module arc(N, r, angle, d, cp, points, width, thickness, start, wedge=false, anchor=CENTER, spin=0) { path = arc(N=N, r=r, angle=angle, d=d, cp=cp, points=points, width=width, thickness=thickness, start=start, wedge=wedge); - attachable(anchor,spin, two_d=true, path=path, extent=true) { + attachable(anchor,spin, two_d=true, path=path, extent=false) { polygon(path); children(); } diff --git a/regions.scad b/regions.scad index d5a2b28..1e453f5 100644 --- a/regions.scad +++ b/regions.scad @@ -288,6 +288,7 @@ function force_region(poly) = is_path(poly) ? [poly] : poly; // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `"origin"` // spin = Rotate this many degrees after anchor. See [spin](attachments.scad#spin). Default: `0` // cp = Centerpoint for determining intersection anchors or centering the shape. Determintes the base of the anchor vector. Can be "centroid", "mean", "box" or a 2D point. Default: "centroid" +// atype = Set to "hull" or "intersect to select anchor type. Default: "hull" // Example(2D): Displaying a region // region([circle(d=50), square(25,center=true)]); // Example(2D): Displaying a list of polygons that intersect each other, which is not a region @@ -298,13 +299,14 @@ function force_region(poly) = is_path(poly) ? [poly] : poly; // region(rgn); module region(r, anchor="origin", spin=0, cp="centroid") { + assert(in_list(atype, _ANCHOR_TYPES), "Anchor type must be \"hull\" or \"intersect\""); r = force_region(r); dummy=assert(is_region(r), "Input is not a region"); points = flatten(r); lengths = [for(path=r) len(path)]; starts = [0,each cumsum(lengths)]; paths = [for(i=idx(r)) count(s=starts[i], n=lengths[i])]; - attachable(anchor, spin, two_d=true, region=r, extent=false, cp=cp){ + attachable(anchor, spin, two_d=true, region=r, extent=atype=="hull", cp=cp){ polygon(points=points, paths=paths); children(); } @@ -646,7 +648,7 @@ module linear_sweep(region, height=1, center, twist=0, scale=1, slices, maxseg, slices=slices, maxseg=maxseg, style=style ); - attachable(anchor,spin,orient, cp=cp, vnf=vnf, extent=!anchor_isect, anchors=anchors) { + attachable(anchor,spin,orient, cp=cp, region=region, h=height, extent=atype=="hull", anchors=anchors) { vnf_polyhedron(vnf, convexity=convexity); children(); } diff --git a/skin.scad b/skin.scad index 585e781..3880f08 100644 --- a/skin.scad +++ b/skin.scad @@ -16,9 +16,9 @@ // Function&Module: skin() // Usage: As module: -// skin(profiles, slices, [z=], [refine=], [method=], [sampling=], [caps=], [closed=], [style=], [convexity=], [anchor=],[cp=],[spin=],[orient=],[extent=]) [attachments]; +// skin(profiles, slices, [z=], [refine=], [method=], [sampling=], [caps=], [closed=], [style=], [convexity=], [anchor=],[cp=],[spin=],[orient=],[atype=]) {attachments}; // Usage: As function: -// vnf = skin(profiles, slices, [z=], [refine=], [method=], [sampling=], [caps=], [closed=], [style=]); +// vnf = skin(profiles, slices, [z=], [refine=], [method=], [sampling=], [caps=], [closed=], [style=], [anchor=],[cp=],[spin=],[orient=],[atype=]); // Description: // Given a list of two or more path `profiles` in 3d space, produces faces to skin a surface between // the profiles. Optionally the first and last profiles can have endcaps, or the first and last profiles @@ -500,9 +500,9 @@ function skin(profiles, slices, refine=1, method="direct", sampling, caps, close // Function&Module: path_sweep() // Usage: As module -// path_sweep(shape, path, [method], [normal=], [closed=], [twist=], [twist_by_length=], [symmetry=], [last_normal=], [tangent=], [relaxed=], [caps=], [style=], [convexity=], [transforms=], [anchor=], [cp=], [spin=], [orient=], [extent=]) [attachments]; -// Usage: As function -// vnf = path_sweep(shape, path, [method], [normal=], [closed=], [twist=], [twist_by_length=], [symmetry=], [last_normal=], [tangent=], [relaxed=], [caps=], [style=], [convexity=], [transforms=]); +// path_sweep(shape, path, [method], [normal=], [closed=], [twist=], [twist_by_length=], [symmetry=], [last_normal=], [tangent=], [relaxed=], [caps=], [style=], [convexity=], [anchor=], [cp=], [spin=], [orient=], [atype=]) {attachments}; +// Usage: As function +// vnf = path_sweep(shape, path, [method], [normal=], [closed=], [twist=], [twist_by_length=], [symmetry=], [last_normal=], [tangent=], [relaxed=], [caps=], [style=], [transforms=], [anchor=], [cp=], [spin=], [orient=], [atype=]) {attachments}; // Description: // Takes as input a 2D polygon path, and a 2d or 3d path and constructs a polyhedron by sweeping the shape along the path. // When run as a module returns the polyhedron geometry. When run as a function returns a VNF by default or if you set `transforms=true` @@ -923,9 +923,9 @@ function path_sweep(shape, path, method="incremental", normal, closed=false, twi // Function&Module: path_sweep2d() // Usage: as module -// path_sweep2d(shape, path, [closed], [caps], [quality], [style], [convexity=], [anchor=], [spin=], [orient=], [extent=], [cp=]) [attachments]; +// path_sweep2d(shape, path, [closed], [caps], [quality], [style], [convexity=], [anchor=], [spin=], [orient=], [atype=], [cp=]) {attachments}; // Usage: as function -// vnf = path_sweep2d(shape, path, [closed], [caps], [quality], [style]); +// vnf = path_sweep2d(shape, path, [closed], [caps], [quality], [style], [anchor=], [spin=], [orient=], [atype=], [cp=]); // Description: // Takes an input 2D polygon (the shape) and a 2d path and constructs a polyhedron by sweeping the shape along the path. // When run as a module returns the polyhedron geometry. When run as a function returns a VNF. @@ -1044,9 +1044,9 @@ function _ofs_face_edge(face,firstlen,second=false) = // Function&Module: sweep() // Usage: As Module -// sweep(shape, transforms, [closed], [caps], [style], [convexity=], [anchor=], [spin=], [orient=], [extent=]) [attachments]; +// sweep(shape, transforms, [closed], [caps], [style], [convexity=], [anchor=], [spin=], [orient=], [atype=]) [attachments]; // Usage: As Function -// vnf = sweep(shape, transforms, [closed], [caps], [style]); +// vnf = sweep(shape, transforms, [closed], [caps], [style], [anchor=], [spin=], [orient=], [atype=]); // Description: // The input `shape` must be a non-self-intersecting 2D polygon or region, and `transforms` // is a list of 4x4 transformation matrices. The sweep algorithm applies each transformation in sequence