vibe-openscad

tier-2-l-bracket / gpt-5.4-nano-2026-03-17

7 run / 累計 92.5s / 累計 $0.0069

openai gpt 5.4 nano 2026-03-17 bare

bare (provider default effort)

run detail →
render
bare render of tier-2-l-bracket
loading STL…
success 11.0s · 294/1586t · $0.0010
SCAD (136 lines)
// L-bracket (M4 countersunk holes)
$fn = 64;

module countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through=100) {
    // Countersink (cone frustum) for head seat
    cylinder(h=head_depth, d1=head_d*0.9, d2=shaft_d, center=false);
    // Through hole
    translate([0,0,-0.01])
        cylinder(h=through + 0.02, d=shaft_d, center=false);
    // Optional: flat top at head seat (keeps seat crisp)
    translate([0,0,head_depth-0.01])
        cylinder(h=0.02, d=head_d, center=false);
}

module l_bracket() {
    // Dimensions
    w = 50;      // width (X)
    d = 40;      // depth (Y) for horizontal flange, and height (Z) for vertical flange
    t = 3;       // thickness
    corner = 0;  // inner corner at origin

    // Positions for holes: 10mm from outer edge, symmetric.
    // For each flange, X coordinate is centered at w/2, and Y/Z coordinate is measured from outer edge.
    // Outer edge along that flange is at +d (since inner corner at 0).
    hole_x_offsets = [- (w/2 - 10), + (w/2 - 10)]; // left/right along X
    hole_y = d - 10; // from outer edge back toward inner corner for horizontal flange
    hole_z = d - 10; // from outer edge down toward inner corner for vertical flange

    union() {
        // Horizontal flange: +Y direction from inner corner, located at Z in [0, t]
        translate([ -w/2, 0, 0 ])
            cube([w, d, t]);

        // Vertical flange: +Z direction from inner corner, located at Y in [0, t]
        translate([ -w/2, 0, 0 ])
            rotate([0, -90, 0]) // align thickness along Y, height along Z
                cube([t, d, w], center=false);
        // The above construction: cube([t, d, w]) with rotation around Y is awkward;
        // Instead, create explicitly:
        // (Overwritten below; keep first two lines for clarity but final geometry is fixed with explicit model.)
    }
}

// Rebuild explicitly for robustness
module l_bracket_explicit() {
    w = 50;
    d = 40;
    t = 3;

    hole_x_offsets = [- (w/2 - 10), + (w/2 - 10)];
    hole_y = d - 10;
    hole_z = d - 10;

    difference() {
        union() {
            // Horizontal flange (XY plane thickness in Z)
            translate([ -w/2, 0, 0 ])
                cube([w, d, t]);

            // Vertical flange (YZ plane thickness in Y)
            translate([ -w/2, 0, 0 ])
                cube([w, t, d]);
        }

        // Holes in horizontal flange (through in Y? Actually through thickness in Z)
        // Each hole: countersink from outer side => outer side is -Y for horizontal flange? Let's infer:
        // Horizontal flange extends +Y; outer face is at +Y? Bolt head should be on outside of the L bracket.
        // For horizontal flange, bolt head should be on the side facing away from vertical flange: that's +Y (outer).
        // Therefore countersink should face +Y direction; with our hole axis along Z, "facing" is not meaningful.
        // We'll place countersink cone top facing +Z for horizontal? Countersink normal is along Z.
        // Outer side for horizontal flange is +Z (top surface away from base). We'll countersink from +Z.
        for (x = hole_x_offsets) {
            translate([x, hole_y, t - 0.001])
                rotate([180,0,0])
                    countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through= t + 0.02);

            // Note: above rotate flips countersink to face downward; adjust to ensure countersink on +Z side.
            // We instead explicitly cut with countersink from +Z side:
            translate([x, hole_y, 0])
                countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through= t + 0.02);
        }

        // Remove duplicate holes? We'll correct by using only one set per flange:
        // To avoid unintended double subtraction, implement properly below by commenting out above duplication.
    }
}

// Correct implementation without duplication
module l_bracket_final() {
    w = 50;
    d = 40;
    t = 3;

    hole_x_offsets = [- (w/2 - 10), + (w/2 - 10)];
    hole_y = d - 10;
    hole_z = d - 10;

    difference() {
        union() {
            // Horizontal flange: +Y, thickness in Z
            translate([ -w/2, 0, 0 ])
                cube([w, d, t]);

            // Vertical flange: +Z, thickness in Y
            translate([ -w/2, 0, 0 ])
                cube([w, t, d]);
        }

        // Horizontal flange holes (axis: Z through thickness)
        // Countersink seat should be on outer side: for horizontal flange, outer is +Z (top).
        // Create countersink cone with flat seat at +Z side.
        for (x = hole_x_offsets) {
            // Cut countersink + through in Z within [0..t]
            translate([x, hole_y, 0])
                // Countersink cone will occupy up to +head_depth from this origin,
                // so place at bottom and cut; but want cone from +Z:
                // Easiest: build a cone pointing downward and cut through.
                // We'll place module and then flip it so the cone points toward -Z (seat at +Z).
                rotate([180,0,0])
                    countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through=t + 0.02);
        }

        // Vertical flange holes (axis: Y through thickness)
        // Outer side for vertical flange is +X? Actually flange extends +Z, thickness in Y.
        // Outer side should be away from inside corner; for vertical flange, inside face is at Y=0,
        // outer face is at Y=t. Countersink seat should face +Y (bolt head side).
        for (x = hole_x_offsets) {
            // Holes located on centerline: along X, and at height hole_z from outer edge at +Z
            translate([x, 0, hole_z])
                rotate([0,90,0]) // make hole axis along +Y (since default axis is Z)
                    countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through=t + 0.02);
        }
    }
}

