////////////////////////////////////////////////////////////////////// // LibFile: metalib.scad // Includes: // include ; // FileGroup: Metal // FileSummary: Metal, metalon, profile, and geometry. ////////////////////////////////////////////////////////////////////// include ; debugging = false; /* [Hidden] */ $fn=32; // Module: miter_profile() // Synopsis: Creates a miter profile // Topics: Metal // Description: // Generates a flexible battery holder for 'n' cylindrical batteries with complex features like wire channels, screw holes, and contact points. // // Continues: // This is the continues content // Side Effects: // No side effects registered // Usage: As Module // miter_profile(length,height,depth); // Arguments: // length = Length // height = Height // depth = Depth // // Example: Simple Case // miter_profile(length=200, height=30, depth=20); module miter_profile( length=200, height=30, depth=20 ) { //cube([50,50,50]); delta=1; difference() { cuboid([length,depth,height],anchor=CENTER,rounding=1); miter(); // Right Miter xflip() miter(); // Left Miter } module miter() { translate([length/2, 0, -height/2]) yrot(-45) color([0.5,0.5,0,0.5]) cube([height, depth+2*delta, height*sqrt(2)+2],anchor = CENTER+LEFT+BOT); } } //miter_profile(length=200, height=30, depth=20); /** * Miter Tubes Module * * This module generates a sequence of mitered tubes based on the provided section lengths, * with options for customizing their dimensions and unfolding their arrangement. * * Parameters: * - `sections` (array): An array of section lengths, each specifying the length of an individual tube. * Example: `[10, 20, 30]` will create three tubes of lengths 10, 20, and 30 units respectively. * * - `height` (number): The height of each tube. This value defines the dimension perpendicular * to the tube's length and depth. * * - `depth` (number): The depth of each tube. This value defines the dimension perpendicular * to the tube's length and height. * * - `unfold` (boolean, optional): Determines whether the sequence of tubes should be unfolded * for easier visualization or fabrication. When `true`, the tubes are laid out in a flat arrangement. * Defaults to `false`. * * @param quote - Display quote * * Internal Variables and Process: * - `moves` (array): Computed positions and rotations for each tube, determined by the `rotSlide` * function applied to the `sections` and `unfold` parameters. * * - Loop: Iterates through the `sections` array to position and render each tube with the following steps: * 1. Extracts the length of the current tube. * 2. Retrieves the computed translation and rotation values for the tube from the `moves` array. * 3. Logs debugging information about the current tube's dimensions and transformations. * 4. Translates and rotates the coordinate system to align with the tube's placement. * 5. Calls the `miter_tube` submodule to render the individual tube with specified dimensions. * * Submodules: * - `miter_tube`: A separate submodule (not defined here) that handles the actual geometry creation * for each tube, based on its length, height, and depth. * * Usage: * ``` * miter_tubes([10, 20, 30], height=5, depth=3, unfold=true); * ``` */ // Module: miter_tubes() // Synopsis: Generates a sequence of mitered tubes // Topics: Metal // Description: // This module generates a sequence of mitered tubes based on the provided section lengths, // with options for customizing their dimensions and unfolding their arrangement. // Arguments: // section = An array of section lengths, each specifying the length of an individual tube. Example: `[10, 20, 30]` will create three tubes of lengths 10, 20, and 30 units respectively. // heights = The height of each tube. This value defines the dimension perpendicular to the tube's length and depth. // depth = The depth of each tube. This value defines the dimension perpendicular to the tube's length and height. // --- // unfold = Determines whether the sequence of tubes should be unfolded for easier visualization or fabrication. When `true`, the tubes are laid out in a flat arrangement. Defaults to `false`. // Example: Simple Case // miter_tubes( // sections = [800,750,800], // height = 50, // depth = 50, // start=false, // end=false, // unfold = false, // quote=false // ); // Example: Unfolded and Quoted // miter_tubes( // sections = [800,750], // height = 50, // depth = 50, // unfold = true, // quote=true // ); module miter_tubes( sections, height, depth, start=true,end=true,unfold=false,quote=false){ for (index = [0:len(sections)-1]) { length = sections[index]; m = computeSectionPositions( sections, unfold )[index]; translate([m[0],m[1], m[2]]) yrot(-m[3]) { miter_tube( length, height, depth, start = index==0 ? start : true, end = index==len(sections)-1 ? end : true ); if (quote) color("Red") { dimension(length); //path = [[0,length], [length,length]]; path = [[0,-140], [length-5,-140]]; stroke(path, width=3,endcaps="arrow2",endcap_width=15); //ext1 = [[0,-140], [length-5,-140]]; ext1 = [[0,0], [0,-140-40]]; stroke(ext1, width=3); ext2 = [[length,0], [length,-140-40]]; stroke(ext2, width=3); } } } } /* miter_tubes( sections = [800,750], height = 50, depth = 50, unfold = true, quote=true ); */ /** * Creates a mitered tube with specified dimensions, wall thickness, and rounding. * * Parameters: * - `length` (number): The length of the tube along its main axis (default: 200). * - `height` (number): The height of the rectangular cross-section (default: 30). * - `depth` (number): The depth of the rectangular cross-section (default: 20). * - `rounding` (number): The rounding radius of the tube's edges (default: 2). * - `wall` (number): The thickness of the tube walls (default: 1.5). * - `start` (boolean): TRue if a miter cut should be done at the start position * - `end` (boolean): TRue if a miter cut should be done at the end position */ module miter_tube(length=200,height=30,depth=20,rounding=2,wall=1.5,start=true,end=true) { delta=1; translate([length,0,0]) difference() { left(length/2) yrot(90) rect_tube(size=[height,depth], wall=wall, h=length,rounding=rounding, anchor=[1,0,0]); if ( end ) miter(-45); // Right Miter if ( start ) translate([-length,0,0]) zrot(180) miter(-45); // Left Miter } module miter(rot) { translate([0,0,0]) yrot(rot) color([0.5,0.5,0,0.5]) cube([height, depth+2*delta, height*sqrt(2)+2],anchor=CENTER+LEFT+BOT); } } /** * Dimension * */ module dimension(value) { fwd(120) right(value/2) text(str(value),size=60,font="Saira Stencil One",halign="center"); } /** * Computes the positions and rotations for sections of a tube structure. * * Parameters: * - `v` (array): An array of section lengths. Each element represents the length of a tube segment. * - `unfold` (boolean, optional): If true, the structure is laid flat, skipping rotation increments. * Defaults to `false`. * * Returns: * - An array of 4-element arrays, each representing the position and rotation of a section in the form [x, y, z, r]: * - `x`, `y`, `z`: The computed coordinates for the section. * - `r`: The rotation angle for the section. * * Example: * computeSectionPositions([10, 20, 30], unfold=false); * // Returns computed positions and rotations for each section. */ function computeSectionPositions(sections, unfold=false) = sections == [] ? [] : assert(is_consistent(sections), "Input array is not consistent.") [ for ( x = 0, y = 0, z = 0, r = 0, idx = 0; idx < len(sections); xFactor = r == 0 ? 1 : (r == 180 ? -1 : 0), zFactor = r == 90 ? 1 : (r == 270 ? -1 : 0), x = x + sections[idx] * xFactor, z = z + sections[idx] * zFactor, r = r + (unfold ? 0 : 90), idx = idx + 1 ) [x, y, z, r] ]; //miter_tubes([400,500,600,700,800],30,20); //echo ("rotSlide",rotSlide([400,500,600,500])); if (debugging) { zrot(90) yrot(-90*0) { miter_tubes( sections = [800,750,800], height = 50, depth = 50, start=false, end=false, unfold = true, quote=true ); back(200) miter_tubes( sections = [800,750,800], height = 50, depth = 50, start=false, end=false, unfold = false, quote=false ); } }