// Sheet-metal Z bracket (offset bracket), 2 mm aluminium // Units mm, Z up, part resting on Z=0. // Bottom flange extends -X, vertical web, top flange extends +X. /* [Sheet] */ thickness = 2; // [0.5:0.1:6] bend_radius = 2; // inside bend radius [0.5:0.1:10] k_factor = 0.44; // [0.2:0.01:0.5] /* [Geometry] */ width = 30; // [10:1:100] offset_height = 20; // outside-to-outside flange offset [8:0.5:100] flange_length = 25; // from outside of bend (outer mold line) [10:0.5:100] hole_diameter = 4.5; // [0:0.1:15] /* [Output] */ mode = "folded"; // [folded, flat2d, flat3d] /* [Hidden] */ $fn = 96; T = thickness; R = bend_radius; K = k_factor; ro = R + T; // outer bend radius flat_flange = flange_length - ro; // straight part of each flange flat_web = offset_height - 2 * ro; // straight part of web BA = (PI / 2) * (R + K * T); // bend allowance, 90 deg flat_len = 2 * flat_flange + flat_web + 2 * BA; hole_from_end = flange_length / 2; // hole centred on nominal flange assert(flat_web >= 0, "offset too small for bend radius"); assert(flat_flange > hole_diameter, "flange too short"); module sector(cx, cz, a0) { // annulus sector from angle a0 to a0+90 in XZ (angle measured from +X toward +Z) translate([cx, width, cz]) rotate([90, 0, 0]) linear_extrude(width) intersection() { difference() { circle(r = ro); circle(r = R); } rotate(a0) square([ro + 1, ro + 1]); } } module hole_z(x) { translate([x, width / 2, -1]) cylinder(d = hole_diameter, h = offset_height + 2); } module folded() { // web outer face (bottom bend side) at x = T, inner at x = 0 difference() { union() { // bottom flange: z in [0,T], x from T - flange_length to T - ro translate([T - flange_length, 0, 0]) cube([flat_flange, width, T]); // bottom bend: centre at (T - ro, ro) = (-R, ro) sector(-R, ro, 270); // web: x in [0,T], z from ro to offset_height - ro translate([0, 0, ro]) cube([T, width, flat_web]); // top bend: centre at (ro, offset_height - ro) sector(ro, offset_height - ro, 90); // top flange: z in [H-T, H], x from ro to flange_length translate([ro, 0, offset_height - T]) cube([flat_flange, width, T]); } hole_z(T - hole_from_end); hole_z(hole_from_end); } } module flat_outline() { difference() { square([flat_len, width]); translate([hole_from_end, width / 2]) circle(d = hole_diameter); translate([flat_len - hole_from_end, width / 2]) circle(d = hole_diameter); } } if (mode == "folded") folded(); else if (mode == "flat2d") flat_outline(); else linear_extrude(T) flat_outline(); echo(str("FLAT ", flat_len, " x ", width, " BA=", BA));