l_bracket_final();

prompt

OpenSCAD で、L 字に折れた金具(L-bracket)を作ってください。

形状:
- 水平面と垂直面の 2 つのフランジが直角に繋がっている
- 水平面は 50mm × 40mm(幅 × 奥行き)
- 垂直面は 50mm × 40mm(幅 × 高さ)
- 板厚はどちらも 3mm
- 内側コーナーが原点になるように配置(水平面は +Y 方向、垂直面は +Z 方向に伸びる)

皿穴(countersunk holes):
- 各面に 2 個ずつ、合計 4 個
- M4 ねじ用(貫通穴 Φ4.5mm + 皿座面 Φ8mm × 深さ 2mm)
- 各面の中心線上で、面の縁から 10mm 内側、左右対称に 2 個並べる
- 皿座面は外側(ボルト頭が当たる側)に向ける

完成したコード全体を ```openscad ... ``` のフェンスで囲んで出力してください。コードのみで、追加の説明は不要です。

variant: effort

low success
low
10.2s · 294/1230t · $0.0008
SCAD (110 lines)
$fn = 64;

// L-bracket parameters
w = 50;   // width (X)
d = 40;   // depth for horizontal / height for vertical (Y/Z extent)
t = 3;    // plate thickness

// M4 countersunk hole parameters
through_d = 4.5;     // clearance hole diameter
seat_d = 8;          // countersink (seat) diameter
seat_depth = 2;     // countersink seat depth

// Placement: inner corner at origin
// Horizontal flange: +Y direction
// Vertical flange:   +Z direction
// Centerline: X is centered, positions are +/- along X (left/right symmetric)
// "縁から 10mm 内側" => along Y for horizontal and along Z for vertical
x_half = w/2;
y_in = 10;  // inner offset from edge for horizontal holes (along +Y)
z_in = 10;  // inner offset from edge for vertical holes (along +Z)

// Two holes per face, centerline on face, left/right symmetric
hole_x1 = -x_half/2;
hole_x2 =  x_half/2;

// Simple countersunk hole (axis along local Z of the plate):
// - through hole
// - countersunk seat on the outer side (top side for horizontal, +X side for vertical)
module m4_countersunk(orient="top") {
    // orient determines which side the countersink opens to.
    // For horizontal plate, we drill from +Z side so seat is on outer (top).
    // For vertical plate, we drill from -X side / +X side accordingly.
    if (orient == "top") {
        // seat at z = thickness
        union() {
            // Through hole
            cylinder(h=t+10, d=through_d, center=false);
            // Seat (subtracted)
            translate([0,0,t-seat_depth])
                cylinder(h=seat_depth+0.01, d=seat_d, center=false);
        }
    } else if (orient == "bottom") {
        // seat at z = 0
        union() {
            cylinder(h=t+10, d=through_d, center=false);
            translate([0,0,0])
                cylinder(h=seat_depth+0.01, d=seat_d, center=false);
        }
    } else {
        // generic (fallback): top
        union() {
            cylinder(h=t+10, d=through_d, center=false);
            translate([0,0,t-seat_depth])
                cylinder(h=seat_depth+0.01, d=seat_d, center=false);
        }
    }
}

// Build plates
difference() {
    // Solid L-bracket (union)
    union() {
        // Horizontal flange: X=[-w/2, w/2], Y=[0, d], Z=[0, t]
        translate([0, d/2, t/2])
            cube([w, d, t], center=true);

        // Vertical flange:   X=[-w/2, w/2], Y=[0, t], Z=[0, d]
        // Positioned so that inner corner is at origin (X centered, Y=0 corner).
        translate([0, t/2, d/2])
            cube([w, t, d], center=true);
    }

    // Subtract countersunk holes
    // 1) Horizontal face (+Z outer side): seat should face outer side (+Z)
    // Holes are on the centerline along the face (X), 10mm from Y edges.
    for (xpos = [hole_x1, hole_x2]) {
        // Centerline on the face: Y is "10mm inward" from the edge (Y=0 edge)
        // Keep them symmetric left/right by xpos
        translate([xpos, y_in, t/2])
            // Drill axis along Z
            rotate([0,0,0]) {
                // Subtract countersunk hole with seat toward +Z
                // Create hole geometry locally spanning beyond the solid
                // (We align so that Z=0 is top of the local subtraction in the module)
                translate([0,0,-(t/2)])
                    m4_countersunk("top");
            }
    }

    // 2) Vertical face (+Z inner side? seat toward outer bolt-head side = -X? +X?)
    // Requirement: "皿座面は外側(ボルト頭が当たる側)に向ける"
    // For vertical flange, outer side is taken as +X (the side opposite the horizontal plate interior).
    // We'll open the countersink to +X by drilling from -X toward +X.
    // Holes are on centerline of the vertical face: Z direction is "10mm inward" from edge (Z=0).
    for (xpos = [hole_x1, hole_x2]) {
        translate([xpos, t/2, z_in]) {
            // Drill axis along X, seat toward +X.
            // Create a countersunk hole with its "top" seat along +local Z; rotate to align X.
            // Local: hole axis along Z. We'll rotate so Z -> X.
            rotate([0, -90, 0])
                // seat "top" should face +X after rotation
                m4_countersunk("top");
        }
    }

    // Note: horizontal plate edge "縁から10mm内側,左右対称に2個"
    // With our positioning, Y offset is fixed (10mm from inner corner along +Y),
    // and X offset gives left/right symmetry.
    // For vertical plate, similarly we use Z offset = 10mm from inner corner along +Z.
}
medium (default) success
medium
11.0s · 294/1586t · $0.0010
SCAD (136 lines)
// L-bracket (M4 countersunk holes)
$fn = 64;

module countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through=100) {
    // Countersink (cone frustum) for head seat
    cylinder(h=head_depth, d1=head_d*0.9, d2=shaft_d, center=false);
    // Through hole
    translate([0,0,-0.01])
        cylinder(h=through + 0.02, d=shaft_d, center=false);
    // Optional: flat top at head seat (keeps seat crisp)
    translate([0,0,head_depth-0.01])
        cylinder(h=0.02, d=head_d, center=false);
}

module l_bracket() {
    // Dimensions
    w = 50;      // width (X)
    d = 40;      // depth (Y) for horizontal flange, and height (Z) for vertical flange
    t = 3;       // thickness
    corner = 0;  // inner corner at origin

    // Positions for holes: 10mm from outer edge, symmetric.
    // For each flange, X coordinate is centered at w/2, and Y/Z coordinate is measured from outer edge.
    // Outer edge along that flange is at +d (since inner corner at 0).
    hole_x_offsets = [- (w/2 - 10), + (w/2 - 10)]; // left/right along X
    hole_y = d - 10; // from outer edge back toward inner corner for horizontal flange
    hole_z = d - 10; // from outer edge down toward inner corner for vertical flange

    union() {
        // Horizontal flange: +Y direction from inner corner, located at Z in [0, t]
        translate([ -w/2, 0, 0 ])
            cube([w, d, t]);

        // Vertical flange: +Z direction from inner corner, located at Y in [0, t]
        translate([ -w/2, 0, 0 ])
            rotate([0, -90, 0]) // align thickness along Y, height along Z
                cube([t, d, w], center=false);
        // The above construction: cube([t, d, w]) with rotation around Y is awkward;
        // Instead, create explicitly:
        // (Overwritten below; keep first two lines for clarity but final geometry is fixed with explicit model.)
    }
}

// Rebuild explicitly for robustness
module l_bracket_explicit() {
    w = 50;
    d = 40;
    t = 3;

    hole_x_offsets = [- (w/2 - 10), + (w/2 - 10)];
    hole_y = d - 10;
    hole_z = d - 10;

    difference() {
        union() {
            // Horizontal flange (XY plane thickness in Z)
            translate([ -w/2, 0, 0 ])
                cube([w, d, t]);

            // Vertical flange (YZ plane thickness in Y)
            translate([ -w/2, 0, 0 ])
                cube([w, t, d]);
        }

        // Holes in horizontal flange (through in Y? Actually through thickness in Z)
        // Each hole: countersink from outer side => outer side is -Y for horizontal flange? Let's infer:
        // Horizontal flange extends +Y; outer face is at +Y? Bolt head should be on outside of the L bracket.
        // For horizontal flange, bolt head should be on the side facing away from vertical flange: that's +Y (outer).
        // Therefore countersink should face +Y direction; with our hole axis along Z, "facing" is not meaningful.
        // We'll place countersink cone top facing +Z for horizontal? Countersink normal is along Z.
        // Outer side for horizontal flange is +Z (top surface away from base). We'll countersink from +Z.
        for (x = hole_x_offsets) {
            translate([x, hole_y, t - 0.001])
                rotate([180,0,0])
                    countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through= t + 0.02);

            // Note: above rotate flips countersink to face downward; adjust to ensure countersink on +Z side.
            // We instead explicitly cut with countersink from +Z side:
            translate([x, hole_y, 0])
                countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through= t + 0.02);
        }

        // Remove duplicate holes? We'll correct by using only one set per flange:
        // To avoid unintended double subtraction, implement properly below by commenting out above duplication.
    }
}

// Correct implementation without duplication
module l_bracket_final() {
    w = 50;
    d = 40;
    t = 3;

    hole_x_offsets = [- (w/2 - 10), + (w/2 - 10)];
    hole_y = d - 10;
    hole_z = d - 10;

    difference() {
        union() {
            // Horizontal flange: +Y, thickness in Z
            translate([ -w/2, 0, 0 ])
                cube([w, d, t]);

            // Vertical flange: +Z, thickness in Y
            translate([ -w/2, 0, 0 ])
                cube([w, t, d]);
        }

        // Horizontal flange holes (axis: Z through thickness)
        // Countersink seat should be on outer side: for horizontal flange, outer is +Z (top).
        // Create countersink cone with flat seat at +Z side.
        for (x = hole_x_offsets) {
            // Cut countersink + through in Z within [0..t]
            translate([x, hole_y, 0])
                // Countersink cone will occupy up to +head_depth from this origin,
                // so place at bottom and cut; but want cone from +Z:
                // Easiest: build a cone pointing downward and cut through.
                // We'll place module and then flip it so the cone points toward -Z (seat at +Z).
                rotate([180,0,0])
                    countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through=t + 0.02);
        }

        // Vertical flange holes (axis: Y through thickness)
        // Outer side for vertical flange is +X? Actually flange extends +Z, thickness in Y.
        // Outer side should be away from inside corner; for vertical flange, inside face is at Y=0,
        // outer face is at Y=t. Countersink seat should face +Y (bolt head side).
        for (x = hole_x_offsets) {
            // Holes located on centerline: along X, and at height hole_z from outer edge at +Z
            translate([x, 0, hole_z])
                rotate([0,90,0]) // make hole axis along +Y (since default axis is Z)
                    countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through=t + 0.02);
        }
    }
}

l_bracket_final();
high success
high
38.8s · 294/3817t · $0.0023
SCAD (57 lines)
$fn = 64;

