////////////////////////////////////////////////////////////////////// // LibFile: masks3d.scad // This file defines 3D masks for applying chamfers, roundovers, and teardrop roundovers to straight edges and circular // edges in three dimensions. // Includes: // include // FileGroup: Basic Modeling // FileSummary: 3D masks for rounding or chamfering edges and corners. // FileFootnotes: STD=Included in std.scad ////////////////////////////////////////////////////////////////////// // Section: Chamfer Masks // Module: chamfer_edge_mask() // Synopsis: Creates a shape to chamfer a 90° edge. // SynTags: Geom // Topics: Masking, Chamfers, Shapes (3D) // See Also: chamfer_corner_mask(), chamfer_cylinder_mask(), chamfer_edge_mask(), default_tag(), diff() // Usage: // chamfer_edge_mask(l|h=|length=|height=, chamfer, [excess]) [ATTACHMENTS]; // Description: // Creates a shape that can be used to chamfer a 90° edge. // Difference it from the object to be chamfered. The center of // the mask object should align exactly with the edge to be chamfered. // Arguments: // l/h/length/height = Length of mask. // chamfer = Size of chamfer. // excess = The extra amount to add to the length of the mask so that it differences away from other shapes cleanly. Default: `0.1` // --- // 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` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` // Side Effects: // Tags the children with "remove" (and hence sets `$tag`) if no tag is already set. // Example: // chamfer_edge_mask(l=50, chamfer=10); // Example: // difference() { // cube(50, anchor=BOTTOM+FRONT); // #chamfer_edge_mask(l=50, chamfer=10, orient=RIGHT); // } // Example: Masking by Attachment // diff() // cube(50, center=true) { // edge_mask(TOP+RIGHT) // #chamfer_edge_mask(l=50, chamfer=10); // } function chamfer_edge_mask(l, chamfer=1, excess=0.1, h, length, height, anchor=CENTER, spin=0, orient=UP) = no_function("chamfer_edge_mask"); module chamfer_edge_mask(l, chamfer=1, excess=0.1, h, length, height, anchor=CENTER, spin=0, orient=UP) { l = one_defined([l, h, height, length], "l,h,height,length"); default_tag("remove") { attachable(anchor,spin,orient, size=[chamfer*2, chamfer*2, l]) { cylinder(r=chamfer, h=l+excess, center=true, $fn=4); children(); } } } // Module: chamfer_corner_mask() // Synopsis: Creates a shape to chamfer a 90° corner. // SynTags: Geom // Topics: Masking, Chamfers, Shapes (3D) // See Also: chamfer_corner_mask(), chamfer_cylinder_mask(), chamfer_edge_mask(), default_tag(), diff() // Usage: // chamfer_corner_mask(chamfer) [ATTACHMENTS]; // Description: // Creates a shape that can be used to chamfer a 90° corner. // Difference it from the object to be chamfered. The center of // the mask object should align exactly with the corner to be chamfered. // Arguments: // chamfer = Size of chamfer. // --- // 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` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` // Side Effects: // Tags the children with "remove" (and hence sets `$tag`) if no tag is already set. // Example: // chamfer_corner_mask(chamfer=10); // Example: // difference() { // cuboid(50, chamfer=10, trimcorners=false); // move(25*[1,-1,1]) #chamfer_corner_mask(chamfer=10); // } // Example: Masking by Attachment // diff() // cuboid(100, chamfer=20, trimcorners=false) { // corner_mask(TOP+FWD+RIGHT) // chamfer_corner_mask(chamfer=20); // } // Example: Anchors // chamfer_corner_mask(chamfer=20) // show_anchors(); function chamfer_corner_mask(chamfer=1, anchor=CENTER, spin=0, orient=UP) = no_function("chamfer_corner_mask"); module chamfer_corner_mask(chamfer=1, anchor=CENTER, spin=0, orient=UP) { default_tag("remove") { octahedron(chamfer*4, anchor=anchor, spin=spin, orient=orient) children(); } } // Module: chamfer_cylinder_mask() // Synopsis: Creates a shape to chamfer the end of a cylinder. // SynTags: Geom // Topics: Masking, Chamfers, Cylinders // See Also: chamfer_corner_mask(), chamfer_cylinder_mask(), chamfer_edge_mask(), default_tag(), diff() // Usage: // chamfer_cylinder_mask(r|d=, chamfer, [ang], [from_end]) [ATTACHMENTS]; // Description: // Create a mask that can be used to bevel/chamfer the end of a cylindrical region. // Difference it from the end of the region to be chamfered. The center of the mask // object should align exactly with the center of the end of the cylindrical region // to be chamfered. // Arguments: // r = Radius of cylinder to chamfer. // chamfer = Size of the edge chamfered, inset from edge. // --- // d = Diameter of cylinder to chamfer. Use instead of r. // ang = Angle of chamfer in degrees from the horizontal. (Default: 45) // from_end = If true, chamfer size is measured from end of cylinder. If false, chamfer is measured outset from the radius of the cylinder. (Default: false) // 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` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` // Side Effects: // Tags the children with "remove" (and hence sets `$tag`) if no tag is already set. // Example: // difference() { // cylinder(r=50, h=100, center=true); // up(50) #chamfer_cylinder_mask(r=50, chamfer=10); // } // Example: // difference() { // cylinder(r=50, h=100, center=true); // up(50) chamfer_cylinder_mask(r=50, chamfer=10); // } // Example: Changing the chamfer angle // difference() { // cylinder(r=50, h=100, center=true); // up(50) #chamfer_cylinder_mask(r=50, chamfer=10, ang=70); // } // Example: // difference() { // cylinder(r=50, h=100, center=true); // up(50) chamfer_cylinder_mask(r=50, chamfer=10, ang=70); // } // Example: Masking by Attachment // diff() // cyl(d=100,h=40) // attach([TOP,BOT]) // tag("remove")chamfer_cylinder_mask(d=100, chamfer=10); function chamfer_cylinder_mask(r, chamfer, d, ang=45, from_end=false, anchor=CENTER, spin=0, orient=UP) = no_function("chamfer_cylinder_mask"); module chamfer_cylinder_mask(r, chamfer, d, ang=45, from_end=false, anchor=CENTER, spin=0, orient=UP) { r = get_radius(r=r, d=d, dflt=1); dummy = assert(all_nonnegative([chamfer]), "Chamfer must be a nonnegative number"); ch = from_end? chamfer : opp_ang_to_adj(chamfer,90-ang); default_tag("remove"){ attachable(anchor,spin,orient, r=r, l=ch*2) { difference() { cyl(r=r+chamfer, l=ch*2, anchor=CENTER); cyl(r=r, l=ch*3, chamfer=chamfer, chamfang=ang, from_end=from_end, anchor=TOP); } children(); } } } // Section: Rounding Masks // Module: rounding_edge_mask() // Synopsis: Creates a shape to round a 90° edge. // SynTags: Geom // Topics: Masks, Rounding, Shapes (3D) // See Also: rounding_angled_edge_mask(), rounding_corner_mask(), rounding_angled_corner_mask(), default_tag(), diff() // Usage: // rounding_edge_mask(l|h=|length=|height=, r|d=, [excess=]) [ATTACHMENTS]; // rounding_edge_mask(l|h=|length=|height=, r1=|d1=, r2=|d2=, [excess=]) [ATTACHMENTS]; // Description: // Creates a shape that can be used to round a vertical 90° edge. // Difference it from the object to be rounded. The center of the mask // object should align exactly with the edge to be rounded. // Arguments: // l/h/length/height = Length of mask. // r = Radius of the rounding. // --- // r1 = Bottom radius of rounding. // r2 = Top radius of rounding. // d = Diameter of the rounding. // d1 = Bottom diameter of rounding. // d2 = Top diameter of rounding. // excess = Extra size for the mask. Defaults: 0.1 // 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` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` // Side Effects: // Tags the children with "remove" (and hence sets `$tag`) if no tag is already set. // Example(VPD=200,VPR=[55,0,120]): // rounding_edge_mask(l=50, r1=10, r2=25); // Example: // difference() { // cube(size=100, center=false); // #rounding_edge_mask(l=100, r=25, orient=UP, anchor=BOTTOM); // } // Example: Varying Rounding Radius // difference() { // cube(size=50, center=false); // #rounding_edge_mask(l=50, r1=25, r2=10, orient=UP, anchor=BOTTOM); // } // Example: Masking by Attachment // diff() // cube(100, center=true) // edge_mask(FRONT+RIGHT) // #rounding_edge_mask(l=$parent_size.z+0.01, r=25); // Example: Multiple Masking by Attachment // diff() // cube([80,90,100], center=true) { // let(p = $parent_size*1.01) { // edge_mask(TOP) // rounding_edge_mask(l=p.z, r=25); // } // } function rounding_edge_mask(l, r, r1, r2, d, d1, d2, excess=0.1, anchor=CENTER, spin=0, orient=UP, h,height,length) = no_function("rounding_edge_mask"); module rounding_edge_mask(l, r, r1, r2, d, d1, d2, excess=0.1, anchor=CENTER, spin=0, orient=UP, h,height,length) { l = one_defined([l, h, height, length], "l,h,height,length"); r1 = get_radius(r1=r1, r=r, d1=d1, d=d, dflt=1); r2 = get_radius(r1=r2, r=r, d1=d2, d=d, dflt=1); sides = quantup(segs(max(r1,r2)),4); default_tag("remove") { attachable(anchor,spin,orient, size=[2*r1,2*r1,l], size2=[2*r2,2*r2]) { if (r10, "Length of mask must be positive") assert(is_num(angle) && angle>0 && angle<90, "Angle must be a number between 0 and 90") assert(is_num(excess)); r = get_radius(r=r, d=d, dflt=1); path = mask2d_teardrop(r=r, angle=angle, excess=excess); default_tag("remove") { linear_sweep(path, height=l, center=true, atype="bbox", anchor=anchor, spin=spin, orient=orient) children(); } } // Module: teardrop_corner_mask() // Synopsis: Creates a shape to round a 90° corner but limit the angle of overhang. // SynTags: Geom // Topics: Masking, Rounding, Shapes (3D), FDM Optimized // See Also: teardrop_corner_mask(), teardrop_edge_mask(), default_tag(), diff() // Usage: // teardrop_corner_mask(r|d=, [angle], [excess], [anchor], [spin], [orient]) [ATTACHMENTS]; // Description: // Makes an apropriate 3D corner rounding mask that keeps within `angle` degrees of vertical. // Arguments: // r = Radius of the mask rounding. // angle = Maximum angle from vertical. Default: 45 // excess = Excess mask size. Default: 0.1 // --- // d = Diameter of the mask rounding. // 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` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` // Side Effects: // Tags the children with "remove" (and hence sets `$tag`) if no tag is already set. // Example: // teardrop_corner_mask(r=20, angle=40); // Example: // diff() // cuboid([50,60,70],rounding=10,edges="Z",anchor=CENTER) { // edge_profile(BOT) // mask2d_teardrop(r=10, angle=40); // corner_mask(BOT) // teardrop_corner_mask(r=10, angle=40); // } function teardrop_corner_mask(r, angle=45, excess=0.1, d, anchor, spin, orient) = no_function("teardrop_corner_mask"); module teardrop_corner_mask(r, angle=45, excess=0.1, d, anchor=CTR, spin=0, orient=UP) { assert(is_num(angle)); assert(is_num(excess)); assert(angle>0 && angle<90); r = get_radius(r=r, d=d, dflt=1); size = (r+excess) * [1,1,1]; midpt = (r-excess)/2 * [1,1,1]; default_tag("remove") { attachable(anchor,spin,orient, size=size, offset=midpt) { difference() { translate(-[1,1,1]*excess) cube(r+excess, center=false); translate([1,1,1]*r) onion(r=r, ang=angle, orient=DOWN); } children(); } } } // vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap