$fn = 64; // --- PARAMETERS --- // Dimensions of the bin's outer top rim bin_length = 150.0; bin_width = 100.0; bin_corner_radius = 10.0; // Lid configuration wall_thickness = 2.0; skirt_height = 15.0; clearance = 0.4; // Tolerance gap between bin and lid for easy fit snap_depth = 0.8; // How far the snap ridge protrudes inward to grip the bin snap_height = 5.0; // Total vertical space taken by the snap ridge profile // --- CALCULATED DIMENSIONS --- outer_l = bin_length + (2 * clearance) + (2 * wall_thickness); outer_w = bin_width + (2 * clearance) + (2 * wall_thickness); outer_h = skirt_height + wall_thickness; outer_r = bin_corner_radius + clearance + wall_thickness; inner_l = bin_length + (2 * clearance); inner_w = bin_width + (2 * clearance); inner_r = bin_corner_radius + clearance; // --- MODULES --- module rounded_box(l, w, h, r) { safe_r = max(0.01, min(r, l/2, w/2)); hull() { for(x = [-l/2 + safe_r, l/2 - safe_r]) { for(y = [-w/2 + safe_r, w/2 - safe_r]) { translate([x, y, 0]) cylinder(r=safe_r, h=h); } } } } // --- MAIN GEOMETRY --- difference() { // Main solid lid body rounded_box(outer_l, outer_w, outer_h, outer_r); // Subtract the inner cavity (bin volume + snap mechanism) union() { // 1. Main inner cavity above the snap ridge translate([0, 0, snap_height]) rounded_box(inner_l, inner_w, skirt_height - snap_height, inner_r); // 2. Top chamfer of the snap ridge (locking face) hull() { translate([0, 0, snap_height]) rounded_box(inner_l, inner_w, 0.01, inner_r); translate([0, 0, snap_height / 2]) rounded_box(inner_l - (2 * snap_depth), inner_w - (2 * snap_depth), 0.01, max(0.1, inner_r - snap_depth)); } // 3. Bottom chamfer of the snap ridge (slide-on entry face) hull() { translate([0, 0, snap_height / 2]) rounded_box(inner_l - (2 * snap_depth), inner_w - (2 * snap_depth), 0.01, max(0.1, inner_r - snap_depth)); // Extend slightly below 0 to ensure a clean manifold cut translate([0, 0, -0.1]) rounded_box(inner_l, inner_w, 0.01, inner_r); } } }