w = 50;        // 幅 (X)
d = 40;        // 水平面 奥行き (Y)
h = 40;        // 垂直面 高さ (Z)
t = 3;         // 板厚
hole_d = 4.5;  // 貫通穴径
cb_d = 8;      // 皿座面径
cb_depth = 2; // 皿座面深さ
offset = 10;   // 面の縁から内側
eps = 0.01;

xs = [offset, w - offset];
y_center = d / 2;
z_center = h / 2;

module countersunk_hole_through_Z(x, y, z0, plate_t) {
  // 貫通穴 (Z方向)
  translate([x, y, -eps + z0])
    cylinder(d = hole_d, h = plate_t + 2 * eps);

  // 皿座面 (外側 = +Z側)
  translate([x, y, plate_t - cb_depth + z0])
    cylinder(d = cb_d, h = cb_depth);
}

module countersunk_hole_through_Y(x, z, y0, plate_t) {
  // 貫通穴 (Y方向) : 回転してY軸へ
  translate([x, y0 + plate_t + eps, z])
    rotate([90, 0, 0])
      cylinder(d = hole_d, h = plate_t + 2 * eps);

  // 皿座面 (外側 = +Y側)
  translate([x, y0 + plate_t, z])
    rotate([90, 0, 0])
      cylinder(d = cb_d, h = cb_depth);
}

difference() {
  union() {
    // 水平フランジ: X(0..w), Y(0..d), Z(0..t)
    cube([w, d, t]);

    // 垂直フランジ: X(0..w), Y(0..t), Z(0..h)
    cube([w, t, h]);
  }

  // 水平面の皿穴 2個 (合計4個中2個)
  for (x = xs) {
    countersunk_hole_through_Z(x, y_center, 0, t);
  }

  // 垂直面の皿穴 2個 (合計4個中2個)
  for (x = xs) {
    countersunk_hole_through_Y(x, z_center, 0, t);
  }
}
maxnot run
xhighnot run

iteration: iter-png

i1 success
iter 1
10.8s · 2545/870t · $0.0007
diff vs bare: +54/-114
- // L-bracket (M4 countersunk holes)
+ // L-bracket with 4x M4 countersunk holes (2 per flange)
+ // Inner corner at origin: horizontal flange extends +Y, vertical flange extends +Z
+ 
  $fn = 64;
  
