r/openscad • • 6h ago

Assemblage de fragments tubulaires courbes

Post image
1 Upvotes

Ici, nous avons un module (pouvant être utilisé dans un "include" qui permet de créer de fragments coudés tubulaires.

On peut ainsi assembler plusieurs fragments de tubes partant en toutes directions.

En appliquant une valeur nulle (0) à la variable "tub" on obtient une suite de coudes pleins.

Dans notre exemple, on voit trois segments de tube dont le diamètre intérieur est de 0.8 ce qui équivaut à 80% du diamètre extérieur.

$fn = 80;

module TUBE(cir,ang,len,pos,tx,ty,scx,scy){
mirror([mir,0,0])
translate([tx,ty,0])
rotate([0,0,pos])
rotate_extrude(angle=ang,convexity=10){
translate([len,0])
scale([scx,scy])
difference(){
circle(r=cir);
circle(r=cir*0.8);}}}

TUBE(30, 60, 80, 50,-42,-63,1.7,1);
# TUBE(30, 60, 80,230, 60, 60,1.7,1);
TUBE(30,120,179.25,290, 25,153,1.7,1);

cir : diamètre du tube
tub : diamètre intérieur du tube
ang : valeur angulaire de 0 à 360°
len : longueur de la section
pos : position angulaire du tube
tx : positionnement sur l'axe X
ty : positionnement sur l'axe Y
scx : déformation de l'axe X du tube
scy : déformation de l'axe Y du tube

Plus d'information sur mon site 😄
https://robotix.ah-oui.org/site/main.php?found=261128-curved-tubes


r/openscad • • 6h ago

Review my OpenSCAD design for a 3D printed power bank case (32140 cell + round PCB), will it fit and print well?

Thumbnail
gallery
0 Upvotes
Hi everyone, I am learning OpenSCAD and 3D printing. I designed a round case for a DIY power bank and I would like your feedback before I print it. English is not my first language, so sorry for any mistakes.

**Parts**
- Battery: 32140 cell, 32 mm diameter x 140 mm long
- Circuit board: round power bank board, 42.5 mm diameter, 1.6 mm thick, with USB-A, USB-C, a power button and an LED display
- Screws: M2.5 x 5 mm into 4 printed standoffs

**Design**
- Body: 44 mm inside diameter, 49 mm outside diameter, 182.5 mm tall
- Battery hole: 32.8 mm (0.4 mm free on each side), with 3 small centering ribs
- 18 mm of free space above the battery for thick wires (I will fill the extra space with foam)
- 45° internal shelf and sloped rib bottoms, so I hope it prints with no supports
- 8 small rails on the outside so it does not roll
- Two friction-fit caps: top (with an LED window) and bottom
- Printer: [your printer model, max Z height]. Material: [PLA / PETG]

**My questions**
1. Will the battery and board fit with these gaps? Are my tolerances good for FDM printing?
2. Is a 0.3 mm gap on the caps good for a friction fit, or should I add a snap or a screw tab?
3. Will the ribs and shelf print without supports?
4. The body is tall and thin (182.5 mm). Will it print well, or should I print it in two parts?
5. Do you see any mistake in the code that could cause problems?


I checked the sizes by calculation only. I have not printed it yet. Code is below. Thank you for your time!

**Code:**


// =========================================================
// Final Round 32140 Power Bank (v7 - All Fixes Applied)
// Open LED Window, 45-Deg Sloped Ribs, 14mm USB-C, 360 Anti-Roll
// Use M2.5 x 5mm screws for PCB | Needs >= 185mm Printer Z-Height
// =========================================================


part_to_render = "all"; // Options: "all", "body", "top_cap", "bottom_cap"


// --- COMPONENT DIMENSIONS (mm) ---
cell_d = 32.0;
cell_l = 140.0;
cell_tol = 0.8;         // Smooth slide-in fit (32.8mm)
batt_wire_space = 18.0; // 14mm net wire room after 4mm bottom cap plug


pcb_d = 42.5;
pcb_thick = 1.6;
pcb_tol = 1.5;          // 44.0mm internal diameter


// --- ENCLOSURE PARAMETERS (mm) ---
wall = 2.5;
cap_tol = 0.3;
$fn = 80;


// --- CALCULATED DIMENSIONS ---
inner_d = pcb_d + pcb_tol;                  // 44.0mm uniform ID
outer_d = inner_d + wall * 2;               // 49.0mm uniform OD
batt_id = cell_d + cell_tol;                // 32.8mm


batt_bay_h = cell_l + batt_wire_space;      // 158.0mm
shelf_h    = 6.5;                           // 45-deg internal shelf
head_h     = 18.0;                          // Standoffs + PCB + USB-A clearance
total_h    = batt_bay_h + shelf_h + head_h; // 182.5mm total height


standoff_h = 4.5;
pcb_z      = batt_bay_h + shelf_h + standoff_h;
pcb_top_z  = pcb_z + pcb_thick;


// Verified 42.5mm PCB mounting hole coordinates (for M2.5 x 5mm screws)
hole_coords = [
    [-11.0,  15.5], // Top-Left
    [-11.0, -15.5], // Bottom-Left
    [ 18.0,   8.0], // Top-Right
    [ 18.0,  -8.0]  // Bottom-Right
];


// --- 1. MAIN BODY ---
module main_body() {
    difference() {
        union() {
            // Outer uniform cylinder
            difference() {
                cylinder(h=total_h, d=outer_d);
                translate([0, 0, -1])
                    cylinder(h=total_h + 2, d=inner_d);
            }
            
            // 8 Symmetric Anti-Roll Rails all around (zero-support 45-deg tapers)
            for (angle = [22.5 : 45 : 359]) {
                rotate([0, 0, angle])
                    translate([outer_d/2 - 0.4, 0, 0]) {
                        cylinder(h=2.0, d1=0.8, d2=3.6);
                        translate([0, 0, 2.0])
                            cylinder(h=pcb_z - 3.5, d=3.6);
                        translate([0, 0, pcb_z - 1.5])
                            cylinder(h=1.5, d1=3.6, d2=0.8);
                    }
            }
            
            // 3 Internal Battery Centering Ribs with 45-deg bottom slope (zero sagging)
            for (angle = [0, 120, 240]) {
                rotate([0, 0, angle])
                    intersection() {
                        cylinder(h=batt_bay_h + 1, d=inner_d + 1);
                        hull() {
                            // Starts flush against inner wall at z=6mm
                            translate([inner_d/2 - 0.5, -1.5, 6.0])
                                cube([1.0, 3.0, 0.5]);
                            // Reaches full rib depth at z=12mm (~45-deg slope)
                            translate([batt_id/2, -1.5, 12.0])
                                cube([(inner_d - batt_id)/2 + 0.5, 3.0, batt_bay_h - 11.0]);
                        }
                    }
            }
            
            // Internal 45-deg Tapered Shelf (zero-support overhang)
            translate([0, 0, batt_bay_h])
                difference() {
                    cylinder(h=shelf_h, d=inner_d + 1);
                    translate([0, 0, -0.5])
                        cylinder(h=shelf_h + 1, d1=inner_d, d2=31.0);
                }
        }
        
        // Wide 5.8mm x 11.8mm slot on -X side of shelf for thick 10-12 AWG wire
        translate([-19.0, 0, batt_bay_h - 1])
            hull() {
                translate([0, -3.0, 0]) cylinder(h=shelf_h + 2, d=5.8);
                translate([0,  3.0, 0]) cylinder(h=shelf_h + 2, d=5.8);
            }
            
        // --- DROP-IN SIDE CUTOUTS FOR PORTS & BUTTON ---
        // USB-A Port Slot (+Y, 90 deg)
        translate([0, outer_d/2, pcb_top_z + 6.5])
            cube([16.0, wall * 3, 14.0], center=true);
            
        // USB-C Port Slot (+X, 0 deg) - Widened to 14mm for thick cable heads
        translate([outer_d/2, 0, pcb_top_z + 6.5])
            cube([wall * 3, 14.0, 14.0], center=true);
            
        // Power Button Finger Cutout (45 deg, upper-right edge)
        rotate([0, 0, 45])
            translate([outer_d/2, 0, pcb_top_z + 6.5])
                cube([wall * 3, 11.0, 14.0], center=true);
    }
    
    // 4 PCB Mounting Standoffs (for M2.5 x 5mm screws)
    for (p = hole_coords) {
        difference() {
            translate([p[0], p[1], batt_bay_h + shelf_h])
                cylinder(h=standoff_h, d=5.2);
            translate([p[0], p[1], batt_bay_h + shelf_h - 1])
                cylinder(h=standoff_h + 2, d=2.1);
        }
    }
}


// --- 2. TOP CAP (Fully Open LED Window, Printed Upside-Down) ---
module top_cap() {
    difference() {
        union() {
            cylinder(h=wall, d=outer_d);
            translate([0, 0, wall])
                difference() {
                    cylinder(h=2.5, d=inner_d - cap_tol*2);
                    translate([0, 0, -0.5])
                        cylinder(h=3.5, d=inner_d - cap_tol*2 - 3.2);
                }
        }
        // Fully open LED Display Window ("188%") centered at [0, -11]
        translate([0, -11.0, wall/2])
            cube([15.5, 10.5, wall + 4], center=true);
    }
}


// --- 3. BOTTOM CAP (Clean Snap-In Plug) ---
module bottom_cap() {
    union() {
        cylinder(h=wall, d=outer_d);
        translate([0, 0, wall])
            difference() {
                cylinder(h=4.0, d=inner_d - cap_tol*2);
                translate([0, 0, -0.5])
                    cylinder(h=5.0, d=inner_d - cap_tol*2 - 3.6);
            }
    }
}


// --- RENDER LAYOUT ---
if (part_to_render == "all") {
    main_body();
    translate([outer_d + 12, 0, 0]) top_cap();
    translate([outer_d + 12, outer_d + 10, 0]) bottom_cap();
} else if (part_to_render == "body") {
    main_body();
} else if (part_to_render == "top_cap") {
    top_cap();
} else if (part_to_render == "bottom_cap") {
    bottom_cap();
}

// =========================================================
// Final Round 32140 Power Bank (v7 - All Fixes Applied)
// Open LED Window, 45-Deg Sloped Ribs, 14mm USB-C, 360 Anti-Roll
// Use M2.5 x 5mm screws for PCB | Needs >= 185mm Printer Z-Height
// =========================================================


part_to_render = "all"; // Options: "all", "body", "top_cap", "bottom_cap"


// --- COMPONENT DIMENSIONS (mm) ---
cell_d = 32.0;
cell_l = 140.0;
cell_tol = 0.8;         // Smooth slide-in fit (32.8mm)
batt_wire_space = 18.0; // 14mm net wire room after 4mm bottom cap plug


pcb_d = 42.5;
pcb_thick = 1.6;
pcb_tol = 1.5;          // 44.0mm internal diameter


// --- ENCLOSURE PARAMETERS (mm) ---
wall = 2.5;
cap_tol = 0.3;
$fn = 80;


// --- CALCULATED DIMENSIONS ---
inner_d = pcb_d + pcb_tol;                  // 44.0mm uniform ID
outer_d = inner_d + wall * 2;               // 49.0mm uniform OD
batt_id = cell_d + cell_tol;                // 32.8mm


batt_bay_h = cell_l + batt_wire_space;      // 158.0mm
shelf_h    = 6.5;                           // 45-deg internal shelf
head_h     = 18.0;                          // Standoffs + PCB + USB-A clearance
total_h    = batt_bay_h + shelf_h + head_h; // 182.5mm total height


standoff_h = 4.5;
pcb_z      = batt_bay_h + shelf_h + standoff_h;
pcb_top_z  = pcb_z + pcb_thick;


// Verified 42.5mm PCB mounting hole coordinates (for M2.5 x 5mm screws)
hole_coords = [
    [-11.0,  15.5], // Top-Left
    [-11.0, -15.5], // Bottom-Left
    [ 18.0,   8.0], // Top-Right
    [ 18.0,  -8.0]  // Bottom-Right
];


// --- 1. MAIN BODY ---
module main_body() {
    difference() {
        union() {
            // Outer uniform cylinder
            difference() {
                cylinder(h=total_h, d=outer_d);
                translate([0, 0, -1])
                    cylinder(h=total_h + 2, d=inner_d);
            }
            
            // 8 Symmetric Anti-Roll Rails all around (zero-support 45-deg tapers)
            for (angle = [22.5 : 45 : 359]) {
                rotate([0, 0, angle])
                    translate([outer_d/2 - 0.4, 0, 0]) {
                        cylinder(h=2.0, d1=0.8, d2=3.6);
                        translate([0, 0, 2.0])
                            cylinder(h=pcb_z - 3.5, d=3.6);
                        translate([0, 0, pcb_z - 1.5])
                            cylinder(h=1.5, d1=3.6, d2=0.8);
                    }
            }
            
            // 3 Internal Battery Centering Ribs with 45-deg bottom slope (zero sagging)
            for (angle = [0, 120, 240]) {
                rotate([0, 0, angle])
                    intersection() {
                        cylinder(h=batt_bay_h + 1, d=inner_d + 1);
                        hull() {
                            // Starts flush against inner wall at z=6mm
                            translate([inner_d/2 - 0.5, -1.5, 6.0])
                                cube([1.0, 3.0, 0.5]);
                            // Reaches full rib depth at z=12mm (~45-deg slope)
                            translate([batt_id/2, -1.5, 12.0])
                                cube([(inner_d - batt_id)/2 + 0.5, 3.0, batt_bay_h - 11.0]);
                        }
                    }
            }
            
            // Internal 45-deg Tapered Shelf (zero-support overhang)
            translate([0, 0, batt_bay_h])
                difference() {
                    cylinder(h=shelf_h, d=inner_d + 1);
                    translate([0, 0, -0.5])
                        cylinder(h=shelf_h + 1, d1=inner_d, d2=31.0);
                }
        }
        
        // Wide 5.8mm x 11.8mm slot on -X side of shelf for thick 10-12 AWG wire
        translate([-19.0, 0, batt_bay_h - 1])
            hull() {
                translate([0, -3.0, 0]) cylinder(h=shelf_h + 2, d=5.8);
                translate([0,  3.0, 0]) cylinder(h=shelf_h + 2, d=5.8);
            }
            
        // --- DROP-IN SIDE CUTOUTS FOR PORTS & BUTTON ---
        // USB-A Port Slot (+Y, 90 deg)
        translate([0, outer_d/2, pcb_top_z + 6.5])
            cube([16.0, wall * 3, 14.0], center=true);
            
        // USB-C Port Slot (+X, 0 deg) - Widened to 14mm for thick cable heads
        translate([outer_d/2, 0, pcb_top_z + 6.5])
            cube([wall * 3, 14.0, 14.0], center=true);
            
        // Power Button Finger Cutout (45 deg, upper-right edge)
        rotate([0, 0, 45])
            translate([outer_d/2, 0, pcb_top_z + 6.5])
                cube([wall * 3, 11.0, 14.0], center=true);
    }
    
    // 4 PCB Mounting Standoffs (for M2.5 x 5mm screws)
    for (p = hole_coords) {
        difference() {
            translate([p[0], p[1], batt_bay_h + shelf_h])
                cylinder(h=standoff_h, d=5.2);
            translate([p[0], p[1], batt_bay_h + shelf_h - 1])
                cylinder(h=standoff_h + 2, d=2.1);
        }
    }
}


// --- 2. TOP CAP (Fully Open LED Window, Printed Upside-Down) ---
module top_cap() {
    difference() {
        union() {
            cylinder(h=wall, d=outer_d);
            translate([0, 0, wall])
                difference() {
                    cylinder(h=2.5, d=inner_d - cap_tol*2);
                    translate([0, 0, -0.5])
                        cylinder(h=3.5, d=inner_d - cap_tol*2 - 3.2);
                }
        }
        // Fully open LED Display Window ("188%") centered at [0, -11]
        translate([0, -11.0, wall/2])
            cube([15.5, 10.5, wall + 4], center=true);
    }
}


// --- 3. BOTTOM CAP (Clean Snap-In Plug) ---
module bottom_cap() {
    union() {
        cylinder(h=wall, d=outer_d);
        translate([0, 0, wall])
            difference() {
                cylinder(h=4.0, d=inner_d - cap_tol*2);
                translate([0, 0, -0.5])
                    cylinder(h=5.0, d=inner_d - cap_tol*2 - 3.6);
            }
    }
}


// --- RENDER LAYOUT ---
if (part_to_render == "all") {
    main_body();
    translate([outer_d + 12, 0, 0]) top_cap();
    translate([outer_d + 12, outer_d + 10, 0]) bottom_cap();
} else if (part_to_render == "body") {
    main_body();
} else if (part_to_render == "top_cap") {
    top_cap();
} else if (part_to_render == "bottom_cap") {
    bottom_cap();
}

r/openscad • • 1h ago

Openscad > Fusion on Maker World in Maker Lab

Thumbnail makerworld.com
0 Upvotes

r/openscad • • 6h ago

J'ai modélisé et fait imprimer cet objet mathématique :

Post image
0 Upvotes