////////////////////////////////////////////////////////////////////// // LibFile: shapes.scad // Common useful shapes and structured objects. // Includes: // include ////////////////////////////////////////////////////////////////////// // Section: Cuboids // Module: cuboid() // // Usage: Standard Cubes // cuboid(size, , , ); // cuboid(size, p1=, ...); // cuboid(p1=, p2=, ...); // Usage: Chamfered Cubes // cuboid(size, , , , , ...); // Usage: Rounded Cubes // cuboid(size, , , , , ...); // Usage: Attaching children // cuboid(size, , ...) ; // // Description: // Creates a cube or cuboid object, with optional chamfering or rounding. // Negative chamfers and roundings can be applied to create external masks, // but only apply to edges around the top or bottom faces. // // Arguments: // size = The size of the cube. // --- // chamfer = Size of chamfer, inset from sides. Default: No chamfering. // rounding = Radius of the edge rounding. Default: No rounding. // edges = Edges to chamfer/round. See the docs for [`edges()`](edges.scad#edges) to see acceptable values. Default: All edges. // except_edges = Edges to explicitly NOT chamfer/round. See the docs for [`edges()`](edges.scad#edges) to see acceptable values. Default: No edges. // trimcorners = If true, rounds or chamfers corners where three chamfered/rounded edges meet. Default: `true` // p1 = Align the cuboid's corner at `p1`, if given. Forces `anchor=ALLNEG`. // p2 = If given with `p1`, defines the cornerpoints of the cuboid. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` // spin = Rotate this many degrees around the Z axis. See [spin](attachments.scad#spin). Default: `0` // orient = Vector to rotate top towards. See [orient](attachments.scad#orient). Default: `UP` // // Example: Simple regular cube. // cuboid(40); // Example: Cube with minimum cornerpoint given. // cuboid(20, p1=[10,0,0]); // Example: Rectangular cube, with given X, Y, and Z sizes. // cuboid([20,40,50]); // Example: Cube by Opposing Corners. // cuboid(p1=[0,10,0], p2=[20,30,30]); // Example: Chamferred Edges and Corners. // cuboid([30,40,50], chamfer=5); // Example: Chamferred Edges, Untrimmed Corners. // cuboid([30,40,50], chamfer=5, trimcorners=false); // Example: Rounded Edges and Corners // cuboid([30,40,50], rounding=10); // Example: Rounded Edges, Untrimmed Corners // cuboid([30,40,50], rounding=10, trimcorners=false); // Example: Chamferring Selected Edges // cuboid([30,40,50], chamfer=5, edges=[TOP+FRONT,TOP+RIGHT,FRONT+RIGHT], $fn=24); // Example: Rounding Selected Edges // cuboid([30,40,50], rounding=5, edges=[TOP+FRONT,TOP+RIGHT,FRONT+RIGHT], $fn=24); // Example: Negative Chamferring // cuboid([30,40,50], chamfer=-5, edges=[TOP,BOT], except_edges=RIGHT, $fn=24); // Example: Negative Chamferring, Untrimmed Corners // cuboid([30,40,50], chamfer=-5, edges=[TOP,BOT], except_edges=RIGHT, trimcorners=false, $fn=24); // Example: Negative Rounding // cuboid([30,40,50], rounding=-5, edges=[TOP,BOT], except_edges=RIGHT, $fn=24); // Example: Negative Rounding, Untrimmed Corners // cuboid([30,40,50], rounding=-5, edges=[TOP,BOT], except_edges=RIGHT, trimcorners=false, $fn=24); // Example: Standard Connectors // cuboid(40) show_anchors(); module cuboid( size=[1,1,1], p1, p2, chamfer, rounding, edges=EDGES_ALL, except_edges=[], trimcorners=true, anchor=CENTER, spin=0, orient=UP ) { module corner_shape(corner) { e = corner_edges(edges, corner); cnt = sum(e); r = first_defined([chamfer, rounding, 0]); c = [min(r,size.x/2), min(r,size.y/2), min(r,size.z/2)]; c2 = vmul(corner,c/2); $fn = is_finite(chamfer)? 4 : segs(r); translate(vmul(corner, size/2-c)) { if (cnt == 0 || approx(r,0)) { translate(c2) cube(c, center=true); } else if (cnt == 1) { if (e.x) right(c2.x) xcyl(l=c.x, r=r); if (e.y) back (c2.y) ycyl(l=c.y, r=r); if (e.z) up (c2.z) zcyl(l=c.z, r=r); } else if (cnt == 2) { if (!e.x) { intersection() { ycyl(l=c.y*2, r=r); zcyl(l=c.z*2, r=r); } } else if (!e.y) { intersection() { xcyl(l=c.x*2, r=r); zcyl(l=c.z*2, r=r); } } else { intersection() { xcyl(l=c.x*2, r=r); ycyl(l=c.y*2, r=r); } } } else { if (trimcorners) { spheroid(r=r, style="octa"); } else { intersection() { xcyl(l=c.x*2, r=r); ycyl(l=c.y*2, r=r); zcyl(l=c.z*2, r=r); } } } } } size = scalar_vec3(size); edges = edges(edges, except=except_edges); assert(is_vector(size,3)); assert(is_undef(chamfer) || is_finite(chamfer)); assert(is_undef(rounding) || is_finite(rounding)); assert(is_undef(p1) || is_vector(p1)); assert(is_undef(p2) || is_vector(p2)); assert(is_bool(trimcorners)); if (!is_undef(p1)) { if (!is_undef(p2)) { translate(pointlist_bounds([p1,p2])[0]) { cuboid(size=vabs(p2-p1), chamfer=chamfer, rounding=rounding, edges=edges, trimcorners=trimcorners, anchor=ALLNEG) children(); } } else { translate(p1) { cuboid(size=size, chamfer=chamfer, rounding=rounding, edges=edges, trimcorners=trimcorners, anchor=ALLNEG) children(); } } } else { if (is_finite(chamfer)) { if (any(edges[0])) assert(chamfer <= size.y/2 && chamfer <=size.z/2, "chamfer must be smaller than half the cube length or height."); if (any(edges[1])) assert(chamfer <= size.x/2 && chamfer <=size.z/2, "chamfer must be smaller than half the cube width or height."); if (any(edges[2])) assert(chamfer <= size.x/2 && chamfer <=size.y/2, "chamfer must be smaller than half the cube width or length."); } if (is_finite(rounding)) { if (any(edges[0])) assert(rounding <= size.y/2 && rounding<=size.z/2, "rounding radius must be smaller than half the cube length or height."); if (any(edges[1])) assert(rounding <= size.x/2 && rounding<=size.z/2, "rounding radius must be smaller than half the cube width or height."); if (any(edges[2])) assert(rounding <= size.x/2 && rounding<=size.y/2, "rounding radius must be smaller than half the cube width or length."); } majrots = [[0,90,0], [90,0,0], [0,0,0]]; attachable(anchor,spin,orient, size=size) { if (is_finite(chamfer) && !approx(chamfer,0)) { if (edges == EDGES_ALL && trimcorners) { if (chamfer<0) { cube(size, center=true) { attach(TOP,overlap=0) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP); attach(BOT,overlap=0) prismoid([size.x,size.y], [size.x-2*chamfer,size.y-2*chamfer], h=-chamfer, anchor=TOP); } } else { isize = [for (v = size) max(0.001, v-2*chamfer)]; hull() { cube([ size.x, isize.y, isize.z], center=true); cube([isize.x, size.y, isize.z], center=true); cube([isize.x, isize.y, size.z], center=true); } } } else if (chamfer<0) { assert(edges == EDGES_ALL || edges[2] == [0,0,0,0], "Cannot use negative chamfer with Z aligned edges."); ach = abs(chamfer); cube(size, center=true); // External-Chamfer mask edges difference() { union() { for (i = [0:3], axis=[0:1]) { if (edges[axis][i]>0) { vec = EDGE_OFFSETS[axis][i]; translate(vmul(vec/2, size+[ach,ach,-ach])) { rotate(majrots[axis]) { cube([ach, ach, size[axis]], center=true); } } } } // Add multi-edge corners. if (trimcorners) { for (za=[-1,1], ya=[-1,1], xa=[-1,1]) { ce = corner_edges(edges, [xa,ya,za]); if (ce.x + ce.y > 1) { translate(vmul([xa,ya,za]/2, size+[ach-0.01,ach-0.01,-ach])) { cube([ach+0.01,ach+0.01,ach], center=true); } } } } } // Remove bevels from overhangs. for (i = [0:3], axis=[0:1]) { if (edges[axis][i]>0) { vec = EDGE_OFFSETS[axis][i]; translate(vmul(vec/2, size+[2*ach,2*ach,-2*ach])) { rotate(majrots[axis]) { zrot(45) cube([ach*sqrt(2), ach*sqrt(2), size[axis]+2.1*ach], center=true); } } } } } } else { hull() { corner_shape([-1,-1,-1]); corner_shape([ 1,-1,-1]); corner_shape([-1, 1,-1]); corner_shape([ 1, 1,-1]); corner_shape([-1,-1, 1]); corner_shape([ 1,-1, 1]); corner_shape([-1, 1, 1]); corner_shape([ 1, 1, 1]); } } } else if (is_finite(rounding) && !approx(rounding,0)) { sides = quantup(segs(rounding),4); if (edges == EDGES_ALL) { if(rounding<0) { cube(size, center=true); zflip_copy() { up(size.z/2) { difference() { down(-rounding/2) cube([size.x-2*rounding, size.y-2*rounding, -rounding], center=true); down(-rounding) { ycopies(size.y-2*rounding) xcyl(l=size.x-3*rounding, r=-rounding); xcopies(size.x-2*rounding) ycyl(l=size.y-3*rounding, r=-rounding); } } } } } else { isize = [for (v = size) max(0.001, v-2*rounding)]; minkowski() { cube(isize, center=true); if (trimcorners) { spheroid(r=rounding, style="octa", $fn=sides); } else { intersection() { cyl(r=rounding, h=rounding*2, $fn=sides); rotate([90,0,0]) cyl(r=rounding, h=rounding*2, $fn=sides); rotate([0,90,0]) cyl(r=rounding, h=rounding*2, $fn=sides); } } } } } else if (rounding<0) { assert(edges == EDGES_ALL || edges[2] == [0,0,0,0], "Cannot use negative rounding with Z aligned edges."); ard = abs(rounding); cube(size, center=true); // External-Rounding mask edges difference() { union() { for (i = [0:3], axis=[0:1]) { if (edges[axis][i]>0) { vec = EDGE_OFFSETS[axis][i]; translate(vmul(vec/2, size+[ard,ard,-ard])) { rotate(majrots[axis]) { cube([ard, ard, size[axis]], center=true); } } } } // Add multi-edge corners. if (trimcorners) { for (za=[-1,1], ya=[-1,1], xa=[-1,1]) { ce = corner_edges(edges, [xa,ya,za]); if (ce.x + ce.y > 1) { translate(vmul([xa,ya,za]/2, size+[ard-0.01,ard-0.01,-ard])) { cube([ard+0.01,ard+0.01,ard], center=true); } } } } } // Remove roundings from overhangs. for (i = [0:3], axis=[0:1]) { if (edges[axis][i]>0) { vec = EDGE_OFFSETS[axis][i]; translate(vmul(vec/2, size+[2*ard,2*ard,-2*ard])) { rotate(majrots[axis]) { cyl(l=size[axis]+2.1*ard, r=ard); } } } } } } else { hull() { corner_shape([-1,-1,-1]); corner_shape([ 1,-1,-1]); corner_shape([-1, 1,-1]); corner_shape([ 1, 1,-1]); corner_shape([-1,-1, 1]); corner_shape([ 1,-1, 1]); corner_shape([-1, 1, 1]); corner_shape([ 1, 1, 1]); } } } else { cube(size=size, center=true); } children(); } } } function cuboid( size=[1,1,1], p1, p2, chamfer, rounding, edges=EDGES_ALL, except_edges=[], trimcorners=true, anchor=CENTER, spin=0, orient=UP ) = no_function("cuboid"); // Section: Prismoids // Function&Module: prismoid() // // Usage: Typical Prismoids // prismoid(size1, size2, h|l, , ...); // Usage: Attaching Children // prismoid(size1, size2, h|l, , ...) ; // Usage: Chamfered Prismoids // prismoid(size1, size2, h|l, , ...); // prismoid(size1, size2, h|l, , , ...); // Usage: Rounded Prismoids // prismoid(size1, size2, h|l, , ...); // prismoid(size1, size2, h|l, , , ...); // Usage: As Function // vnf = prismoid(size1, size2, h|l, , , ); // vnf = prismoid(size1, size2, h|l, , , , , ); // // Description: // Creates a rectangular prismoid shape with optional roundovers and chamfering. // You can only round or chamfer the vertical(ish) edges. For those edges, you can // specify rounding and/or chamferring per-edge, and for top and bottom separately. // Note: if using chamfers or rounding, you **must** also include the hull.scad file: // ``` // include // ``` // // Arguments: // size1 = [width, length] of the bottom end of the prism. // size2 = [width, length] of the top end of the prism. // h|l = Height of the prism. // shift = [X,Y] amount to shift the center of the top end with respect to the center of the bottom end. // --- // rounding = The roundover radius for the vertical-ish edges of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual radii for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-]. Default: 0 (no rounding) // rounding1 = The roundover radius for the bottom of the vertical-ish edges of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual radii for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-]. // rounding2 = The roundover radius for the top of the vertical-ish edges of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual radii for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-]. // chamfer = The chamfer size for the vertical-ish edges of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-]. Default: 0 (no chamfer) // chamfer1 = The chamfer size for the bottom of the vertical-ish edges of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-]. // chamfer2 = The chamfer size for the top of the vertical-ish edges of the prismoid. Requires including hull.scad. If given as a list of four numbers, gives individual chamfers for each corner, in the order [X+Y+,X-Y+,X-Y-,X+Y-]. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` // // Example: Rectangular Pyramid // prismoid([40,40], [0,0], h=20); // Example: Prism // prismoid(size1=[40,40], size2=[0,40], h=20); // Example: Truncated Pyramid // prismoid(size1=[35,50], size2=[20,30], h=20); // Example: Wedge // prismoid(size1=[60,35], size2=[30,0], h=30); // Example: Truncated Tetrahedron // prismoid(size1=[10,40], size2=[40,10], h=40); // Example: Inverted Truncated Pyramid // prismoid(size1=[15,5], size2=[30,20], h=20); // Example: Right Prism // prismoid(size1=[30,60], size2=[0,60], shift=[-15,0], h=30); // Example(FlatSpin,VPD=160,VPT=[0,0,10]): Shifting/Skewing // prismoid(size1=[50,30], size2=[20,20], h=20, shift=[15,5]); // Example: Rounding // include // prismoid(100, 80, rounding=10, h=30); // Example: Outer Chamfer Only // include // prismoid(100, 80, chamfer=5, h=30); // Example: Gradiant Rounding // include // prismoid(100, 80, rounding1=10, rounding2=0, h=30); // Example: Per Corner Rounding // include // prismoid(100, 80, rounding=[0,5,10,15], h=30); // Example: Per Corner Chamfer // include // prismoid(100, 80, chamfer=[0,5,10,15], h=30); // Example: Mixing Chamfer and Rounding // include // prismoid(100, 80, chamfer=[0,5,0,10], rounding=[5,0,10,0], h=30); // Example: Really Mixing It Up // include // prismoid( // size1=[100,80], size2=[80,60], h=20, // chamfer1=[0,5,0,10], chamfer2=[5,0,10,0], // rounding1=[5,0,10,0], rounding2=[0,5,0,10] // ); // Example(Spin,VPD=160,VPT=[0,0,10]): Standard Connectors // prismoid(size1=[50,30], size2=[20,20], h=20, shift=[15,5]) // show_anchors(); module prismoid( size1, size2, h, shift=[0,0], rounding=0, rounding1, rounding2, chamfer=0, chamfer1, chamfer2, l, center, anchor, spin=0, orient=UP ) { assert(is_num(size1) || is_vector(size1,2)); assert(is_num(size2) || is_vector(size2,2)); assert(is_num(h) || is_num(l)); assert(is_vector(shift,2)); assert(is_num(rounding) || is_vector(rounding,4), "Bad rounding argument."); assert(is_undef(rounding1) || is_num(rounding1) || is_vector(rounding1,4), "Bad rounding1 argument."); assert(is_undef(rounding2) || is_num(rounding2) || is_vector(rounding2,4), "Bad rounding2 argument."); assert(is_num(chamfer) || is_vector(chamfer,4), "Bad chamfer argument."); assert(is_undef(chamfer1) || is_num(chamfer1) || is_vector(chamfer1,4), "Bad chamfer1 argument."); assert(is_undef(chamfer2) || is_num(chamfer2) || is_vector(chamfer2,4), "Bad chamfer2 argument."); eps = pow(2,-14); size1 = is_num(size1)? [size1,size1] : size1; size2 = is_num(size2)? [size2,size2] : size2; s1 = [max(size1.x, eps), max(size1.y, eps)]; s2 = [max(size2.x, eps), max(size2.y, eps)]; rounding1 = default(rounding1, rounding); rounding2 = default(rounding2, rounding); chamfer1 = default(chamfer1, chamfer); chamfer2 = default(chamfer2, chamfer); anchor = get_anchor(anchor, center, BOT, BOT); vnf = prismoid( size1=size1, size2=size2, h=h, shift=shift, rounding=rounding, rounding1=rounding1, rounding2=rounding2, chamfer=chamfer, chamfer1=chamfer1, chamfer2=chamfer2, l=l, center=CENTER ); attachable(anchor,spin,orient, size=[s1.x,s1.y,h], size2=s2, shift=shift) { vnf_polyhedron(vnf, convexity=4); children(); } } function prismoid( size1, size2, h, shift=[0,0], rounding=0, rounding1, rounding2, chamfer=0, chamfer1, chamfer2, l, center, anchor=DOWN, spin=0, orient=UP ) = assert(is_vector(size1,2)) assert(is_vector(size2,2)) assert(is_num(h) || is_num(l)) assert(is_vector(shift,2)) assert(is_num(rounding) || is_vector(rounding,4), "Bad rounding argument.") assert(is_undef(rounding1) || is_num(rounding1) || is_vector(rounding1,4), "Bad rounding1 argument.") assert(is_undef(rounding2) || is_num(rounding2) || is_vector(rounding2,4), "Bad rounding2 argument.") assert(is_num(chamfer) || is_vector(chamfer,4), "Bad chamfer argument.") assert(is_undef(chamfer1) || is_num(chamfer1) || is_vector(chamfer1,4), "Bad chamfer1 argument.") assert(is_undef(chamfer2) || is_num(chamfer2) || is_vector(chamfer2,4), "Bad chamfer2 argument.") let( eps = pow(2,-14), h = first_defined([h,l,1]), shiftby = point3d(point2d(shift)), s1 = [max(size1.x, eps), max(size1.y, eps)], s2 = [max(size2.x, eps), max(size2.y, eps)], rounding1 = default(rounding1, rounding), rounding2 = default(rounding2, rounding), chamfer1 = default(chamfer1, chamfer), chamfer2 = default(chamfer2, chamfer), anchor = get_anchor(anchor, center, BOT, BOT), vnf = (rounding1==0 && rounding2==0 && chamfer1==0 && chamfer2==0)? ( let( corners = [[1,1],[1,-1],[-1,-1],[-1,1]] * 0.5, points = [ for (p=corners) point3d(vmul(s2,p), +h/2) + shiftby, for (p=corners) point3d(vmul(s1,p), -h/2) ], faces=[ [0,1,2], [0,2,3], [0,4,5], [0,5,1], [1,5,6], [1,6,2], [2,6,7], [2,7,3], [3,7,4], [3,4,0], [4,7,6], [4,6,5], ] ) [points, faces] ) : ( let( path1 = rect(size1, rounding=rounding1, chamfer=chamfer1, anchor=CTR), path2 = rect(size2, rounding=rounding2, chamfer=chamfer2, anchor=CTR), points = [ each path3d(path1, -h/2), each path3d(move(shiftby, p=path2), +h/2), ], faces = hull(points) ) [points, faces] ) ) reorient(anchor,spin,orient, size=[s1.x,s1.y,h], size2=s2, shift=shift, p=vnf); // Module: rect_tube() // Usage: Typical Rectangular Tubes // rect_tube(h, size, isize,
, ); // rect_tube(h, size, wall=, ); // rect_tube(h, isize=, wall=, ); // Usage: Tapering Rectangular Tubes // rect_tube(h, size1=, size2=, wall=, ...); // rect_tube(h, isize1=, isize2=, wall=, ...); // rect_tube(h, size1=, size2=, isize1=, isize2=, ...); // Usage: Chamfered // rect_tube(h, size, isize, chamfer=, ...); // rect_tube(h, size, isize, chamfer1=, chamfer2= ...); // rect_tube(h, size, isize, ichamfer=, ...); // rect_tube(h, size, isize, ichamfer1=, ichamfer2= ...); // rect_tube(h, size, isize, chamfer=, ichamfer=, ...); // Usage: Rounded // rect_tube(h, size, isize, rounding=, ...); // rect_tube(h, size, isize, rounding1=, rounding2= ...); // rect_tube(h, size, isize, irounding=, ...); // rect_tube(h, size, isize, irounding1=, irounding2= ...); // rect_tube(h, size, isize, rounding=, irounding=, ...); // Usage: Attaching Children // rect_tube(h, size, isize, ...) ; // // Description: // Creates a rectangular or prismoid tube with optional roundovers and/or chamfers. // You can only round or chamfer the vertical(ish) edges. For those edges, you can // specify rounding and/or chamferring per-edge, and for top and bottom, inside and // outside separately. // Note: if using chamfers or rounding, you **must** also include the hull.scad file: // ``` // include // ``` // Arguments: // h|l = The height or length of the rectangular tube. Default: 1 // size = The outer [X,Y] size of the rectangular tube. // isize = The inner [X,Y] size of the rectangular tube. // center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=UP`. // shift = [X,Y] amount to shift the center of the top end with respect to the center of the bottom end. // --- // wall = The thickness of the rectangular tube wall. // size1 = The [X,Y] size of the outside of the bottom of the rectangular tube. // size2 = The [X,Y] size of the outside of the top of the rectangular tube. // isize1 = The [X,Y] size of the inside of the bottom of the rectangular tube. // isize2 = The [X,Y] size of the inside of the top of the rectangular tube. // rounding = The roundover radius for the outside edges of the rectangular tube. // rounding1 = The roundover radius for the outside bottom corner of the rectangular tube. // rounding2 = The roundover radius for the outside top corner of the rectangular tube. // chamfer = The chamfer size for the outside edges of the rectangular tube. // chamfer1 = The chamfer size for the outside bottom corner of the rectangular tube. // chamfer2 = The chamfer size for the outside top corner of the rectangular tube. // irounding = The roundover radius for the inside edges of the rectangular tube. Default: Same as `rounding` // irounding1 = The roundover radius for the inside bottom corner of the rectangular tube. // irounding2 = The roundover radius for the inside top corner of the rectangular tube. // ichamfer = The chamfer size for the inside edges of the rectangular tube. Default: Same as `chamfer` // ichamfer1 = The chamfer size for the inside bottom corner of the rectangular tube. // ichamfer2 = The chamfer size for the inside top corner of the rectangular tube. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `BOTTOM` // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` // Examples: // rect_tube(size=50, wall=5, h=30); // rect_tube(size=[100,60], wall=5, h=30); // rect_tube(isize=[60,80], wall=5, h=30); // rect_tube(size=[100,60], isize=[90,50], h=30); // rect_tube(size1=[100,60], size2=[70,40], wall=5, h=30); // rect_tube(size1=[100,60], size2=[70,40], isize1=[40,20], isize2=[65,35], h=15); // Example: Outer Rounding Only // include // rect_tube(size=100, wall=5, rounding=10, irounding=0, h=30); // Example: Outer Chamfer Only // include // rect_tube(size=100, wall=5, chamfer=5, ichamfer=0, h=30); // Example: Outer Rounding, Inner Chamfer // include // rect_tube(size=100, wall=5, rounding=10, ichamfer=8, h=30); // Example: Inner Rounding, Outer Chamfer // include // rect_tube(size=100, wall=5, chamfer=10, irounding=8, h=30); // Example: Gradiant Rounding // include // rect_tube(size1=100, size2=80, wall=5, rounding1=10, rounding2=0, irounding1=8, irounding2=0, h=30); // Example: Per Corner Rounding // include // rect_tube(size=100, wall=10, rounding=[0,5,10,15], irounding=0, h=30); // Example: Per Corner Chamfer // include // rect_tube(size=100, wall=10, chamfer=[0,5,10,15], ichamfer=0, h=30); // Example: Mixing Chamfer and Rounding // include // rect_tube(size=100, wall=10, chamfer=[0,5,0,10], ichamfer=0, rounding=[5,0,10,0], irounding=0, h=30); // Example: Really Mixing It Up // include // rect_tube( // size1=[100,80], size2=[80,60], // isize1=[50,30], isize2=[70,50], h=20, // chamfer1=[0,5,0,10], ichamfer1=[0,3,0,8], // chamfer2=[5,0,10,0], ichamfer2=[3,0,8,0], // rounding1=[5,0,10,0], irounding1=[3,0,8,0], // rounding2=[0,5,0,10], irounding2=[0,3,0,8] // ); module rect_tube( h, size, isize, center, shift=[0,0], wall, size1, size2, isize1, isize2, rounding=0, rounding1, rounding2, irounding=0, irounding1, irounding2, chamfer=0, chamfer1, chamfer2, ichamfer=0, ichamfer1, ichamfer2, anchor, spin=0, orient=UP, l ) { h = one_defined([h,l],"h,l"); assert(is_num(h), "l or h argument required."); assert(is_vector(shift,2)); s1 = is_num(size1)? [size1, size1] : is_vector(size1,2)? size1 : is_num(size)? [size, size] : is_vector(size,2)? size : undef; s2 = is_num(size2)? [size2, size2] : is_vector(size2,2)? size2 : is_num(size)? [size, size] : is_vector(size,2)? size : undef; is1 = is_num(isize1)? [isize1, isize1] : is_vector(isize1,2)? isize1 : is_num(isize)? [isize, isize] : is_vector(isize,2)? isize : undef; is2 = is_num(isize2)? [isize2, isize2] : is_vector(isize2,2)? isize2 : is_num(isize)? [isize, isize] : is_vector(isize,2)? isize : undef; size1 = is_def(s1)? s1 : (is_def(wall) && is_def(is1))? (is1+2*[wall,wall]) : undef; size2 = is_def(s2)? s2 : (is_def(wall) && is_def(is2))? (is2+2*[wall,wall]) : undef; isize1 = is_def(is1)? is1 : (is_def(wall) && is_def(s1))? (s1-2*[wall,wall]) : undef; isize2 = is_def(is2)? is2 : (is_def(wall) && is_def(s2))? (s2-2*[wall,wall]) : undef; assert(wall==undef || is_num(wall)); assert(size1!=undef, "Bad size/size1 argument."); assert(size2!=undef, "Bad size/size2 argument."); assert(isize1!=undef, "Bad isize/isize1 argument."); assert(isize2!=undef, "Bad isize/isize2 argument."); assert(isize1.x < size1.x, "Inner size is larger than outer size."); assert(isize1.y < size1.y, "Inner size is larger than outer size."); assert(isize2.x < size2.x, "Inner size is larger than outer size."); assert(isize2.y < size2.y, "Inner size is larger than outer size."); anchor = get_anchor(anchor, center, BOT, BOT); attachable(anchor,spin,orient, size=[each size1, h], size2=size2, shift=shift) { diff("_H_o_L_e_") prismoid( size1, size2, h=h, shift=shift, rounding=rounding, rounding1=rounding1, rounding2=rounding2, chamfer=chamfer, chamfer1=chamfer1, chamfer2=chamfer2, anchor=CTR ) { children(); tags("_H_o_L_e_") prismoid( isize1, isize2, h=h+0.05, shift=shift, rounding=irounding, rounding1=irounding1, rounding2=irounding2, chamfer=ichamfer, chamfer1=ichamfer1, chamfer2=ichamfer2, anchor=CTR ); } children(); } } function rect_tube( h, size, isize, center, shift=[0,0], wall, size1, size2, isize1, isize2, rounding=0, rounding1, rounding2, irounding=0, irounding1, irounding2, chamfer=0, chamfer1, chamfer2, ichamfer=0, ichamfer1, ichamfer2, anchor, spin=0, orient=UP, l ) = no_function("rect_tube"); // Module: right_triangle() // // Usage: // right_triangle(size,
); // // Description: // Creates a 3D right triangular prism with the hypotenuse in the X+Y+ quadrant. // // Arguments: // size = [width, thickness, height] // center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=UP`. // --- // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `ALLNEG` // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` // // Example: Centered // right_triangle([60, 40, 10], center=true); // Example: *Non*-Centered // right_triangle([60, 40, 10]); // Example: Standard Connectors // right_triangle([60, 40, 15]) show_anchors(); module right_triangle(size=[1, 1, 1], center, anchor, spin=0, orient=UP) { size = scalar_vec3(size); anchor = get_anchor(anchor, center, ALLNEG, ALLNEG); attachable(anchor,spin,orient, size=size) { if (size.z > 0) { linear_extrude(height=size.z, convexity=2, center=true) { polygon([[-size.x/2,-size.y/2], [-size.x/2,size.y/2], [size.x/2,-size.y/2]]); } } children(); } } function right_triangle(size=[1,1,1], center, anchor, spin=0, orient=UP) = no_function("right_triangle"); // Section: Cylindroids // Module: cyl() // // Description: // Creates cylinders in various anchorings and orientations, with optional rounding and chamfers. // You can use `h` and `l` interchangably, and all variants allow specifying size by either `r`|`d`, // or `r1`|`d1` and `r2`|`d2`. Note: the chamfers and rounding cannot be cumulatively longer than // the cylinder's length. // // Usage: Normal Cylinders // cyl(l|h, r,
, , ); // cyl(l|h, d=, ...); // cyl(l|h, r1=, r2=, ...); // cyl(l|h, d1=, d2=, ...); // // Usage: Chamferred Cylinders // cyl(l|h, r|d, chamfer=, , , ...); // cyl(l|h, r|d, chamfer1=, , , ...); // cyl(l|h, r|d, chamfer2=, , , ...); // cyl(l|h, r|d, chamfer1=, chamfer2=, , , , ...); // // Usage: Rounded End Cylinders // cyl(l|h, r|d, rounding=, ...); // cyl(l|h, r|d, rounding1=, ...); // cyl(l|h, r|d, rounding2=, ...); // cyl(l|h, r|d, rounding1=, rounding2=, ...); // // Arguments: // l / h = Length of cylinder along oriented axis. Default: 1 // r = Radius of cylinder. Default: 1 // center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=DOWN`. // --- // r1 = Radius of the negative (X-, Y-, Z-) end of cylinder. // r2 = Radius of the positive (X+, Y+, Z+) end of cylinder. // d = Diameter of cylinder. // d1 = Diameter of the negative (X-, Y-, Z-) end of cylinder. // d2 = Diameter of the positive (X+, Y+, Z+) end of cylinder. // circum = If true, cylinder should circumscribe the circle of the given size. Otherwise inscribes. Default: `false` // chamfer = The size of the chamfers on the ends of the cylinder. Default: none. // chamfer1 = The size of the chamfer on the bottom end of the cylinder. Default: none. // chamfer2 = The size of the chamfer on the top end of the cylinder. Default: none. // chamfang = The angle in degrees of the chamfers on the ends of the cylinder. // chamfang1 = The angle in degrees of the chamfer on the bottom end of the cylinder. // chamfang2 = The angle in degrees of the chamfer on the top end of the cylinder. // from_end = If true, chamfer is measured from the end of the cylinder, instead of inset from the edge. Default: `false`. // rounding = The radius of the rounding on the ends of the cylinder. Default: none. // rounding1 = The radius of the rounding on the bottom end of the cylinder. // rounding2 = The radius of the rounding on the top end of the cylinder. // realign = If true, rotate the cylinder by half the angle of one face. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` // // Example: By Radius // xdistribute(30) { // cyl(l=40, r=10); // cyl(l=40, r1=10, r2=5); // } // // Example: By Diameter // xdistribute(30) { // cyl(l=40, d=25); // cyl(l=40, d1=25, d2=10); // } // // Example: Chamferring // xdistribute(60) { // // Shown Left to right. // cyl(l=40, d=40, chamfer=7); // Default chamfang=45 // cyl(l=40, d=40, chamfer=7, chamfang=30, from_end=false); // cyl(l=40, d=40, chamfer=7, chamfang=30, from_end=true); // } // // Example: Rounding // cyl(l=40, d=40, rounding=10); // // Example: Heterogenous Chamfers and Rounding // ydistribute(80) { // // Shown Front to Back. // cyl(l=40, d=40, rounding1=15, orient=UP); // cyl(l=40, d=40, chamfer2=5, orient=UP); // cyl(l=40, d=40, chamfer1=12, rounding2=10, orient=UP); // } // // Example: Putting it all together // cyl(l=40, d1=25, d2=15, chamfer1=10, chamfang1=30, from_end=true, rounding2=5); // // Example: External Chamfers // cyl(l=50, r=30, chamfer=-5, chamfang=30, $fa=1, $fs=1); // // Example: External Roundings // cyl(l=50, r=30, rounding1=-5, rounding2=5, $fa=1, $fs=1); // // Example: Standard Connectors // xdistribute(40) { // cyl(l=30, d=25) show_anchors(); // cyl(l=30, d1=25, d2=10) show_anchors(); // } // module cyl( h, r, center, l, r1, r2, d, d1, d2, chamfer, chamfer1, chamfer2, chamfang, chamfang1, chamfang2, rounding, rounding1, rounding2, circum=false, realign=false, from_end=false, anchor, spin=0, orient=UP ) { l = first_defined([l, h, 1]); _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 = segs(max(_r1,_r2)); sc = circum? 1/cos(180/sides) : 1; r1=_r1*sc; r2=_r2*sc; phi = atan2(l, r2-r1); anchor = get_anchor(anchor,center,BOT,CENTER); attachable(anchor,spin,orient, r1=r1, r2=r2, l=l) { zrot(realign? 180/sides : 0) { if (!any_defined([chamfer, chamfer1, chamfer2, rounding, rounding1, rounding2])) { cylinder(h=l, r1=r1, r2=r2, center=true, $fn=sides); } else { vang = atan2(l, r1-r2)/2; chang1 = 90-first_defined([chamfang1, chamfang, vang]); chang2 = 90-first_defined([chamfang2, chamfang, 90-vang]); cham1 = u_mul(first_defined([chamfer1, chamfer]) , (from_end? 1 : tan(chang1))); cham2 = u_mul(first_defined([chamfer2, chamfer]) , (from_end? 1 : tan(chang2))); fil1 = first_defined([rounding1, rounding]); fil2 = first_defined([rounding2, rounding]); if (chamfer != undef) { assert(chamfer <= r1, "chamfer is larger than the r1 radius of the cylinder."); assert(chamfer <= r2, "chamfer is larger than the r2 radius of the cylinder."); } if (cham1 != undef) { assert(cham1 <= r1, "chamfer1 is larger than the r1 radius of the cylinder."); } if (cham2 != undef) { assert(cham2 <= r2, "chamfer2 is larger than the r2 radius of the cylinder."); } if (rounding != undef) { assert(rounding <= r1, "rounding is larger than the r1 radius of the cylinder."); assert(rounding <= r2, "rounding is larger than the r2 radius of the cylinder."); } if (fil1 != undef) { assert(fil1 <= r1, "rounding1 is larger than the r1 radius of the cylinder."); } if (fil2 != undef) { assert(fil2 <= r2, "rounding2 is larger than the r1 radius of the cylinder."); } dy1 = abs(first_defined([cham1, fil1, 0])); dy2 = abs(first_defined([cham2, fil2, 0])); assert(dy1+dy2 <= l, "Sum of fillets and chamfer sizes must be less than the length of the cylinder."); path = concat( [[0,l/2]], !is_undef(cham2)? ( let( p1 = [r2-cham2/tan(chang2),l/2], p2 = lerp([r2,l/2],[r1,-l/2],abs(cham2)/l) ) [p1,p2] ) : !is_undef(fil2)? ( let( cn = circle_2tangents([r2-fil2,l/2], [r2,l/2], [r1,-l/2], r=abs(fil2)), ang = fil2<0? phi : phi-180, steps = ceil(abs(ang)/360*segs(abs(fil2))), step = ang/steps, pts = [for (i=[0:1:steps]) let(a=90+i*step) cn[0]+abs(fil2)*[cos(a),sin(a)]] ) pts ) : [[r2,l/2]], !is_undef(cham1)? ( let( p1 = lerp([r1,-l/2],[r2,l/2],abs(cham1)/l), p2 = [r1-cham1/tan(chang1),-l/2] ) [p1,p2] ) : !is_undef(fil1)? ( let( cn = circle_2tangents([r1-fil1,-l/2], [r1,-l/2], [r2,l/2], r=abs(fil1)), ang = fil1<0? 180-phi : -phi, steps = ceil(abs(ang)/360*segs(abs(fil1))), step = ang/steps, pts = [for (i=[0:1:steps]) let(a=(fil1<0?180:0)+(phi-90)+i*step) cn[0]+abs(fil1)*[cos(a),sin(a)]] ) pts ) : [[r1,-l/2]], [[0,-l/2]] ); rotate_extrude(convexity=2) { polygon(path); } } } children(); } } // Module: xcyl() // // Description: // Creates a cylinder oriented along the X axis. // // Usage: Typical // xcyl(l|h, r, ); // xcyl(l|h, d=, ); // xcyl(l|h, r1=|d1=, r2=|d2=, ); // Usage: Attaching Children // xcyl(l|h, r, ) ; // // Arguments: // l / h = Length of cylinder along oriented axis. Default: 1 // r = Radius of cylinder. Default: 1 // --- // r1 = Optional radius of left (X-) end of cylinder. // r2 = Optional radius of right (X+) end of cylinder. // d = Optional diameter of cylinder. (use instead of `r`) // d1 = Optional diameter of left (X-) end of cylinder. // d2 = Optional diameter of right (X+) end of cylinder. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` // // Example: By Radius // ydistribute(50) { // xcyl(l=35, r=10); // xcyl(l=35, r1=15, r2=5); // } // // Example: By Diameter // ydistribute(50) { // xcyl(l=35, d=20); // xcyl(l=35, d1=30, d2=10); // } module xcyl(h, r, d, r1, r2, d1, d2, l, anchor=CENTER) { 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); l = first_defined([l, h, 1]); attachable(anchor,0,UP, r1=r1, r2=r2, l=l, axis=RIGHT) { cyl(l=l, r1=r1, r2=r2, orient=RIGHT, anchor=CENTER); children(); } } // Module: ycyl() // // Description: // Creates a cylinder oriented along the Y axis. // // Usage: Typical // ycyl(l|h, r, ); // ycyl(l|h, d=, ); // ycyl(l|h, r1=|d1=, r2=|d2=, ); // Usage: Attaching Children // ycyl(l|h, r, ) ; // // Arguments: // l / h = Length of cylinder along oriented axis. (Default: `1.0`) // r = Radius of cylinder. // --- // r1 = Radius of front (Y-) end of cone. // r2 = Radius of back (Y+) end of one. // d = Diameter of cylinder. // d1 = Diameter of front (Y-) end of one. // d2 = Diameter of back (Y+) end of one. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` // // Example: By Radius // xdistribute(50) { // ycyl(l=35, r=10); // ycyl(l=35, r1=15, r2=5); // } // // Example: By Diameter // xdistribute(50) { // ycyl(l=35, d=20); // ycyl(l=35, d1=30, d2=10); // } module ycyl(h, r, d, r1, r2, d1, d2, l, anchor=CENTER) { 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); l = first_defined([l, h, 1]); attachable(anchor,0,UP, r1=r1, r2=r2, l=l, axis=BACK) { cyl(l=l, h=h, r1=r1, r2=r2, orient=BACK, anchor=CENTER); children(); } } // Module: zcyl() // // Description: // Creates a cylinder oriented along the Z axis. // // Usage: Typical // zcyl(l|h, r, ); // zcyl(l|h, d=, ); // zcyl(l|h, r1=|d1=, r2=|d2=, ); // Usage: Attaching Children // zcyl(l|h, r, ) ; // // Arguments: // l / h = Length of cylinder along oriented axis. (Default: 1.0) // r = Radius of cylinder. // --- // r1 = Radius of front (Y-) end of cone. // r2 = Radius of back (Y+) end of one. // d = Diameter of cylinder. // d1 = Diameter of front (Y-) end of one. // d2 = Diameter of back (Y+) end of one. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` // // Example: By Radius // xdistribute(50) { // zcyl(l=35, r=10); // zcyl(l=35, r1=15, r2=5); // } // // Example: By Diameter // xdistribute(50) { // zcyl(l=35, d=20); // zcyl(l=35, d1=30, d2=10); // } module zcyl(h, r, d, r1, r2, d1, d2, l, anchor=CENTER) { cyl(l=l, h=h, r=r, r1=r1, r2=r2, d=d, d1=d1, d2=d2, orient=UP, anchor=anchor) children(); } // Module: tube() // // Description: // Makes a hollow tube with the given outer size and wall thickness. // // Usage: Typical // tube(h|l, or, ir,
, ); // tube(h|l, or=|od=, ir=|id=, ...); // tube(h|l, ir|id, wall, ...); // tube(h|l, or|od, wall, ...); // tube(h|l, ir1|id1, ir2|id2, wall, ...); // tube(h|l, or1|od1, or2|od2, wall, ...); // tube(h|l, ir1|id1, ir2|id2, or1|od1, or2|od2, ); // Usage: Attaching Children // tube(h|l, or, ir,
) ; // // Arguments: // h / l = height of tube. Default: 1 // or = Outer radius of tube. Default: 1 // ir = Inner radius of tube. // center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=DOWN`. // --- // od = Outer diameter of tube. // id = Inner diameter of tube. // wall = horizontal thickness of tube wall. Default 0.5 // or1 = Outer radius of bottom of tube. Default: value of r) // or2 = Outer radius of top of tube. Default: value of r) // od1 = Outer diameter of bottom of tube. // od2 = Outer diameter of top of tube. // ir1 = Inner radius of bottom of tube. // ir2 = Inner radius of top of tube. // id1 = Inner diameter of bottom of tube. // id2 = Inner diameter of top of tube. // realign = If true, rotate the tube by half the angle of one face. // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` // spin = Rotate this many degrees around the Z axis after anchor. See [spin](attachments.scad#spin). Default: `0` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` // // Example: These all Produce the Same Tube // tube(h=30, or=40, wall=5); // tube(h=30, ir=35, wall=5); // tube(h=30, or=40, ir=35); // tube(h=30, od=80, id=70); // Example: These all Produce the Same Conical Tube // tube(h=30, or1=40, or2=25, wall=5); // tube(h=30, ir1=35, or2=20, wall=5); // tube(h=30, or1=40, or2=25, ir1=35, ir2=20); // Example: Circular Wedge // tube(h=30, or1=40, or2=30, ir1=20, ir2=30); // Example: Standard Connectors // tube(h=30, or=40, wall=5) show_anchors(); module tube( h, or, ir, center, od, id, wall, or1, or2, od1, od2, ir1, ir2, id1, id2, realign=false, l, anchor, spin=0, orient=UP ) { h = first_defined([h,l,1]); orr1 = get_radius(r1=or1, r=or, d1=od1, d=od, dflt=undef); orr2 = get_radius(r1=or2, r=or, d1=od2, d=od, dflt=undef); irr1 = get_radius(r1=ir1, r=ir, d1=id1, d=id, dflt=undef); irr2 = get_radius(r1=ir2, r=ir, d1=id2, d=id, dflt=undef); r1 = default(orr1, u_add(irr1,wall)); r2 = default(orr2, u_add(irr2,wall)); ir1 = default(irr1, u_sub(orr1,wall)); ir2 = default(irr2, u_sub(orr2,wall)); assert(ir1 <= r1, "Inner radius is larger than outer radius."); assert(ir2 <= r2, "Inner radius is larger than outer radius."); sides = segs(max(r1,r2)); anchor = get_anchor(anchor, center, BOT, BOT); attachable(anchor,spin,orient, r1=r1, r2=r2, l=h) { zrot(realign? 180/sides : 0) { difference() { cyl(h=h, r1=r1, r2=r2, $fn=sides) children(); cyl(h=h+0.05, r1=ir1, r2=ir2); } } children(); } } // Module: torus() // // Usage: Typical // torus(r_maj|d_maj, r_min|d_min,
, ...); // torus(or|od, ir|id, ...); // torus(r_maj|d_maj, or|od, ...); // torus(r_maj|d_maj, ir|id, ...); // torus(r_min|d_min, or|od, ...); // torus(r_min|d_min, ir|id, ...); // Usage: Attaching Children // torus(or|od, ir|id, ...) ;; // // Description: // Creates a torus shape. // // Figure(2D,Med): // module text3d(t,size=8) text(text=t,size=size,font="Helvetica", halign="center",valign="center"); // module dashcirc(r,start=0,angle=359.9,dashlen=5) let(step=360*dashlen/(2*r*PI)) for(a=[start:step:start+angle]) stroke(arc(r=r,start=a,angle=step/2)); // r = 75; r2 = 30; // down(r2+0.1) #torus(r_maj=r, r_min=r2, $fn=72); // color("blue") linear_extrude(height=0.01) { // dashcirc(r=r,start=15,angle=45); // dashcirc(r=r-r2, start=90+15, angle=60); // dashcirc(r=r+r2, start=180+45, angle=30); // dashcirc(r=r+r2, start=15, angle=30); // } // rot(240) color("blue") linear_extrude(height=0.01) { // stroke([[0,0],[r+r2,0]], endcaps="arrow2",width=2); // right(r) fwd(9) rot(-240) text3d("or",size=10); // } // rot(135) color("blue") linear_extrude(height=0.01) { // stroke([[0,0],[r-r2,0]], endcaps="arrow2",width=2); // right((r-r2)/2) back(8) rot(-135) text3d("ir",size=10); // } // rot(45) color("blue") linear_extrude(height=0.01) { // stroke([[0,0],[r,0]], endcaps="arrow2",width=2); // right(r/2) back(8) text3d("r_maj",size=9); // } // rot(30) color("blue") linear_extrude(height=0.01) { // stroke([[r,0],[r+r2,0]], endcaps="arrow2",width=2); // right(r+r2/2) fwd(8) text3d("r_min",size=7); // } // // Arguments: // r_maj = major radius of torus ring. (use with 'r_min', or 'd_min') // r_min = minor radius of torus ring. (use with 'r_maj', or 'd_maj') // center = If given, overrides `anchor`. A true value sets `anchor=CENTER`, false sets `anchor=DOWN`. // --- // d_maj = major diameter of torus ring. (use with 'r_min', or 'd_min') // d_min = minor diameter of torus ring. (use with 'r_maj', or 'd_maj') // or = outer radius of the torus. (use with 'ir', or 'id') // ir = inside radius of the torus. (use with 'or', or 'od') // od = outer diameter of the torus. (use with 'ir' or 'id') // id = inside diameter of the torus. (use with 'or' or 'od') // anchor = Translate so anchor point is at origin (0,0,0). See [anchor](attachments.scad#anchor). Default: `CENTER` // orient = Vector to rotate top towards, after spin. See [orient](attachments.scad#orient). Default: `UP` // // Example: // // These all produce the same torus. // torus(r_maj=22.5, r_min=7.5); // torus(d_maj=45, d_min=15); // torus(or=30, ir=15); // torus(od=60, id=30); // torus(d_maj=45, id=30); // torus(d_maj=45, od=60); // torus(d_min=15, id=30); // torus(d_min=15, od=60); // Example: Standard Connectors // torus(od=60, id=30) show_anchors(); module torus( r_maj, r_min, center, d_maj, d_min, or, od, ir, id, anchor, spin=0, orient=UP ) { _or = get_radius(r=or, d=od, dflt=undef); _ir = get_radius(r=ir, d=id, dflt=undef); _r_maj = get_radius(r=r_maj, d=d_maj, dflt=undef); _r_min = get_radius(r=r_min, d=d_min, dflt=undef); majrad = is_finite(_r_maj)? _r_maj : is_finite(_ir) && is_finite(_or)? (_or + _ir)/2 : is_finite(_ir) && is_finite(_r_min)? (_ir + _r_min) : is_finite(_or) && is_finite(_r_min)? (_or - _r_min) : assert(false, "Bad Parameters"); minrad = is_finite(_r_min)? _r_min : is_finite(_ir)? (majrad - _ir) : is_finite(_or)? (_or - majrad) : assert(false, "Bad Parameters"); anchor = get_anchor(anchor, center, BOT, CENTER); attachable(anchor,spin,orient, r=(majrad+minrad), l=minrad*2) { rotate_extrude(convexity=4) { right(majrad) circle(r=minrad); } children(); } } // Section: Spheroid // Function&Module: spheroid() // Usage: Typical // spheroid(r|d, ,