- module countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through=100) {
-     // Countersink (cone frustum) for head seat
-     cylinder(h=head_depth, d1=head_d*0.9, d2=shaft_d, center=false);
-     // Through hole
-     translate([0,0,-0.01])
-         cylinder(h=through + 0.02, d=shaft_d, center=false);
-     // Optional: flat top at head seat (keeps seat crisp)
-     translate([0,0,head_depth-0.01])
-         cylinder(h=0.02, d=head_d, center=false);
- }
- 
- module l_bracket() {
-     // Dimensions
-     w = 50;      // width (X)
-     d = 40;      // depth (Y) for horizontal flange, and height (Z) for vertical flange
-     t = 3;       // thickness
-     corner = 0;  // inner corner at origin
- 
-     // Positions for holes: 10mm from outer edge, symmetric.
-     // For each flange, X coordinate is centered at w/2, and Y/Z coordinate is measured from outer edge.
-     // Outer edge along that flange is at +d (since inner corner at 0).
-     hole_x_offsets = [- (w/2 - 10), + (w/2 - 10)]; // left/right along X
-     hole_y = d - 10; // from outer edge back toward inner corner for horizontal flange
-     hole_z = d - 10; // from outer edge down toward inner corner for vertical flange
- 
+ module countersunk_hole(
+     shaft_d = 4.5,     // through hole Ø
+     head_d  = 8,       // countersink seat Ø
+     head_h  = 2,       // countersink depth
+     through  = 200     // long enough for bores
+ ){
+     // Cut sequence along +Z axis (default cylinder axis)
+     // Countersink seat (flat at top): place cone so its top is at z=0
+     // Then drill through.
      union() {
-         // Horizontal flange: +Y direction from inner corner, located at Z in [0, t]
-         translate([ -w/2, 0, 0 ])
-             cube([w, d, t]);
+         // through hole
+         translate([0,0,-0.01])
+             cylinder(h = through + 0.02, d = shaft_d, center = false);
  
-         // Vertical flange: +Z direction from inner corner, located at Y in [0, t]
-         translate([ -w/2, 0, 0 ])
-             rotate([0, -90, 0]) // align thickness along Y, height along Z
-                 cube([t, d, w], center=false);
-         // The above construction: cube([t, d, w]) with rotation around Y is awkward;
-         // Instead, create explicitly:
-         // (Overwritten below; keep first two lines for clarity but final geometry is fixed with explicit model.)
+         // countersink: cone with top at z=0, going to -head_h
+         // Use d1 (top) = head_d, d2 (bottom) ~ shaft_d
+         translate([0,0,0])
+             cylinder(h = head_h, d1 = head_d, d2 = shaft_d, center = false);
      }
  }
  
- // Rebuild explicitly for robustness
- module l_bracket_explicit() {
-     w = 50;
-     d = 40;
-     t = 3;
+ module l_bracket() {
+     w = 50;      // width (X)
+     d = 40;      // depth/height along +Y for horizontal, +Z for vertical
+     t = 3;       // thickness for both flanges
  
-     hole_x_offsets = [- (w/2 - 10), + (w/2 - 10)];
-     hole_y = d - 10;
-     hole_z = d - 10;
+     // hole positions:
+     // "面の中心線上で、面の縁から 10mm 内側、左右対称に2個"
+     // For each flange: X is centered -> holes at x = ±(w/2 - 10)
+     // For horizontal flange: distance from outer edge (+Y) inward -> y = (d - 10)
+     // For vertical flange: distance from outer edge (+Z) inward -> z = (d - 10)
+     hx = [-(w/2 - 10), +(w/2 - 10)];
+     hy = d - 10;
+     hz = d - 10;
  
      difference() {
          union() {
-             // Horizontal flange (XY plane thickness in Z)
-             translate([ -w/2, 0, 0 ])
+             // Horizontal flange: size w (X) x d (Y) x t (Z), Z in [0, t]
+             translate([-w/2, 0, 0])
                  cube([w, d, t]);
  
-             // Vertical flange (YZ plane thickness in Y)
-             translate([ -w/2, 0, 0 ])
+             // Vertical flange: size w (X) x t (Y thickness) x d (Z), Y in [0, t], Z in [0, d]
+             translate([-w/2, 0, 0])
                  cube([w, t, d]);
          }
  
-         // Holes in horizontal flange (through in Y? Actually through thickness in Z)
-         // Each hole: countersink from outer side => outer side is -Y for horizontal flange? Let's infer:
-         // Horizontal flange extends +Y; outer face is at +Y? Bolt head should be on outside of the L bracket.
-         // For horizontal flange, bolt head should be on the side facing away from vertical flange: that's +Y (outer).
-         // Therefore countersink should face +Y direction; with our hole axis along Z, "facing" is not meaningful.
-         // We'll place countersink cone top facing +Z for horizontal? Countersink normal is along Z.
-         // Outer side for horizontal flange is +Z (top surface away from base). We'll countersink from +Z.
-         for (x = hole_x_offsets) {
-             translate([x, hole_y, t - 0.001])
-                 rotate([180,0,0])
-                     countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through= t + 0.02);
- 
-             // Note: above rotate flips countersink to face downward; adjust to ensure countersink on +Z side.
-             // We instead explicitly cut with countersink from +Z side:
-             translate([x, hole_y, 0])
-                 countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through= t + 0.02);
+         // --- Horizontal flange holes ---
+         // Outer side for bolt head: outside face at +Z (top of horizontal flange)
+         // Therefore countersink should face +Z.
+         // Hole axis: Z (through thickness in Z)
+         for (x = hx) {
+             translate([x, hy, 0])  // start at bottom of flange
+                 rotate([180,0,0])  // make countersink face +Z (top at +Z)
+                     countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=t + 20);
          }
  
-         // Remove duplicate holes? We'll correct by using only one set per flange:
-         // To avoid unintended double subtraction, implement properly below by commenting out above duplication.
-     }
- }
- 
- // Correct implementation without duplication
- module l_bracket_final() {
-     w = 50;
-     d = 40;
-     t = 3;
- 
-     hole_x_offsets = [- (w/2 - 10), + (w/2 - 10)];
-     hole_y = d - 10;
-     hole_z = d - 10;
- 
-     difference() {
-         union() {
-             // Horizontal flange: +Y, thickness in Z
-             translate([ -w/2, 0, 0 ])
-                 cube([w, d, t]);
- 
-             // Vertical flange: +Z, thickness in Y
-             translate([ -w/2, 0, 0 ])
-                 cube([w, t, d]);
+         // --- Vertical flange holes ---
+         // Outer side for bolt head: outside face at +Y (away from inside corner)
+         // Hole axis: Y through thickness t.
+         // Build in Y: map default Z-axis model to Y-axis.
+         for (x = hx) {
+             translate([x, t, hz])   // place at outer face +Y, z=hz
+                 rotate([0,90,0])    // rotate Z-axis hole to Y-axis
+                     // Also flip so countersink seat opens toward +Y (outer side)
+                     rotate([180,0,0])
+                         countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=t + 20);
          }
- 
-         // Horizontal flange holes (axis: Z through thickness)
-         // Countersink seat should be on outer side: for horizontal flange, outer is +Z (top).
-         // Create countersink cone with flat seat at +Z side.
-         for (x = hole_x_offsets) {
-             // Cut countersink + through in Z within [0..t]
-             translate([x, hole_y, 0])
-                 // Countersink cone will occupy up to +head_depth from this origin,
-                 // so place at bottom and cut; but want cone from +Z:
-                 // Easiest: build a cone pointing downward and cut through.
-                 // We'll place module and then flip it so the cone points toward -Z (seat at +Z).
-                 rotate([180,0,0])
-                     countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through=t + 0.02);
-         }
- 
-         // Vertical flange holes (axis: Y through thickness)
-         // Outer side for vertical flange is +X? Actually flange extends +Z, thickness in Y.
-         // Outer side should be away from inside corner; for vertical flange, inside face is at Y=0,
-         // outer face is at Y=t. Countersink seat should face +Y (bolt head side).
-         for (x = hole_x_offsets) {
-             // Holes located on centerline: along X, and at height hole_z from outer edge at +Z
-             translate([x, 0, hole_z])
-                 rotate([0,90,0]) // make hole axis along +Y (since default axis is Z)
-                     countersunk_hole_through(shaft_d=4.5, head_d=8, head_depth=2, through=t + 0.02);
-         }
      }
  }
  
- l_bracket_final();
+ l_bracket();
SCAD (76 lines)
// L-bracket with 4x M4 countersunk holes (2 per flange)
// Inner corner at origin: horizontal flange extends +Y, vertical flange extends +Z

$fn = 64;

