diff --git a/joiners.scad b/joiners.scad index e13e2b4..b6c8ebb 100644 --- a/joiners.scad +++ b/joiners.scad @@ -1,6 +1,6 @@ ////////////////////////////////////////////////////////////////////// // LibFile: joiners.scad -// Snap-together joiners. +// Modules for joining separately printed parts including screw together, snap-together and dovetails. // Includes: // include // include @@ -19,11 +19,12 @@ include // Description: // Creates a mask to clear an area so that a half_joiner can be placed there. // Usage: -// half_joiner_clear(h, w, [a], [clearance], [overlap]) +// half_joiner_clear(h, w, [a], [clearance=], [overlap=]) [ATTACHMENTS]; // Arguments: // h = Height of the joiner to clear space for. // w = Width of the joiner to clear space for. // a = Overhang angle of the joiner. +// --- // clearance = Extra width to clear. // overlap = Extra depth to clear. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER` @@ -31,6 +32,7 @@ include // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` // Example: // half_joiner_clear(); +function half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP) = no_function("half_joiner_clear"); module half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP) { dmnd_height = h*1.0; @@ -62,7 +64,7 @@ module half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, anchor=CEN // Module: half_joiner() // Usage: -// half_joiner(h, w, l, [a], [screwsize], [guides], [$slop]) +// half_joiner(h, w, l, [a], [screwsize=], [guides=], [$slop=]) [ATTACHMENTS]; // Description: // Creates a half_joiner object that can be attached to half_joiner2 object. // Arguments: @@ -70,6 +72,7 @@ module half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, anchor=CEN // w = Width of the half_joiner. // l = Length of the backing to the half_joiner. // a = Overhang angle of the half_joiner. +// --- // screwsize = Diameter of screwhole. // guides = If true, create sliding alignment guides. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER` @@ -79,6 +82,7 @@ module half_joiner_clear(h=20, w=10, a=30, clearance=0, overlap=0.01, anchor=CEN // Examples(FlatSpin,VPD=75): // half_joiner(screwsize=3); // half_joiner(h=20,w=10,l=10); +function half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP) = no_function("half_joiner"); module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP) { dmnd_height = h*1.0; @@ -141,7 +145,7 @@ module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, anchor= // Module: half_joiner2() // Usage: -// half_joiner2(h, w, l, [a], [screwsize], [guides]) +// half_joiner2(h, w, l, [a], [screwsize=], [guides=]) // Description: // Creates a half_joiner2 object that can be attached to half_joiner object. // Arguments: @@ -149,6 +153,7 @@ module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, anchor= // w = Width of the half_joiner. // l = Length of the backing to the half_joiner. // a = Overhang angle of the half_joiner. +// --- // screwsize = Diameter of screwhole. // guides = If true, create sliding alignment guides. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER` @@ -157,6 +162,7 @@ module half_joiner(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, anchor= // Examples(FlatSpin,VPD=75): // half_joiner2(screwsize=3); // half_joiner2(h=20,w=10,l=10); +function half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP) = no_function("half_joiner2"); module half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP) { dmnd_height = h*1.0; @@ -193,11 +199,12 @@ module half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, anchor // Description: // Creates a mask to clear an area so that a joiner can be placed there. // Usage: -// joiner_clear(h, w, [a], [clearance], [overlap]) +// joiner_clear(h, w, [a], [clearance=], [overlap=]) [ATTACHMENTS]; // Arguments: // h = Height of the joiner to clear space for. // w = Width of the joiner to clear space for. // a = Overhang angle of the joiner. +// --- // clearance = Extra width to clear. // overlap = Extra depth to clear. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER` @@ -205,6 +212,7 @@ module half_joiner2(h=20, w=10, l=10, a=30, screwsize=undef, guides=true, anchor // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` // Example: // joiner_clear(); +function joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP) = no_function("joiner_clear"); module joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP) { dmnd_height = h*0.5; @@ -225,7 +233,7 @@ module joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, // Module: joiner() // Usage: -// joiner(h, w, l, [a], [screwsize], [guides], [$slop]) +// joiner(h, w, l, [a], [screwsize=], [guides=], [$slop=]) [ATTACHMENTS]; // Description: // Creates a joiner object that can be attached to another joiner object. // Arguments: @@ -233,6 +241,7 @@ module joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, // w = Width of the joiner. // l = Length of the backing to the joiner. // a = Overhang angle of the joiner. +// --- // screwsize = Diameter of screwhole. // guides = If true, create sliding alignment guides. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER` @@ -242,6 +251,7 @@ module joiner_clear(h=40, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, // Examples(FlatSpin,VPD=125): // joiner(screwsize=3); // joiner(w=10, l=10, h=40); +function joiner(h=40, w=10, l=10, a=30, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP) = no_function("joiner"); module joiner(h=40, w=10, l=10, a=30, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP) { attachable(anchor,spin,orient, size=[w, 2*l, h]) { @@ -262,13 +272,14 @@ module joiner(h=40, w=10, l=10, a=30, screwsize=undef, guides=true, anchor=CENTE // Description: // Creates a mask to clear an area so that a pair of joiners can be placed there. // Usage: -// joiner_pair_clear(spacing, [n], [h], [w], [a], [clearance], [overlap]) +// joiner_pair_clear(spacing, [n], [h], [w], [a], [clearance=], [overlap=]) [ATTACHMENTS]; // Arguments: // spacing = Spacing between joiner centers. +// n = Number of joiners (2 by default) to clear for. // h = Height of the joiner to clear space for. // w = Width of the joiner to clear space for. // a = Overhang angle of the joiner. -// n = Number of joiners (2 by default) to clear for. +// --- // clearance = Extra width to clear. // overlap = Extra depth to clear. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER` @@ -277,7 +288,8 @@ module joiner(h=40, w=10, l=10, a=30, screwsize=undef, guides=true, anchor=CENTE // Examples: // joiner_pair_clear(spacing=50, n=2); // joiner_pair_clear(spacing=50, n=3); -module joiner_pair_clear(spacing=100, h=40, w=10, a=30, n=2, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP) +function joiner_pair_clear(spacing=100, n=2, h=40, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP) = no_function("joiner_pair_clear"); +module joiner_pair_clear(spacing=100, n=2, h=40, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP) { dmnd_height = h*0.5; dmnd_width = dmnd_height*tan(a); @@ -296,16 +308,17 @@ module joiner_pair_clear(spacing=100, h=40, w=10, a=30, n=2, clearance=0, overla // Module: joiner_pair() // Usage: -// joiner_pair(h, w, l, [a], [screwsize], [guides], [$slop]) +// joiner_pair(spacing, [n], h, w, l, [a], [alternate=], [screwsize=], [guides=], [$slop=]) [ATTACHMENTS]; // Description: // Creates a joiner_pair object that can be attached to other joiner_pairs . // Arguments: // spacing = Spacing between joiner centers. +// n = Number of joiners in a row. Default: 2 // h = Height of the joiners. // w = Width of the joiners. // l = Length of the backing to the joiners. // a = Overhang angle of the joiners. -// n = Number of joiners in a row. Default: 2 +// --- // alternate = If true (default), each joiner alternates it's orientation. If alternate is "alt", do opposite alternating orientations. // screwsize = Diameter of screwhole. // guides = If true, create sliding alignment guides. @@ -319,6 +332,7 @@ module joiner_pair_clear(spacing=100, h=40, w=10, a=30, n=2, clearance=0, overla // joiner_pair(spacing=50, l=10, n=3, alternate=false); // joiner_pair(spacing=50, l=10, n=3, alternate=true); // joiner_pair(spacing=50, l=10, n=3, alternate="alt"); +function joiner_pair(spacing=100, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP) = no_function("joiner_pair"); module joiner_pair(spacing=100, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP) { attachable(anchor,spin,orient, size=[spacing+w, 2*l, h]) { @@ -344,14 +358,15 @@ module joiner_pair(spacing=100, h=40, w=10, l=10, a=30, n=2, alternate=true, scr // Description: // Creates a mask to clear an area so that a pair of joiners can be placed there. // Usage: -// joiner_quad_clear(spacing, [n], [h], [w], [a], [clearance], [overlap]) +// joiner_quad_clear([xspacing|spacing1=],[yspacing|spacing2=], [n], [h], [w], [a], [clearance], [overlap]) [ATTACHMENTS]; // Arguments: -// spacing1 = Spacing between joiner centers. -// spacing2 = Spacing between back-to-back pairs/sets of joiners. +// spacing1 / xspacing = Spacing between joiner centers. +// spacing2 / yspacing = Spacing between back-to-back pairs/sets of joiners. +// n = Number of joiners in a row. Default: 2 // h = Height of the joiner to clear space for. // w = Width of the joiner to clear space for. // a = Overhang angle of the joiner. -// n = Number of joiners in a row. Default: 2 +// --- // clearance = Extra width to clear. // overlap = Extra depth to clear. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `CENTER` @@ -360,7 +375,8 @@ module joiner_pair(spacing=100, h=40, w=10, l=10, a=30, n=2, alternate=true, scr // Examples: // joiner_quad_clear(spacing1=50, spacing2=50, n=2); // joiner_quad_clear(spacing1=50, spacing2=50, n=3); -module joiner_quad_clear(xspacing=undef, yspacing=undef, spacing1=undef, spacing2=undef, n=2, h=40, w=10, a=30, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP) +function joiner_quad_clear(xspacing=undef, yspacing=undef, n=2, h=40, w=10, a=30, spacing1=undef, spacing2=undef, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP)=no_function("joiner_quad_clear"); +module joiner_quad_clear(xspacing=undef, yspacing=undef, n=2, h=40, w=10, a=30, spacing1=undef, spacing2=undef, clearance=0, overlap=0.01, anchor=CENTER, spin=0, orient=UP) { spacing1 = first_defined([spacing1, xspacing, 100]); spacing2 = first_defined([spacing2, yspacing, 50]); @@ -378,16 +394,18 @@ module joiner_quad_clear(xspacing=undef, yspacing=undef, spacing1=undef, spacing // Module: joiner_quad() // Usage: -// joiner_quad(h, w, l, [a], [screwsize], [guides], [$slop]) +// joiner_quad([xspacing|spacing1=], [yspacing|spacing2=], [n], h, w, l, [a], [alternate=], [screwsize=], [guides=], [$slop=]) [ATTACHMENTS]; // Description: // Creates a joiner_quad object that can be attached to other joiner_pairs . // Arguments: -// spacing = Spacing between joiner centers. +// spacing1 / xspacing = Spacing between joiner centers. +// spacing2 / yspacing = Spacing between back-to-back pairs/sets of joiners. +// n = Number of joiners in a row. Default: 2 // h = Height of the joiners. // w = Width of the joiners. // l = Length of the backing to the joiners. // a = Overhang angle of the joiners. -// n = Number of joiners in a row. Default: 2 +// --- // alternate = If true (default), joiners on each side alternate orientations. If alternate is "alt", do opposite alternating orientations. // screwsize = Diameter of screwhole. // guides = If true, create sliding alignment guides. @@ -401,6 +419,7 @@ module joiner_quad_clear(xspacing=undef, yspacing=undef, spacing1=undef, spacing // joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate=false); // joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate=true); // joiner_quad(spacing1=50, spacing2=50, l=10, n=3, alternate="alt"); +function joiner_quad(spacing1=undef, spacing2=undef, xspacing=undef, yspacing=undef, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP) = no_function("joiner_quad"); module joiner_quad(spacing1=undef, spacing2=undef, xspacing=undef, yspacing=undef, h=40, w=10, l=10, a=30, n=2, alternate=true, screwsize=undef, guides=true, anchor=CENTER, spin=0, orient=UP) { spacing1 = first_defined([spacing1, xspacing, 100]); @@ -421,7 +440,7 @@ module joiner_quad(spacing1=undef, spacing2=undef, xspacing=undef, yspacing=unde // Module: dovetail() // // Usage: -// dovetail(gender, w|width, h|height, slide, [slope|angle], [taper|back_width], [chamfer], [r|radius], [round], [extra], [$slop]) +// dovetail(gender, w=|width, h=|height, slide, [slope=|angle=], [taper=|back_width=], [chamfer=], [r=|radius=], [round=], [extra=], [$slop=]) // // Description: // Produces a possibly tapered dovetail joint shape to attach to or subtract from two parts you wish to join together. @@ -500,6 +519,7 @@ module joiner_quad(spacing1=undef, spacing2=undef, xspacing=undef, yspacing=unde // diff("remove") // cuboid([50,30,10]) // position(TOP+BACK) xcopies(10,5) dovetail("female", slide=10, width=7, taper=4, height=4, $tags="remove",anchor=BOTTOM+FRONT,spin=180); +function dovetail(gender, width, height, slide, h, w, angle, slope, taper, back_width, chamfer, extra=0.01, r, radius, round=false, anchor=BOTTOM, spin=0, orient) = no_function("dovetail"); module dovetail(gender, width, height, slide, h, w, angle, slope, taper, back_width, chamfer, extra=0.01, r, radius, round=false, anchor=BOTTOM, spin=0, orient) { radius = get_radius(r1=radius,r2=r); @@ -656,8 +676,8 @@ function _pin_size(size) = // Module: snap_pin() // Usage: -// snap_pin(size, [pointed], [anchor], [spin], [orient]) -// snap_pin(r|radius|d|diameter, l|length, nub_depth, snap, thickness, [clearance], [preload], [pointed], [anchor], [spin], [orient]) +// snap_pin(size, [pointed=], [anchor=], [spin=], [orient]=) [ATTACHMENTS]; +// snap_pin(r=|radius=|d=|diameter=, l=|length=, nub_depth=, snap=, thickness=, [clearance=], [preload=], [pointed=]) [ATTACHMENTS]; // Description: // Creates a snap pin that can be inserted into an appropriate socket to connect two objects together. You can choose from some standard // pin dimensions by giving a size, or you can specify all the pin geometry parameters yourself. If you use a standard size you can @@ -674,6 +694,7 @@ function _pin_size(size) = // and distributed under the Creative Commons - Attribution - Share Alike License // Arguments: // size = text string to select from a list of predefined sizes, one of "standard", "small", or "tiny". +// --- // pointed = set to true to get a pointed pin, false to get one with a rounded end. Default: true // r/radius = radius of the pin // d/diameter = diameter of the pin @@ -688,6 +709,7 @@ function _pin_size(size) = // snap_pin("standard", anchor=CENTER, orient=UP, thickness = 1, $fn=40); // Example: Pins oriented for printing // xcopies(spacing=10, n=4) snap_pin("standard", $fn=40); +function snap_pin(size,r,radius,d,diameter, l,length, nub_depth, snap, thickness, clearance=0.2, preload, pointed=true, anchor=FRONT, spin=0, orient=FRONT, center) =no_function("snap_pin"); module snap_pin(size,r,radius,d,diameter, l,length, nub_depth, snap, thickness, clearance=0.2, preload, pointed=true, anchor=FRONT, spin=0, orient=FRONT, center) { preload_default = 0.2; sizedat = _pin_size(size); @@ -724,8 +746,8 @@ module snap_pin(size,r,radius,d,diameter, l,length, nub_depth, snap, thickness, // Module: snap_pin_socket() // Usage: -// snap_pin_socket(size, [fixed], [fins], [pointed], [anchor], [spin], [orient]); -// snap_pin_socket(r|radius|d|diameter, l|length, nub_depth, snap, [fixed], [pointed], [fins], [anchor], [spin], [orient]) +// snap_pin_socket(size, [fixed=], [fins=], [pointed=], [anchor=], [spin=], [orient=]) [ATTACHMENTS]; +// snap_pin_socket(r=|radius=|d=|diameter=, l=|length=, nub_depth=, snap=, [fixed=], [pointed=], [fins=]) [ATTACHMENTS]; // Description: // Constructs a socket suitable for a snap_pin with the same parameters. If `fixed` is true then the socket has flat walls and the // pin will not rotate in the socket. If `fixed` is false then the socket is round and the pin will rotate, particularly well @@ -739,6 +761,7 @@ module snap_pin(size,r,radius,d,diameter, l,length, nub_depth, snap, thickness, // has a length of 6 and diameter of 3.2. The "tiny" pin has a length of 4 and a diameter of 2.5. // Arguments: // size = text string to select from a list of predefined sizes, one of "standard", "small", or "tiny". +// --- // pointed = set to true to get a pointed pin, false to get one with a rounded end. Default: true // r/radius = radius of the pin // d/diameter = diameter of the pin @@ -757,7 +780,8 @@ module snap_pin(size,r,radius,d,diameter, l,length, nub_depth, snap, thickness, // diff("socket") cuboid([20,20,20]) { // attach(TOP) snap_pin_socket("standard", $tags="socket"); // position(TOP+FRONT)snap_pin_socket("standard", $tags="socket"); -// } +// } +function snap_pin_socket(size, r, radius, l,length, d,diameter,nub_depth, snap, fixed=true, pointed=true, fins=false, anchor=BOTTOM, spin=0, orient=DOWN) = no_function("snap_pin_socket"); module snap_pin_socket(size, r, radius, l,length, d,diameter,nub_depth, snap, fixed=true, pointed=true, fins=false, anchor=BOTTOM, spin=0, orient=DOWN) { sizedat = _pin_size(size); radius = get_radius(r1=r,r2=radius,d1=d,d2=diameter,dflt=struct_val(sizedat,"diameter")/2); @@ -791,7 +815,7 @@ module snap_pin_socket(size, r, radius, l,length, d,diameter,nub_depth, snap, fi // Module: rabbit_clip() // Usage: -// rabbit_clip(type, length, width, snap, thickness, depth, [compression], [clearance], [lock], [lock_clearance], [splineteps], [anchor], [orient], [spin]) +// rabbit_clip(type, length, width, snap, thickness, depth, [compression=], [clearance=], [lock=], [lock_clearance=], [splineteps=], [anchor=], [orient=], [spin=]) [ATTACHMENTS]; // Description: // Creates a clip with two flexible ears to lock into a mating socket, or create a mask to produce the appropriate // mating socket. The clip can be made to insert and release easily, or to hold much better, or it can be @@ -871,6 +895,7 @@ module snap_pin_socket(size, r, radius, l,length, d,diameter,nub_depth, snap, fi // snap = depth of hollow on the side of the clip // thickness = thickness of the clip "line" // depth = amount to extrude clip (give extra room for the socket, about 0.4mm) +// --- // compression = excess width at the "ears" to lock more tightly. Default: 0.1 // clearance = extra space in the socket for easier insertion. Default: 0.1 // lock = set to true to make a locking clip that may be irreversible. Default: false @@ -920,6 +945,10 @@ module snap_pin_socket(size, r, radius, l,length, d,diameter,nub_depth, snap, fi // xscale(0.8) // zcyl(l=20,r=13.5, $tags="remove",$fn=64); // } + +function rabbit_clip(type, length, width, snap, thickness, depth, compression=0.1, clearance=.1, lock=false, lock_clearance=0, + splinesteps=8, anchor, orient, spin=0) = no_function("rabbit_clip"); + module rabbit_clip(type, length, width, snap, thickness, depth, compression=0.1, clearance=.1, lock=false, lock_clearance=0, splinesteps=8, anchor, orient, spin=0) { diff --git a/polyhedra.scad b/polyhedra.scad index 38fd491..45331fb 100644 --- a/polyhedra.scad +++ b/polyhedra.scad @@ -1,11 +1,12 @@ ////////////////////////////////////////////////////////////////////// // LibFile: polyhedra.scad -// Useful platonic, archimedian, and catalan polyhedra. +// Generate Platonic solids, Archimedian solids, Catalan polyhedra, the trapezohedron, and some stellated polyhedra. +// You can also stellate any of the polyhedra, select polyhedra by their characterics and position objects on polyhedra faces. // Includes: // include // include // FileGroup: Parts -// FileSummary: Platonic, Archimidean, Catalan, and stellated polyhedra. +// FileSummary: Platonic, Archimidean, Catalan, and stellated polyhedra ////////////////////////////////////////////////////////////////////// @@ -36,9 +37,16 @@ function _unique_groups(m) = [ // Module: regular_polyhedron() -// +// Usage: Selecting a polyhedron +// regular_polyhedron([name],[index=],[type=],[faces=],[facetype=],[hasfaces=],...) [CHILDREN]; +// Usage: Controlling the size and position of the polyhedron +// regular_polyhedron(..., [or=|r=|d=],[ir=],[mr=],[side=],[facedown=],[anchor=], ...) [CHILDREN];] +// Usage: Other options that change the polyhedron or handling of children +// regular_polyhedron(..., [draw=], [rounding=], [stellate=], [repeat=], [rotate_children=]) [CHILDREN]; +// Usage: options only for the trapezohedron +// regular_polyhedron("trapezohedron", [longside=],[h=], ...) [CHILDREN]; // Description: -// Creates a regular polyhedron with optional rounding. Children are placed on the polyhedron's faces. +// Creates a regular polyhedron with optional rounding. Children are placed on the polyhedron's faces. (Note that this is not attachable.) // . // **Selecting the polyhedron:** // You constrain the polyhedra list by specifying different characteristics, that must all be met @@ -127,22 +135,19 @@ function _unique_groups(m) = [ // faces = Number of faces. // facetype = Scalar or vector listing required type of faces as vertex count. Polyhedron must have faces of every type listed and no other types. // hasfaces = Scalar of vector list face vertex counts. Polyhedron must have at least one of the listed types of face. -// side = Length of the smallest edge of the polyhedron. Default: 1. -// ir = inner radius. Polyhedron is scaled so it has the specified inner radius. Overrides side. -// mr = middle radius. Polyhedron is scaled so it has the specified middle radius. Overrides side. -// or = outer radius. Polyhedron is scaled so it has the specified outer radius. Overrides side. -// r = outer radius. Overrides or. -// d = outer diameter. Overrides or. -// anchor = Side of the origin to anchor to. The bounding box of the polyhedron is aligned as specified. Use directional constants from `constants.scad`. Default: `CENTER` -// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=UP+BACK+RIGHT`. +// side = Length of the smallest edge of the polyhedron. Default: 1 (if no radius or diameter is given). +// ir = inner radius. Polyhedron is scaled so it has the specified inner radius. +// mr = middle radius. Polyhedron is scaled so it has the specified middle radius. +// or / r / d = outer radius. Polyhedron is scaled so it has the specified outer radius. +// anchor = Side of the origin to anchor to. The bounding box of the polyhedron is aligned as specified. Default: `CENTER` // facedown = If false display the solid in native orientation. If true orient it with a largest face down. If set to a vertex count, orient it so a face with the specified number of vertices is down. Default: true. // rounding = Specify a rounding radius for the shape. Note that depending on $fn the dimensions of the shape may have small dimensional errors. // repeat = If true then repeat the children to fill all the faces. If false use only the available children and stop. Default: true. // draw = If true then draw the polyhedron. If false, draw the children but not the polyhedron. Default: true. // rotate_children = If true then orient children normal to their associated face. If false orient children to the parent coordinate system. Default: true. -// stellate = Set to a number to erect a pyramid on every face of your polyhedron with the specified height. The height is a multiple of the side length. Default: false. -// longside = Specify the long side length for a trapezohedron. Ignored for other shapes. -// h = Specify the height of the apex for a trapezohedron. Ignored for other shapes. +// stellate = Set to a number to erect a pyramid of that height on every face of your polyhedron. The height is a multiple of the side length. Default: false. +// longside = Specify the long side length for a trapezohedron. Invalid for other shapes. +// h = Specify the height of the apex for a trapezohedron. Invalid for other shapes. // // Side Effects: // `$faceindex` - Index number of the face @@ -293,8 +298,7 @@ module regular_polyhedron( or=undef, r=undef, d=undef, - anchor=[0,0,0], - center=undef, + anchor=CENTER, rounding=0, repeat=true, facedown=true, @@ -311,7 +315,7 @@ module regular_polyhedron( hasfaces=hasfaces, side=side, ir=ir, mr=mr, or=or, r=r, d=d, - anchor=anchor, center=center, + anchor=anchor, facedown=facedown, stellate=stellate, longside=longside, h=h @@ -548,11 +552,11 @@ _stellated_polyhedra_ = [ // Function: regular_polyhedron_info() // // Usage: -// x = regular_polyhedron_info(info, ....); +// info = regular_polyhedron_info(info, ...); // // Description: // Calculate characteristics of regular polyhedra or the selection set for regular_polyhedron(). -// Invoke with the same arguments used by regular_polyhedron() and use the `info` argument to +// Invoke with the same polyhedron selection and size arguments used by {{regular_polyhedron()}} and use the `info` argument to // request the desired return value. Set `info` to: // * `"vnf"`: vnf for the selected polyhedron // * `"vertices"`: vertex list for the selected polyhedron @@ -569,6 +573,7 @@ _stellated_polyhedra_ = [ // * `"name"`: name of selected polyhedron // // Arguments: +// info = Desired information to return for the polyhedron // name = Name of polyhedron to create. // --- // index = Index to select from polyhedron list. Default: 0. @@ -576,22 +581,15 @@ _stellated_polyhedra_ = [ // faces = Number of faces. // facetype = Scalar or vector listing required type of faces as vertex count. Polyhedron must have faces of every type listed and no other types. // hasfaces = Scalar of vector list face vertex counts. Polyhedron must have at least one of the listed types of face. -// side = Length of the smallest edge of the polyhedron. Default: 1. -// ir = inner radius. Polyhedron is scaled so it has the specified inner radius. Overrides side. -// mr = middle radius. Polyhedron is scaled so it has the specified middle radius. Overrides side. -// or = outer radius. Polyhedron is scaled so it has the specified outer radius. Overrides side. -// r = outer radius. Overrides or. -// d = outer diameter. Overrides or. -// anchor = Side of the origin to anchor to. The bounding box of the polyhedron is aligned as specified. Use directional constants from `constants.scad`. Default: `CENTER` -// center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=UP+BACK+RIGHT`. +// side = Length of the smallest edge of the polyhedron. Default: 1 (if no radius or diameter is given). +// or / r / d = outer radius. Polyhedron is scaled so it has the specified outer radius or diameter. +// mr = middle radius. Polyhedron is scaled so it has the specified middle radius. +// ir = inner radius. Polyhedron is scaled so it has the specified inner radius. +// anchor = Side of the origin to anchor to. The bounding box of the polyhedron is aligned as specified. Default: `CENTER` // facedown = If false display the solid in native orientation. If true orient it with a largest face down. If set to a vertex count, orient it so a face with the specified number of vertices is down. Default: true. -// rounding = Specify a rounding radius for the shape. Note that depending on $fn the dimensions of the shape may have small dimensional errors. -// repeat = If true then repeat the children to fill all the faces. If false use only the available children and stop. Default: true. -// draw = If true then draw the polyhedron. If false, draw the children but not the polyhedron. Default: true. -// rotate_children = If true then orient children normal to their associated face. If false orient children to the parent coordinate system. Default: true. -// stellate = Set to a number to erect a pyramid on every face of your polyhedron with the specified height. The height is a multiple of the side length. Default: false. -// longside = Specify the long side length for a trapezohedron. Ignored for other shapes. -// h = Specify the height of the apex for a trapezohedron. Ignored for other shapes. +// stellate = Set to a number to erect a pyramid of that height on every face of your polyhedron. The height is a multiple of the side length. Default: false. +// longside = Specify the long side length for a trapezohedron. Invalid for other shapes. +// h = Specify the height of the apex for a trapezohedron. Invalid for other shapes. function regular_polyhedron_info( info=undef, name=undef, index=undef, type=undef, @@ -599,14 +597,13 @@ function regular_polyhedron_info( hasfaces=undef, side=undef, ir=undef, mr=undef, or=undef, r=undef, d=undef, - anchor=[0,0,0], center=undef, + anchor=CENTER, facedown=true, stellate=false, longside=undef, h=undef // special parameters for trapezohedron ) = let( - anchor = !is_undef(center) ? [0,0,0] : anchor, - argcount = num_defined([ir,mr,or,r,d]) + argcount = num_defined([side,ir,mr,or,r,d]) ) - assert(argcount<=1, "You must specify only one of 'ir', 'mr', 'or', 'r', and 'd'") + assert(argcount<=1, "You must specify only one of 'side', 'ir', 'mr', 'or', 'r', and 'd'") let( ////////////////////// //Index values into the _polyhedra_ array @@ -622,8 +619,7 @@ function regular_polyhedron_info( volume = 8, // volume of unit polyhedron (data not validated, not used right now) vertices = 9, // vertex list (in arbitrary order) ////////////////////// - r = !is_undef(d) ? d/2 : r, - or = !is_undef(r) ? r : or, + or = get_radius(r=r,r1=or,d=d), stellate_index = search([name], _stellated_polyhedra_, 1, 0)[0], name = stellate_index==[] ? name : _stellated_polyhedra_[stellate_index][1], stellate = stellate_index==[] ? stellate : _stellated_polyhedra_[stellate_index][2], @@ -667,14 +663,16 @@ function regular_polyhedron_info( ), valid_facedown = is_bool(facedown) || in_list(facedown, entry[facevertices]) ) + assert(name == "trapezohedron" || num_defined([longside,h])==0, "The 'longside' and 'h' parameters are only allowed with trapezohedrons") assert(valid_facedown,str("'facedown' set to ",facedown," but selected polygon only has faces with size(s) ",entry[facevertices])) let( - side = default(side,1), // This default setting must occur after _trapezohedron is called scalefactor = ( name=="trapezohedron" ? 1 : ( - argcount == 0? side : - !is_undef(ir)? ir/entry[in_radius] : - !is_undef(mr)? mr/entry[mid_radius] : or/entry[out_radius] + argcount == 0? 1 // Default side=1 if no size info given + : is_def(side) ? side + : is_def(ir) ? ir/entry[in_radius] + : is_def(mr) ? mr/entry[mid_radius] + : or/entry[out_radius] ) / entry[edgelen] ), face_triangles = hull(entry[vertices]), diff --git a/sliders.scad b/sliders.scad index 5f18955..a983d9f 100644 --- a/sliders.scad +++ b/sliders.scad @@ -16,11 +16,12 @@ // Description: // Creates a slider to match a V-groove rail. // Usage: -// slider(l, w, h, [base], [wall], [ang], [$slop]) +// slider(l, w, h, [base=], [wall=], [ang=], [$slop=]) [ATTACHMENTS]; // Arguments: // l = Length (long axis) of slider. // w = Width of slider. // h = Height of slider. +// --- // base = Height of slider base. // wall = Width of wall behind each side of the slider. // ang = Overhang angle for slider, to facilitate supportless printig. @@ -30,6 +31,7 @@ // $slop = The printer-specific slop value to make parts fit just right. // Example: // slider(l=30, base=10, wall=4, $slop=0.2, spin=90); +function slider(l=30, w=10, h=10, base=10, wall=5, ang=30, anchor=BOTTOM, spin=0, orient=UP) = no_function("slider"); module slider(l=30, w=10, h=10, base=10, wall=5, ang=30, anchor=BOTTOM, spin=0, orient=UP) { full_width = w + 2*wall; @@ -64,11 +66,12 @@ module slider(l=30, w=10, h=10, base=10, wall=5, ang=30, anchor=BOTTOM, spin=0, // Description: // Creates a V-groove rail. // Usage: -// rail(l, w, h, [chamfer], [ang]) +// rail(l, w, h, [chamfer=], [ang=]) [ATTACHMENTS]; // Arguments: // l = Length (long axis) of slider. // w = Width of slider. // h = Height of slider. +// --- // chamfer = Size of chamfer at end of rail. // ang = Overhang angle for slider, to facilitate supportless printig. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#subsection-anchor). Default: `BOTTOM` @@ -76,6 +79,7 @@ module slider(l=30, w=10, h=10, base=10, wall=5, ang=30, anchor=BOTTOM, spin=0, // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#subsection-orient). Default: `UP` // Example: // rail(l=100, w=10, h=10); +function rail(l=30, w=10, h=10, chamfer=1.0, ang=30, anchor=BOTTOM, spin=0, orient=UP) = no_function("rail"); module rail(l=30, w=10, h=10, chamfer=1.0, ang=30, anchor=BOTTOM, spin=0, orient=UP) { attack_ang = 30; diff --git a/utility.scad b/utility.scad index 5a92dfb..a429754 100644 --- a/utility.scad +++ b/utility.scad @@ -22,6 +22,8 @@ // Description: // Returns a string representing the type of the value. One of "undef", "boolean", "number", "nan", "string", "list", "range", "function" or "invalid". // Some malformed "ranges", like '[0:NAN:INF]' and '[0:"a":INF]', may be classified as "undef" or "invalid". +// Arguments: +// x = value whose type to check // Example: // typ = typeof(undef); // Returns: "undef" // typ = typeof(true); // Returns: "boolean" @@ -75,6 +77,8 @@ function is_type(x,types) = // See Also: typeof(), is_type(), is_str() // Description: // Returns true if `x` is not `undef`. False if `x==undef`. +// Arguments: +// x = value to check // Example: // bool = is_def(undef); // Returns: false // bool = is_def(false); // Returns: true @@ -90,6 +94,8 @@ function is_def(x) = !is_undef(x); // See Also: typeof(), is_type(), is_int(), is_def() // Description: // Returns true if `x` is a string. A shortcut for `is_string()`. +// Arguments: +// x = value to check // Example: // bool = is_str(undef); // Returns: false // bool = is_str(false); // Returns: false @@ -107,6 +113,8 @@ function is_str(x) = is_string(x); // See Also: typeof(), is_type(), is_str(), is_def() // Description: // Returns true if the given value is an integer (it is a number and it rounds to itself). +// Arguments: +// n = value to check // Example: // bool = is_int(undef); // Returns: false // bool = is_int(false); // Returns: false @@ -147,6 +155,8 @@ function all_integer(x) = // See Also: typeof(), is_type(), is_str(), is_def(), is_int() // Description: // Returns true if a given value `x` is nan, a floating point value representing "not a number". +// Arguments: +// x = value to check // Example: // bool = is_nan(undef); // Returns: false // bool = is_nan(false); // Returns: false @@ -163,6 +173,8 @@ function is_nan(x) = (x!=x); // See Also: typeof(), is_type(), is_str(), is_def(), is_int(), is_nan() // Description: // Returns true if a given value `x` is a finite number. +// Arguments: +// x = value to check // Example: // bool = is_finite(undef); // Returns: false // bool = is_finite(false); // Returns: false @@ -181,6 +193,8 @@ function is_finite(x) = is_num(x) && !is_nan(0*x); // See Also: typeof(), is_type(), is_str(), is_def(), is_int() // Description: // Returns true if its argument is a range +// Arguments: +// x = value to check // Example: // bool = is_range(undef); // Returns: false // bool = is_range(false); // Returns: false @@ -198,6 +212,8 @@ function is_range(x) = !is_list(x) && is_finite(x[0]) && is_finite(x[1]) && is_f // See Also: typeof(), is_type(), is_str(), is_def(), is_int(), is_range() // Description: // Returns true if its argument is a valid range (deprecated ranges excluded). +// Arguments: +// x = value to check // Example: // bool = is_range(undef); // Returns: false // bool = is_range(false); // Returns: false @@ -219,7 +235,7 @@ function valid_range(x) = // Description: // Returns true if OpenSCAD supports function literals, and the given item is one. // Arguments: -// x = The value to check against. +// x = The value to check // Example: // f = function (a) a==2; // bool = is_func(f); // Returns: true @@ -307,7 +323,7 @@ function is_bool_list(list, length) = // Otherwise, returns the value of `dflt`. // Arguments: // v = Value to pass through if not `undef`. -// dflt = Value to return if `v` *is* `undef`. +// dflt = Value to return if `v` *is* `undef`. Default: undef function default(v,dflt=undef) = is_undef(v)? dflt : v; @@ -321,7 +337,7 @@ function default(v,dflt=undef) = is_undef(v)? dflt : v; // If all items are `undef`, or list is empty, returns `undef`. // Arguments: // v = The list whose items are being checked. -// recursive = If true, sublists are checked recursively for defined values. The first sublist that has a defined item is returned. +// recursive = If true, sublists are checked recursively for defined values. The first sublist that has a defined item is returned. Default: false // Example: // val = first_defined([undef,7,undef,true]); // Returns: 7 function first_defined(v,recursive=false,_i=0) = @@ -396,7 +412,7 @@ function num_defined(v) = // Returns true if any item in the given array is not `undef`. // Arguments: // v = The list whose items are being checked. -// recursive = If true, any sublists are evaluated recursively. +// recursive = If true, any sublists are evaluated recursively. Default: false // Example: // bool = any_defined([undef,undef,undef]); // Returns: false // bool = any_defined([undef,42,undef]); // Returns: true @@ -415,7 +431,7 @@ function any_defined(v,recursive=false) = // Returns true if all items in the given array are not `undef`. // Arguments: // v = The list whose items are being checked. -// recursive = If true, any sublists are evaluated recursively. +// recursive = If true, any sublists are evaluated recursively. Default: false // Example: // bool = all_defined([undef,undef,undef]); // Returns: false // bool = all_defined([undef,42,undef]); // Returns: false @@ -492,7 +508,7 @@ function u_div(a,b) = // bool = any(l); // bool = any(l, func); // Requires OpenSCAD 2021.01 or later. // Requirements: -// Requires OpenSCAD 2021.01 or later to use the `func=` argument. +// Requires OpenSCAD 2021.01 or later to use the `func` argument. // Description: // Returns true if any item in list `l` evaluates as true. // Arguments: @@ -525,7 +541,7 @@ function _any_bool(l, i=0, out=false) = // bool = all(l); // bool = all(l, func); // Requires OpenSCAD 2021.01 or later. // Requirements: -// Requires OpenSCAD 2021.01 or later to use the `func=` argument. +// Requires OpenSCAD 2021.01 or later to use the `func` argument. // Description: // Returns true if all items in list `l` evaluate as true. If `func` is given a function liteal // of signature (x), returning bool, then that function literal is evaluated for each list item. @@ -823,7 +839,7 @@ function _valstr(x) = // expected = The value that was expected. // info = Extra info to print out to make the error clearer. // Example: -// assert_approx(1/3, 0.333333333333333, str("number=",1,", demon=",3)); +// assert_approx(1/3, 0.333333333333333, str("number=",1,", denom=",3)); module assert_approx(got, expected, info) { no_children($children); if (!approx(got, expected)) { @@ -874,7 +890,7 @@ module assert_equal(got, expected, info) { // Module: shape_compare() // Usage: -// shape_compare([eps]) {test_shape(); expected_shape();} +// shape_compare([eps]) {TEST_SHAPE; EXPECTED_SHAPE;} // Topics: Error Checking, Debugging, Testing // See Also: assert_approx(), assert_equal() // Description: @@ -889,6 +905,7 @@ module assert_equal(got, expected, info) { // rotate_extrude() right_half(planar=true) circle(d=100); // } module shape_compare(eps=1/1024) { + assert($children==2,"Must give exactly two children"); union() { difference() { children(0);