From cc14ca2872f18fb99f04ca5be28634763a3f2fb9 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Tue, 28 Mar 2023 20:39:37 -0700 Subject: [PATCH] Fixed wedge/triangle shapes anchoring issues. --- shapes2d.scad | 29 +++++++++++++++++++++-------- shapes3d.scad | 33 +++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/shapes2d.scad b/shapes2d.scad index c2730d3..936618a 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -839,13 +839,20 @@ module octagon(r, d, or, od, ir, id, side, rounding=0, realign=false, align_tip, // --- // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER` // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0` +// Extra Anchors: +// hypot = Center of angled side, perpendicular to that side. // Example(2D): // right_triangle([40,30]); // Example(2D): With `center=true` // right_triangle([40,30], center=true); -// Example(2D): Anchors -// right_triangle([40,30]) -// show_anchors(); +// Example(2D): Standard Anchors +// right_triangle([80,30], center=true) +// show_anchors(custom=false); +// color([0.5,0.5,0.5,0.1]) +// square([80,30], center=true); +// Example(2D): Named Anchors +// right_triangle([80,30], center=true) +// show_anchors(std=false); function right_triangle(size=[1,1], center, anchor, spin=0) = let( size = is_num(size)? [size,size] : size, @@ -854,15 +861,21 @@ function right_triangle(size=[1,1], center, anchor, spin=0) = assert(is_vector(size,2)) assert(min(size)>0, "Must give positive size") let( - path = [ [size.x/2,-size.y/2], [-size.x/2,-size.y/2], [-size.x/2,size.y/2] ] - ) reorient(anchor,spin, two_d=true, size=[size.x,size.y], size2=0, shift=-size.x/2, p=path); + path = [ [size.x/2,-size.y/2], [-size.x/2,-size.y/2], [-size.x/2,size.y/2] ], + anchors = [ + named_anchor("hypot", CTR, unit([size.y,size.x])), + ] + ) reorient(anchor,spin, two_d=true, size=[size.x,size.y], anchors=anchors, p=path); module right_triangle(size=[1,1], center, anchor, spin=0) { size = is_num(size)? [size,size] : size; anchor = get_anchor(anchor, center, [-1,-1], [-1,-1]); check = assert(is_vector(size,2)); - path = right_triangle(size, center=true); - attachable(anchor,spin, two_d=true, size=[size.x,size.y], size2=0, shift=-size.x/2) { + path = right_triangle(size, anchor="origin"); + anchors = [ + named_anchor("hypot", CTR, unit([size.y,size.x])), + ]; + attachable(anchor,spin, two_d=true, size=[size.x,size.y], anchors=anchors) { polygon(path); children(); } @@ -1062,7 +1075,7 @@ function trapezoid(h, w1, w2, ang, shift, chamfer=0, rounding=0, flip=false, anc module trapezoid(h, w1, w2, ang, shift, chamfer=0, rounding=0, flip=false, anchor=CENTER, spin=0, atype="box", angle) { path_over = trapezoid(h=h, w1=w1, w2=w2, ang=ang, shift=shift, chamfer=chamfer, rounding=rounding, - flip=flip, angle=angle,atype=atype,_return_override=true); + flip=flip, angle=angle,atype=atype,anchor="origin",_return_override=true); path=path_over[0]; override = path_over[1]; ang = force_list(ang,2); diff --git a/shapes3d.scad b/shapes3d.scad index 0487bcb..f54553e 100644 --- a/shapes3d.scad +++ b/shapes3d.scad @@ -1111,19 +1111,35 @@ function rect_tube( // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#subsection-spin). Default: `0` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` // +// Extra Anchors: +// hypot = Center of angled wedge face, perpendicular to that face. +// hypot_left = Left side of angled wedge face, bisecting the angle between the left side and angled faces. +// hypot_right = Right side of angled wedge face, bisecting the angle between the right side and angled faces. +// // Example: Centered // wedge([20, 40, 15], center=true); // Example: *Non*-Centered // wedge([20, 40, 15]); -// Example: Standard Connectors -// wedge([20, 40, 15]) show_anchors(); +// Example: Standard Anchors +// wedge([40, 80, 30], center=true) +// show_anchors(custom=false); +// color([0.5,0.5,0.5,0.1]) +// cube([40, 80, 30], center=true); +// Example: Named Anchors +// wedge([40, 80, 30], center=true) +// show_anchors(std=false); module wedge(size=[1, 1, 1], center, anchor, spin=0, orient=UP) { size = scalar_vec3(size); anchor = get_anchor(anchor, center, -[1,1,1], -[1,1,1]); - vnf = wedge(size, center=true); - attachable(anchor,spin,orient, size=size, size2=[size.x,0], shift=[0,-size.y/2]) { + vnf = wedge(size, anchor="origin"); + anchors = [ + named_anchor("hypot", CTR, unit([0,size.z,size.y],UP)), + named_anchor("hypot_left", [-size.x/2,0,0], unit(unit([0,size.z,size.y],UP)+LEFT)), + named_anchor("hypot_right", [size.x/2,0,0], unit(unit([0,size.z,size.y],UP)+RIGHT)), + ]; + attachable(anchor,spin,orient, size=size, anchors=anchors) { if (size.z > 0) { vnf_polyhedron(vnf); } @@ -1144,9 +1160,14 @@ function wedge(size=[1,1,1], center, anchor, spin=0, orient=UP) = [0,1,2], [3,5,4], [0,3,1], [1,3,4], [1,4,2], [2,4,5], [2,5,3], [0,2,3], ], - vnf = [scale(size/2,p=pts), faces] + vnf = [scale(size/2,p=pts), faces], + anchors = [ + named_anchor("hypot", CTR, unit([0,size.z,size.y],UP)), + named_anchor("hypot_left", [-size.x/2,0,0], unit(unit([0,size.z,size.y],UP)+LEFT)), + named_anchor("hypot_right", [size.x/2,0,0], unit(unit([0,size.z,size.y],UP)+RIGHT)), + ] ) - reorient(anchor,spin,orient, size=size, size2=[size.x,0], shift=[0,-size.y/2], p=vnf); + reorient(anchor,spin,orient, size=size, anchors=anchors, p=vnf); // Section: Cylinders