module countersunk_hole(
    shaft_d = 4.5,     // through hole Ø
    head_d  = 8,       // countersink seat Ø
    head_h  = 2,       // countersink depth
    through  = 200     // long enough for bores
){
    // Cut sequence along +Z axis (default cylinder axis)
    // Countersink seat (flat at top): place cone so its top is at z=0
    // Then drill through.
    union() {
        // through hole
        translate([0,0,-0.01])
            cylinder(h = through + 0.02, d = shaft_d, center = false);

        // countersink: cone with top at z=0, going to -head_h
        // Use d1 (top) = head_d, d2 (bottom) ~ shaft_d
        translate([0,0,0])
            cylinder(h = head_h, d1 = head_d, d2 = shaft_d, center = false);
    }
}

module l_bracket() {
    w = 50;      // width (X)
    d = 40;      // depth/height along +Y for horizontal, +Z for vertical
    t = 3;       // thickness for both flanges

    // hole positions:
    // "面の中心線上で、面の縁から 10mm 内側、左右対称に2個"
    // For each flange: X is centered -> holes at x = ±(w/2 - 10)
    // For horizontal flange: distance from outer edge (+Y) inward -> y = (d - 10)
    // For vertical flange: distance from outer edge (+Z) inward -> z = (d - 10)
    hx = [-(w/2 - 10), +(w/2 - 10)];
    hy = d - 10;
    hz = d - 10;

    difference() {
        union() {
            // Horizontal flange: size w (X) x d (Y) x t (Z), Z in [0, t]
            translate([-w/2, 0, 0])
                cube([w, d, t]);

            // Vertical flange: size w (X) x t (Y thickness) x d (Z), Y in [0, t], Z in [0, d]
            translate([-w/2, 0, 0])
                cube([w, t, d]);
        }

        // --- Horizontal flange holes ---
        // Outer side for bolt head: outside face at +Z (top of horizontal flange)
        // Therefore countersink should face +Z.
        // Hole axis: Z (through thickness in Z)
        for (x = hx) {
            translate([x, hy, 0])  // start at bottom of flange
                rotate([180,0,0])  // make countersink face +Z (top at +Z)
                    countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=t + 20);
        }

        // --- Vertical flange holes ---
        // Outer side for bolt head: outside face at +Y (away from inside corner)
        // Hole axis: Y through thickness t.
        // Build in Y: map default Z-axis model to Y-axis.
        for (x = hx) {
            translate([x, t, hz])   // place at outer face +Y, z=hz
                rotate([0,90,0])    // rotate Z-axis hole to Y-axis
                    // Also flip so countersink seat opens toward +Y (outer side)
                    rotate([180,0,0])
                        countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=t + 20);
        }
    }
}

l_bracket();
i2 success
iter 2
5.6s · 1829/751t · $0.0006
diff vs i1: +33/-44
  // L-bracket with 4x M4 countersunk holes (2 per flange)
  // Inner corner at origin: horizontal flange extends +Y, vertical flange extends +Z
  
- $fn = 64;
+ $fn = 96;
  
- module countersunk_hole(
-     shaft_d = 4.5,     // through hole Ø
-     head_d  = 8,       // countersink seat Ø
-     head_h  = 2,       // countersink depth
-     through  = 200     // long enough for bores
- ){
-     // Cut sequence along +Z axis (default cylinder axis)
-     // Countersink seat (flat at top): place cone so its top is at z=0
-     // Then drill through.
+ module countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=50){
+     // Countersink + through: axis along +Z (top at z=0, extends to -)
+     // Note: We start hole at z=0 and cut downward so it cleanly matches the faces.
      union() {
-         // through hole
-         translate([0,0,-0.01])
-             cylinder(h = through + 0.02, d = shaft_d, center = false);
+         // through
+         cylinder(h=through, d=shaft_d, center=false);
  
-         // countersink: cone with top at z=0, going to -head_h
-         // Use d1 (top) = head_d, d2 (bottom) ~ shaft_d
+         // countersink (cone)
          translate([0,0,0])
-             cylinder(h = head_h, d1 = head_d, d2 = shaft_d, center = false);
+             cylinder(h=head_h, d1=head_d, d2=shaft_d, center=false);
      }
  }
  
  module l_bracket() {
-     w = 50;      // width (X)
-     d = 40;      // depth/height along +Y for horizontal, +Z for vertical
-     t = 3;       // thickness for both flanges
+     w = 50;   // width (X)
+     d = 40;   // length of flange along Y (horizontal) / Z (vertical)
+     t = 3;    // thickness of both flanges
  
-     // hole positions:
-     // "面の中心線上で、面の縁から 10mm 内側、左右対称に2個"
-     // For each flange: X is centered -> holes at x = ±(w/2 - 10)
-     // For horizontal flange: distance from outer edge (+Y) inward -> y = (d - 10)
-     // For vertical flange: distance from outer edge (+Z) inward -> z = (d - 10)
-     hx = [-(w/2 - 10), +(w/2 - 10)];
-     hy = d - 10;
-     hz = d - 10;
+     // hole x positions: on center line in X, 10mm inside from outer edge -> x = ±(w/2-10)
+     hx = [-(w/2 - 10), (w/2 - 10)];
  
+     // hole y/z positions: 10mm inside from outer edge
+     hy = d - 10; // for horizontal flange: y in [0..d], outer edge at y=d
+     hz = d - 10; // for vertical flange: z in [0..d], outer edge at z=d
+ 
      difference() {
          union() {
-             // Horizontal flange: size w (X) x d (Y) x t (Z), Z in [0, t]
+             // Horizontal flange: X=[-w/2..+w/2], Y=[0..d], Z=[0..t]
              translate([-w/2, 0, 0])
                  cube([w, d, t]);
  
-             // Vertical flange: size w (X) x t (Y thickness) x d (Z), Y in [0, t], Z in [0, d]
+             // Vertical flange: X=[-w/2..+w/2], Y=[0..t], Z=[0..d]
              translate([-w/2, 0, 0])
                  cube([w, t, d]);
          }
  
-         // --- Horizontal flange holes ---
-         // Outer side for bolt head: outside face at +Z (top of horizontal flange)
-         // Therefore countersink should face +Z.
-         // Hole axis: Z (through thickness in Z)
+         // --- Horizontal flange holes (2x) ---
+         // Countersink should face outer side: +Z (top face at z=t)
          for (x = hx) {
-             translate([x, hy, 0])  // start at bottom of flange
-                 rotate([180,0,0])  // make countersink face +Z (top at +Z)
-                     countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=t + 20);
+             // Place so that countersink seat is cut from the top face (z=t) downwards
+             translate([x, hy, t])
+                 rotate([180,0,0]) // flip so the countersink points upward (+Z face) in original model coordinates
+                     countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100);
          }
  
-         // --- Vertical flange holes ---
-         // Outer side for bolt head: outside face at +Y (away from inside corner)
-         // Hole axis: Y through thickness t.
-         // Build in Y: map default Z-axis model to Y-axis.
+         // --- Vertical flange holes (2x) ---
+         // Countersink should face outer side: +Y (away from inner corner)
+         // Vertical flange thickness is along Y: Y in [0..t], outer face at Y=t
          for (x = hx) {
-             translate([x, t, hz])   // place at outer face +Y, z=hz
-                 rotate([0,90,0])    // rotate Z-axis hole to Y-axis
-                     // Also flip so countersink seat opens toward +Y (outer side)
+             // Place at outer face (y=t) and cut toward -Y
+             translate([x, t, hz])
+                 rotate([0,90,0])   // rotate Z-axis hole to Y-axis
+                     // flip to ensure countersink opens toward +Y (outer face)
                      rotate([180,0,0])
-                         countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=t + 20);
+                         countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100);
          }
      }
  }
  
  l_bracket();
SCAD (65 lines)
// L-bracket with 4x M4 countersunk holes (2 per flange)
// Inner corner at origin: horizontal flange extends +Y, vertical flange extends +Z

$fn = 96;

module countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=50){
    // Countersink + through: axis along +Z (top at z=0, extends to -)
    // Note: We start hole at z=0 and cut downward so it cleanly matches the faces.
    union() {
        // through
        cylinder(h=through, d=shaft_d, center=false);

        // countersink (cone)
        translate([0,0,0])
            cylinder(h=head_h, d1=head_d, d2=shaft_d, center=false);
    }
}

module l_bracket() {
    w = 50;   // width (X)
    d = 40;   // length of flange along Y (horizontal) / Z (vertical)
    t = 3;    // thickness of both flanges

    // hole x positions: on center line in X, 10mm inside from outer edge -> x = ±(w/2-10)
    hx = [-(w/2 - 10), (w/2 - 10)];

    // hole y/z positions: 10mm inside from outer edge
    hy = d - 10; // for horizontal flange: y in [0..d], outer edge at y=d
    hz = d - 10; // for vertical flange: z in [0..d], outer edge at z=d

    difference() {
        union() {
            // Horizontal flange: X=[-w/2..+w/2], Y=[0..d], Z=[0..t]
            translate([-w/2, 0, 0])
                cube([w, d, t]);

            // Vertical flange: X=[-w/2..+w/2], Y=[0..t], Z=[0..d]
            translate([-w/2, 0, 0])
                cube([w, t, d]);
        }

        // --- Horizontal flange holes (2x) ---
        // Countersink should face outer side: +Z (top face at z=t)
        for (x = hx) {
            // Place so that countersink seat is cut from the top face (z=t) downwards
            translate([x, hy, t])
                rotate([180,0,0]) // flip so the countersink points upward (+Z face) in original model coordinates
                    countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100);
        }

        // --- Vertical flange holes (2x) ---
        // Countersink should face outer side: +Y (away from inner corner)
        // Vertical flange thickness is along Y: Y in [0..t], outer face at Y=t
        for (x = hx) {
            // Place at outer face (y=t) and cut toward -Y
            translate([x, t, hz])
                rotate([0,90,0])   // rotate Z-axis hole to Y-axis
                    // flip to ensure countersink opens toward +Y (outer face)
                    rotate([180,0,0])
                        countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100);
        }
    }
}

l_bracket();
i3 success
iter 3
5.2s · 1710/735t · $0.0006
diff vs i2: +30/-29
  // L-bracket with 4x M4 countersunk holes (2 per flange)
  // Inner corner at origin: horizontal flange extends +Y, vertical flange extends +Z
  
  $fn = 96;
  
- module countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=50){
-     // Countersink + through: axis along +Z (top at z=0, extends to -)
-     // Note: We start hole at z=0 and cut downward so it cleanly matches the faces.
+ module countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100)
+ {
+     // Cut with axis along +Z (top at z=0, extends to -Z)
      union() {
-         // through
-         cylinder(h=through, d=shaft_d, center=false);
- 
-         // countersink (cone)
-         translate([0,0,0])
-             cylinder(h=head_h, d1=head_d, d2=shaft_d, center=false);
+         cylinder(h=through, d=shaft_d, center=false);                       // through hole
+         cylinder(h=head_h,  d1=head_d, d2=shaft_d, center=false);          // countersink
      }
  }
  
- module l_bracket() {
-     w = 50;   // width (X)
-     d = 40;   // length of flange along Y (horizontal) / Z (vertical)
+ module l_bracket()
+ {
+     w = 50;   // X size
+     d = 40;   // Y (horizontal) / Z (vertical) size
      t = 3;    // thickness of both flanges
  
-     // hole x positions: on center line in X, 10mm inside from outer edge -> x = ±(w/2-10)
+     // Hole centers along X on the centerline; 10mm from outer edges.
+     // Outer edges at x=±w/2 => center positions at x=±(w/2 - 10)
      hx = [-(w/2 - 10), (w/2 - 10)];
  
-     // hole y/z positions: 10mm inside from outer edge
-     hy = d - 10; // for horizontal flange: y in [0..d], outer edge at y=d
-     hz = d - 10; // for vertical flange: z in [0..d], outer edge at z=d
+     // Hole center lines 10mm inside from outer edge.
+     // Horizontal flange outer edge at Y=d => hole centers at y=d-10
+     // Vertical flange outer edge at Z=d => hole centers at z=d-10
+     hy = d - 10;
+     hz = d - 10;
  
      difference() {
          union() {
-             // Horizontal flange: X=[-w/2..+w/2], Y=[0..d], Z=[0..t]
+             // Horizontal flange: X[-w/2..+w/2], Y[0..d], Z[0..t]
              translate([-w/2, 0, 0])
                  cube([w, d, t]);
  
-             // Vertical flange: X=[-w/2..+w/2], Y=[0..t], Z=[0..d]
+             // Vertical flange: X[-w/2..+w/2], Y[0..t], Z[0..d]
              translate([-w/2, 0, 0])
                  cube([w, t, d]);
          }
  
          // --- Horizontal flange holes (2x) ---
-         // Countersink should face outer side: +Z (top face at z=t)
+         // Countersink should face the outer side: +Z face (top of horizontal flange).
+         // We cut by placing hole primitive at z=t and cutting downward (-Z).
          for (x = hx) {
-             // Place so that countersink seat is cut from the top face (z=t) downwards
              translate([x, hy, t])
-                 rotate([180,0,0]) // flip so the countersink points upward (+Z face) in original model coordinates
-                     countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100);
+                 // hole axis along -Z: already built as cutting from z=0 downwards,
+                 // so just translate; no flips needed.
+                 countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100);
          }
  
          // --- Vertical flange holes (2x) ---
-         // Countersink should face outer side: +Y (away from inner corner)
-         // Vertical flange thickness is along Y: Y in [0..t], outer face at Y=t
+         // Countersink should face outer side: +Y face of the vertical flange (away from inner corner).
+         // Place at y=t and cut toward -Y (i.e., axis along -Y).
          for (x = hx) {
-             // Place at outer face (y=t) and cut toward -Y
              translate([x, t, hz])
-                 rotate([0,90,0])   // rotate Z-axis hole to Y-axis
-                     // flip to ensure countersink opens toward +Y (outer face)
-                     rotate([180,0,0])
-                         countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100);
+                 rotate([0, 90, 0])   // rotate Z-axis hole to Y-axis
+                     // now the countersink axis direction should be toward -Y.
+                     // The countersunk_hole is built to extend along -Z from its local origin.
+                     // After rotation, that becomes extension along -Y.
+                     countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100);
          }
      }
  }
  
  l_bracket();
SCAD (66 lines)
// L-bracket with 4x M4 countersunk holes (2 per flange)
// Inner corner at origin: horizontal flange extends +Y, vertical flange extends +Z

$fn = 96;

module countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100)
{
    // Cut with axis along +Z (top at z=0, extends to -Z)
    union() {
        cylinder(h=through, d=shaft_d, center=false);                       // through hole
        cylinder(h=head_h,  d1=head_d, d2=shaft_d, center=false);          // countersink
    }
}

module l_bracket()
{
    w = 50;   // X size
    d = 40;   // Y (horizontal) / Z (vertical) size
    t = 3;    // thickness of both flanges

    // Hole centers along X on the centerline; 10mm from outer edges.
    // Outer edges at x=±w/2 => center positions at x=±(w/2 - 10)
    hx = [-(w/2 - 10), (w/2 - 10)];

    // Hole center lines 10mm inside from outer edge.
    // Horizontal flange outer edge at Y=d => hole centers at y=d-10
    // Vertical flange outer edge at Z=d => hole centers at z=d-10
    hy = d - 10;
    hz = d - 10;

    difference() {
        union() {
            // Horizontal flange: X[-w/2..+w/2], Y[0..d], Z[0..t]
            translate([-w/2, 0, 0])
                cube([w, d, t]);

            // Vertical flange: X[-w/2..+w/2], Y[0..t], Z[0..d]
            translate([-w/2, 0, 0])
                cube([w, t, d]);
        }

        // --- Horizontal flange holes (2x) ---
        // Countersink should face the outer side: +Z face (top of horizontal flange).
        // We cut by placing hole primitive at z=t and cutting downward (-Z).
        for (x = hx) {
            translate([x, hy, t])
                // hole axis along -Z: already built as cutting from z=0 downwards,
                // so just translate; no flips needed.
                countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100);
        }

        // --- Vertical flange holes (2x) ---
        // Countersink should face outer side: +Y face of the vertical flange (away from inner corner).
        // Place at y=t and cut toward -Y (i.e., axis along -Y).
        for (x = hx) {
            translate([x, t, hz])
                rotate([0, 90, 0])   // rotate Z-axis hole to Y-axis
                    // now the countersink axis direction should be toward -Y.
                    // The countersunk_hole is built to extend along -Z from its local origin.
                    // After rotation, that becomes extension along -Y.
                    countersunk_hole(shaft_d=4.5, head_d=8, head_h=2, through=100);
        }
    }
}

l_bracket();