vibe-openscad

tier-3-butt-hinge / o3-2025-04-16

7 run / 累計 527.3s / 累計 $0.3079

openai o3 2025-04-16 bare

bare (provider default effort)

run detail →
render
bare render of tier-3-butt-hinge
loading STL…
success 59.7s · 592/4919t · $0.0405
SCAD (70 lines)
// Butt hinge (opened 180°)
// Parameters
plate_len = 30;           // along Y
plate_w   = 25;           // along X (each leaf)
plate_t   = 2;            // thickness (Z)
kn_seg    = 6;            // single knuckle length
kn_count  = 5;            // total knuckle pieces
kn_od     = 8;            // knuckle outer Ø
kn_id     = 4.6;          // knuckle inner Ø (pin clearance)
pin_d     = 4;            // pin Ø
pin_len   = plate_len+2;  // 32 mm (30 + 1 + 1)

// Convenience
$fn = 64;

// ---------- Modules ----------
module cyl_y(h,r,center=false)
    rotate([90,0,0]) cylinder(h=h,r=r,center=center);

module knuckle_seg(len=kn_seg, od=kn_od/2, id=kn_id/2)
difference(){
    cyl_y(len, od);
    cyl_y(len+0.2, id);     // a bit longer for clean subtraction
}

module countersunk_hole()
union(){
    translate([0,0,-2]) cylinder(h=6,r=3.2/2,$fn=32);   // through M3.2
    translate([0,0,0])  cylinder(h=1,r=6/2,$fn=32);     // 6 mm Ø, 1 mm deep
}

module leaf(is_left=true){
    // X positions
    plate_x = is_left ? -(kn_od/2) - plate_w :  kn_od/2;
    hole_x  = is_left ? -(kn_od/2) - plate_w/2 : kn_od/2 + plate_w/2;

    difference(){
        // Solid parts
        union(){
            // plate
            translate([plate_x,0,-plate_t/2])
                cube([plate_w, plate_len, plate_t]);

            // knuckles
            if(is_left){
                for(i=[0,2,4])
                    translate([0,i*kn_seg,0]) knuckle_seg();
            }else{
                for(i=[1,3])
                    translate([0,i*kn_seg,0]) knuckle_seg();
            }
        }

        // screw holes (Y positions 6 mm, 14 mm, 22 mm from one end)
        for(y=[6,14,22])
            translate([hole_x,y,plate_t/2])
                countersunk_hole();
    }
}

module pin(){
    translate([0,-1,0]) cyl_y(pin_len, pin_d/2, false);
}

// ---------- Assembly ----------
union(){
    leaf(true);   // left leaf
    leaf(false);  // right leaf
    pin();        // hinge pin
}
パラメータ (8)
スライダを動かすと openscad-wasm で再レンダリング

prompt

OpenSCAD で、家具用の小型バット蝶番(butt hinge)を作ってください。
3 つのパーツ(左板、右板、ピン軸)が組み合わさって動作する完成品を、
「開いた状態(180°)」で 1 つの SCAD ファイルに配置して出力します。

寸法と配置:
- 板(leaf)2 枚: 30mm × 25mm × 厚さ 2mm の鉄板形状
  - 縦 30mm の辺がピン軸に沿う(ヒンジ軸方向)
  - 横 25mm の辺が回転で開く方向に伸びる
- ピン軸: 直径 4mm の円柱、長さ 32mm(両端 1mm ずつ knuckle から飛び出す)
- knuckle(筒部): 縦 30mm を 5 等分(各 6mm)に区切り、左板に 3 個・右板に 2 個を
  互い違いに配置(左板は外側 2 個 + 中央 1 個、右板は中間 2 個)
- knuckle 外径 8mm、内径はピン軸 + 0.3mm クリアランス(= 4.6mm 穴)
- 左板と右板はピン軸を共有して回転可能。180° 開いた状態で、両板の
  平らな面が同一平面に来るように配置する
- 各板の knuckle から離れた側に、M3 用の皿穴を 3 個ずつ
  (穴ピッチは板の縦方向に 8mm 間隔、皿穴は表面から見て直径 6mm × 深さ 1mm
  のテーパ + 直径 3.2mm の貫通穴)

座標系:
- ピン軸の中心線を Y 軸に重ねる(ピン軸は +Y 方向)
- 板の平らな面は Z 軸に直交し、左板が x<0 側、右板が x>0 側に伸びる(180° 開)
- knuckle は X=0 を中心とし、Y 方向に 6mm ずつ並ぶ

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

variant: effort

low success
low
45.5s · 592/2562t · $0.0217
SCAD (89 lines)
// Butt hinge (opened 180°)  ---------------------------
// Parameters
leaf_w   = 25;     // width (X direction)
leaf_h   = 30;     // height (Y direction)
leaf_t   = 2;      // thickness (Z)
kn_d_out = 8;      // knuckle outer diameter
kn_d_in  = 4.6;    // knuckle inner diameter  (= pin Ø + 0.3)
kn_len   = 6;      // each knuckle length
pin_d    = 4;      // pin diameter
pin_len  = 32;     // pin total length (30 + 1 + 1)
hole_d   = 3.2;    // through-hole diameter
cs_d     = 6;      // countersink top diameter
cs_depth = 1;      // countersink depth
hole_off = 20;     // X position of holes from origin (±)
hole_pitch = 8;    // Y spacing between holes

$fn = 64;

// Main assembly
module hinge()
{
    // pin
    rotate([90,0,0])
        translate([0,0,-pin_len/2])
            cylinder(d=pin_d, h=pin_len);

    // leaves
    leaf(side = -1);   // left leaf (x < 0)
    leaf(side =  1);   // right leaf (x > 0)
}

// Leaf with knuckles and holes
// side = -1 (left), +1 (right)
module leaf(side = -1)
{
    // Base plate
    translate([side*(leaf_w * -0.5 - kn_d_out/2), -leaf_h/2, 0])
        difference()
        {
            // plate
            cube([leaf_w, leaf_h, leaf_t]);

            // countersunk holes
            for(i=[-1,0,1])          // three holes
            {
                y_pos = leaf_h/2 + i*hole_pitch;   // convert i index to Y
                translate([side*hole_off, y_pos, 0])
                    countersunk_hole();
            }
        }

    // Knuckles
    for(idx=[0:4])
    {
        // decide if this knuckle belongs to this leaf
        knuckle_to_side = (idx % 2 == 0) ? -1 : 1;   // even -> left, odd -> right
        if(knuckle_to_side == side)
        {
            y_center = -leaf_h/2 + kn_len/2 + idx*kn_len;
            // Solid cylinder knuckle (outer)
            translate([0, y_center, 0])
                rotate([90,0,0])
                    cylinder(d=kn_d_out, h=kn_len);

            // Bore for pin clearance
            translate([0, y_center, 0])
                rotate([90,0,0])
                    #cylinder(d=kn_d_in, h=kn_len);   // use "#" for preview of hole
        }
    }
}

// Countersunk hole (subtractive)
module countersunk_hole()
{
    union()
    {
        // through hole
        translate([0,0,-1])   // extend a bit below plate for clean subtraction
            cylinder(d=hole_d, h=leaf_t+2);

        // countersink (straight-walled approximation)
        translate([0,0,leaf_t-cs_depth])
            cylinder(d=cs_d, h=cs_depth+0.01); // slight overlap
    }
}

// --- Render ---
hinge();
medium (default) success
medium
59.7s · 592/4919t · $0.0405
SCAD (70 lines)
// Butt hinge (opened 180°)
// Parameters
plate_len = 30;           // along Y
plate_w   = 25;           // along X (each leaf)
plate_t   = 2;            // thickness (Z)
kn_seg    = 6;            // single knuckle length
kn_count  = 5;            // total knuckle pieces
kn_od     = 8;            // knuckle outer Ø
kn_id     = 4.6;          // knuckle inner Ø (pin clearance)
pin_d     = 4;            // pin Ø
pin_len   = plate_len+2;  // 32 mm (30 + 1 + 1)

// Convenience
$fn = 64;

// ---------- Modules ----------
module cyl_y(h,r,center=false)
    rotate([90,0,0]) cylinder(h=h,r=r,center=center);

module knuckle_seg(len=kn_seg, od=kn_od/2, id=kn_id/2)
difference(){
    cyl_y(len, od);
    cyl_y(len+0.2, id);     // a bit longer for clean subtraction
}

module countersunk_hole()
union(){
    translate([0,0,-2]) cylinder(h=6,r=3.2/2,$fn=32);   // through M3.2
    translate([0,0,0])  cylinder(h=1,r=6/2,$fn=32);     // 6 mm Ø, 1 mm deep
}

module leaf(is_left=true){
    // X positions
    plate_x = is_left ? -(kn_od/2) - plate_w :  kn_od/2;
    hole_x  = is_left ? -(kn_od/2) - plate_w/2 : kn_od/2 + plate_w/2;

    difference(){
        // Solid parts
        union(){
            // plate
            translate([plate_x,0,-plate_t/2])
                cube([plate_w, plate_len, plate_t]);

            // knuckles
            if(is_left){
                for(i=[0,2,4])
                    translate([0,i*kn_seg,0]) knuckle_seg();
            }else{
                for(i=[1,3])
                    translate([0,i*kn_seg,0]) knuckle_seg();
            }
        }

        // screw holes (Y positions 6 mm, 14 mm, 22 mm from one end)
        for(y=[6,14,22])
            translate([hole_x,y,plate_t/2])
                countersunk_hole();
    }
}

module pin(){
    translate([0,-1,0]) cyl_y(pin_len, pin_d/2, false);
}

// ---------- Assembly ----------
union(){
    leaf(true);   // left leaf
    leaf(false);  // right leaf
    pin();        // hinge pin
}
high success
high
115.9s · 592/9048t · $0.0736
SCAD (72 lines)
$fn = 64;

// ---------- Parameters ----------
leaf_w            = 25;      // width (X direction)
leaf_h            = 30;      // height (Y direction)
plate_t           = 2;       // thickness (Z direction)

knuckle_od        = 8;       // outer diameter
knuckle_id        = 4.6;     // inner diameter (pin clearance)
knuckle_len       = 6;       // length of each knuckle segment
segments_total    = 5;       // total knuckles (fixed)

pin_d             = 4;       // pin diameter
pin_len           = leaf_h + 2; // 32 mm (1 mm overhang per end)

hole_cs_d         = 6;       // countersink diameter
hole_cs_depth     = 1;       // countersink depth
hole_thru_d       = 3.2;     // through-hole diameter
hole_ypos         = [6,14,22]; // Y positions of screw holes

// ---------- Modules ----------
module knuckle(y0){
    translate([0,y0,0])
        rotate([-90,0,0])
            difference(){
                cylinder(d=knuckle_od, h=knuckle_len, center=false);
                cylinder(d=knuckle_id, h=knuckle_len, center=false);
            }
}

module screw_hole(){
    union(){
        // countersink (taper simplified as cone)
        translate([0,0,plate_t - hole_cs_depth])
            cylinder(h=hole_cs_depth, d1=hole_cs_d, d2=hole_thru_d, center=false);
        // through hole
        cylinder(h=plate_t - hole_cs_depth, d=hole_thru_d, center=false);
    }
}

module leaf(side="left"){
    s         = (side=="left") ? -1 :  1;           // -1 for left, +1 for right
    plate_x0  = (s==-1)        ? -4 - leaf_w : 4;   // plate origin X
    plate_xc  = plate_x0 + leaf_w/2;                // hole center X
    segs      = (side=="left") ? [0,2,4]  : [1,3];  // knuckle indices

    difference(){
        union(){
            // plate
            translate([plate_x0,0,0])
                cube([leaf_w, leaf_h, plate_t]);
            // knuckles
            for(i = segs)
                knuckle(i * knuckle_len);
        }
        // screw holes
        for(yh = hole_ypos)
            translate([plate_xc, yh, 0])
                screw_hole();
    }
}

module pin(){
    translate([0,-1,0])          // 1 mm overhang at each end
        rotate([-90,0,0])
            cylinder(d=pin_d, h=pin_len, center=false);
}

// ---------- Assembly ----------
leaf("left");
leaf("right");
pin();
maxnot run
xhighnot run

iteration: iter-png

i1 success
iter 1
66.6s · 1965/3596t · $0.0327
diff vs bare: +39/-31
  // Butt hinge (opened 180°)
- // Parameters
- plate_len = 30;           // along Y
- plate_w   = 25;           // along X (each leaf)
- plate_t   = 2;            // thickness (Z)
- kn_seg    = 6;            // single knuckle length
- kn_count  = 5;            // total knuckle pieces
- kn_od     = 8;            // knuckle outer Ø
- kn_id     = 4.6;          // knuckle inner Ø (pin clearance)
- pin_d     = 4;            // pin Ø
- pin_len   = plate_len+2;  // 32 mm (30 + 1 + 1)
  
- // Convenience
+ // ---------- Parameters ----------
+ plate_len = 30;          // Y-length of each leaf
+ plate_w   = 25;          // X-width  of each leaf
+ plate_t   = 2;           // thickness (Z)
+ kn_seg    = 6;           // single knuckle length
+ kn_count  = 5;           // total knuckles
+ kn_od     = 8;           // knuckle outer Ø
+ kn_id     = 4.6;         // knuckle inner Ø (pin clearance)
+ pin_d     = 4;           // pin Ø
+ pin_len   = plate_len+2; // 32 mm  (1 mm overhang each end)
+ 
+ // ---------- Rendering quality ----------
  $fn = 64;
  
- // ---------- Modules ----------
+ // ---------- Helper : cylinder along Y ----------
  module cyl_y(h,r,center=false)
      rotate([90,0,0]) cylinder(h=h,r=r,center=center);
  
- module knuckle_seg(len=kn_seg, od=kn_od/2, id=kn_id/2)
+ // ---------- Knuckle segment ----------
+ module knuckle_seg()
  difference(){
-     cyl_y(len, od);
-     cyl_y(len+0.2, id);     // a bit longer for clean subtraction
+     cyl_y(kn_seg, kn_od/2);
+     cyl_y(kn_seg+0.2, kn_id/2);   // slightly longer for clean cut
  }
  
+ // ---------- Countersunk M3 hole ----------
  module countersunk_hole()
  union(){
-     translate([0,0,-2]) cylinder(h=6,r=3.2/2,$fn=32);   // through M3.2
-     translate([0,0,0])  cylinder(h=1,r=6/2,$fn=32);     // 6 mm Ø, 1 mm deep
+     // Through hole (3.2 mm) – centred, long enough to pass the plate
+     cylinder(h=plate_t+4, r=3.2/2, center=true, $fn=32);
+     // 6 mm Ø, 1 mm deep countersink from top face
+     translate([0,0, plate_t/2 - 1])
+         cylinder(h=1, r=6/2, center=false, $fn=32);
  }
  
+ // ---------- Leaf (left / right) ----------
  module leaf(is_left=true){
-     // X positions
-     plate_x = is_left ? -(kn_od/2) - plate_w :  kn_od/2;
+     // X-positions
+     plate_x = is_left ? -(kn_od/2) - plate_w : kn_od/2;
      hole_x  = is_left ? -(kn_od/2) - plate_w/2 : kn_od/2 + plate_w/2;
  
      difference(){
-         // Solid parts
+         // Solid geometry
          union(){
-             // plate
-             translate([plate_x,0,-plate_t/2])
+             // Plate
+             translate([plate_x, 0, -plate_t/2])
                  cube([plate_w, plate_len, plate_t]);
  
-             // knuckles
+             // Knuckles (0-based index of 5 segments)
              if(is_left){
                  for(i=[0,2,4])
-                     translate([0,i*kn_seg,0]) knuckle_seg();
-             }else{
+                     translate([0, i*kn_seg, 0]) knuckle_seg();
+             } else {
                  for(i=[1,3])
-                     translate([0,i*kn_seg,0]) knuckle_seg();
+                     translate([0, i*kn_seg, 0]) knuckle_seg();
              }
          }
  
-         // screw holes (Y positions 6 mm, 14 mm, 22 mm from one end)
-         for(y=[6,14,22])
-             translate([hole_x,y,plate_t/2])
-                 countersunk_hole();
+         // Screw holes – Y positions 7 mm, 15 mm, 23 mm (8 mm pitch)
+         for(y=[7,15,23])
+             translate([hole_x, y, 0]) countersunk_hole();
      }
  }
  
+ // ---------- Pin ----------
  module pin(){
+     // Shift –1 mm so it projects 1 mm beyond each end of the 30 mm knuckle stack
      translate([0,-1,0]) cyl_y(pin_len, pin_d/2, false);
  }
  
  // ---------- Assembly ----------
  union(){
      leaf(true);   // left leaf
      leaf(false);  // right leaf
-     pin();        // hinge pin
+     pin();        // central pin
  }
SCAD (78 lines)
// Butt hinge (opened 180°)

// ---------- Parameters ----------
plate_len = 30;          // Y-length of each leaf
plate_w   = 25;          // X-width  of each leaf
plate_t   = 2;           // thickness (Z)
kn_seg    = 6;           // single knuckle length
kn_count  = 5;           // total knuckles
kn_od     = 8;           // knuckle outer Ø
kn_id     = 4.6;         // knuckle inner Ø (pin clearance)
pin_d     = 4;           // pin Ø
pin_len   = plate_len+2; // 32 mm  (1 mm overhang each end)

// ---------- Rendering quality ----------
$fn = 64;

// ---------- Helper : cylinder along Y ----------
module cyl_y(h,r,center=false)
    rotate([90,0,0]) cylinder(h=h,r=r,center=center);

// ---------- Knuckle segment ----------
module knuckle_seg()
difference(){
    cyl_y(kn_seg, kn_od/2);
    cyl_y(kn_seg+0.2, kn_id/2);   // slightly longer for clean cut
}

// ---------- Countersunk M3 hole ----------
module countersunk_hole()
union(){
    // Through hole (3.2 mm) – centred, long enough to pass the plate
    cylinder(h=plate_t+4, r=3.2/2, center=true, $fn=32);
    // 6 mm Ø, 1 mm deep countersink from top face
    translate([0,0, plate_t/2 - 1])
        cylinder(h=1, r=6/2, center=false, $fn=32);
}

// ---------- Leaf (left / right) ----------
module leaf(is_left=true){
    // X-positions
    plate_x = is_left ? -(kn_od/2) - plate_w : kn_od/2;
    hole_x  = is_left ? -(kn_od/2) - plate_w/2 : kn_od/2 + plate_w/2;

    difference(){
        // Solid geometry
        union(){
            // Plate
            translate([plate_x, 0, -plate_t/2])
                cube([plate_w, plate_len, plate_t]);

            // Knuckles (0-based index of 5 segments)
            if(is_left){
                for(i=[0,2,4])
                    translate([0, i*kn_seg, 0]) knuckle_seg();
            } else {
                for(i=[1,3])
                    translate([0, i*kn_seg, 0]) knuckle_seg();
            }
        }

        // Screw holes – Y positions 7 mm, 15 mm, 23 mm (8 mm pitch)
        for(y=[7,15,23])
            translate([hole_x, y, 0]) countersunk_hole();
    }
}

// ---------- Pin ----------
module pin(){
    // Shift –1 mm so it projects 1 mm beyond each end of the 30 mm knuckle stack
    translate([0,-1,0]) cyl_y(pin_len, pin_d/2, false);
}

// ---------- Assembly ----------
union(){
    leaf(true);   // left leaf
    leaf(false);  // right leaf
    pin();        // central pin
}
i2 success
iter 2
60.1s · 2052/4146t · $0.0373
diff vs i1: +27/-23
  // Butt hinge (opened 180°)
  
  // ---------- Parameters ----------
  plate_len = 30;          // Y-length of each leaf
  plate_w   = 25;          // X-width  of each leaf
  plate_t   = 2;           // thickness (Z)
+ 
  kn_seg    = 6;           // single knuckle length
  kn_count  = 5;           // total knuckles
  kn_od     = 8;           // knuckle outer Ø
- kn_id     = 4.6;         // knuckle inner Ø (pin clearance)
+ kn_id     = 4.6;         // knuckle inner Ø (pin Ø 4 + 0.3 clearance)
+ 
  pin_d     = 4;           // pin Ø
- pin_len   = plate_len+2; // 32 mm  (1 mm overhang each end)
+ pin_len   = plate_len+2; // 32 mm  (1 mm over-hang each end)
  
  // ---------- Rendering quality ----------
  $fn = 64;
  
  // ---------- Helper : cylinder along Y ----------
- module cyl_y(h,r,center=false)
-     rotate([90,0,0]) cylinder(h=h,r=r,center=center);
+ module cyl_y(h, r, center=false)
+     rotate([90,0,0]) cylinder(h=h, r=r, center=center);
  
- // ---------- Knuckle segment ----------
+ // ---------- Knuckle segment (hollow) ----------
  module knuckle_seg()
  difference(){
      cyl_y(kn_seg, kn_od/2);
-     cyl_y(kn_seg+0.2, kn_id/2);   // slightly longer for clean cut
+     cyl_y(kn_seg + 0.2, kn_id/2);   // slightly longer for clean cut
  }
  
- // ---------- Countersunk M3 hole ----------
- module countersunk_hole()
- union(){
-     // Through hole (3.2 mm) – centred, long enough to pass the plate
-     cylinder(h=plate_t+4, r=3.2/2, center=true, $fn=32);
-     // 6 mm Ø, 1 mm deep countersink from top face
-     translate([0,0, plate_t/2 - 1])
-         cylinder(h=1, r=6/2, center=false, $fn=32);
+ // ---------- Countersunk M3 hole (6 mm Ø, 1 mm deep 90° taper + Ø3.2 through) ----------
+ module countersunk_hole(){
+     union(){
+         // 3.2 mm through hole (slightly longer than plate thickness)
+         translate([0,0,-(plate_t/2+0.2)])
+             cylinder(h=plate_t+0.4, r=3.2/2, $fn=32);
+         // Conical countersink: Ø6 mm → Ø3.2 mm, depth 1 mm from top surface
+         translate([0,0,plate_t/2-1])
+             cylinder(h=1, r1=6/2, r2=3.2/2, $fn=64);
+     }
  }
  
  // ---------- Leaf (left / right) ----------
  module leaf(is_left=true){
-     // X-positions
-     plate_x = is_left ? -(kn_od/2) - plate_w : kn_od/2;
-     hole_x  = is_left ? -(kn_od/2) - plate_w/2 : kn_od/2 + plate_w/2;
+     // X-offsets
+     plate_x = is_left ? -(kn_od/2) - plate_w :  kn_od/2;          // plate anchor
+     hole_x  = is_left ? -(kn_od/2) - plate_w/2 : kn_od/2 + plate_w/2; // hole line
  
      difference(){
-         // Solid geometry
+         // Solid part (plate + knuckles)
          union(){
              // Plate
              translate([plate_x, 0, -plate_t/2])
                  cube([plate_w, plate_len, plate_t]);
  
-             // Knuckles (0-based index of 5 segments)
+             // Knuckles (0-based indices)
              if(is_left){
                  for(i=[0,2,4])
                      translate([0, i*kn_seg, 0]) knuckle_seg();
              } else {
                  for(i=[1,3])
                      translate([0, i*kn_seg, 0]) knuckle_seg();
              }
          }
  
-         // Screw holes – Y positions 7 mm, 15 mm, 23 mm (8 mm pitch)
+         // Screw holes – Y positions 7 mm, 15 mm, 23 mm  (8 mm pitch)
          for(y=[7,15,23])
              translate([hole_x, y, 0]) countersunk_hole();
      }
  }
  
  // ---------- Pin ----------
  module pin(){
      // Shift –1 mm so it projects 1 mm beyond each end of the 30 mm knuckle stack
      translate([0,-1,0]) cyl_y(pin_len, pin_d/2, false);
  }
  
  // ---------- Assembly ----------
  union(){
-     leaf(true);   // left leaf
-     leaf(false);  // right leaf
-     pin();        // central pin
+     leaf(true);   // left leaf (x < 0)
+     leaf(false);  // right leaf (x > 0)
+     pin();        // shared pin
  }
SCAD (82 lines)
// Butt hinge (opened 180°)

// ---------- Parameters ----------
plate_len = 30;          // Y-length of each leaf
plate_w   = 25;          // X-width  of each leaf
plate_t   = 2;           // thickness (Z)

kn_seg    = 6;           // single knuckle length
kn_count  = 5;           // total knuckles
kn_od     = 8;           // knuckle outer Ø
kn_id     = 4.6;         // knuckle inner Ø (pin Ø 4 + 0.3 clearance)

pin_d     = 4;           // pin Ø
pin_len   = plate_len+2; // 32 mm  (1 mm over-hang each end)

// ---------- Rendering quality ----------
$fn = 64;

// ---------- Helper : cylinder along Y ----------
module cyl_y(h, r, center=false)
    rotate([90,0,0]) cylinder(h=h, r=r, center=center);

// ---------- Knuckle segment (hollow) ----------
module knuckle_seg()
difference(){
    cyl_y(kn_seg, kn_od/2);
    cyl_y(kn_seg + 0.2, kn_id/2);   // slightly longer for clean cut
}

// ---------- Countersunk M3 hole (6 mm Ø, 1 mm deep 90° taper + Ø3.2 through) ----------
module countersunk_hole(){
    union(){
        // 3.2 mm through hole (slightly longer than plate thickness)
        translate([0,0,-(plate_t/2+0.2)])
            cylinder(h=plate_t+0.4, r=3.2/2, $fn=32);
        // Conical countersink: Ø6 mm → Ø3.2 mm, depth 1 mm from top surface
        translate([0,0,plate_t/2-1])
            cylinder(h=1, r1=6/2, r2=3.2/2, $fn=64);
    }
}

// ---------- Leaf (left / right) ----------
module leaf(is_left=true){
    // X-offsets
    plate_x = is_left ? -(kn_od/2) - plate_w :  kn_od/2;          // plate anchor
    hole_x  = is_left ? -(kn_od/2) - plate_w/2 : kn_od/2 + plate_w/2; // hole line

    difference(){
        // Solid part (plate + knuckles)
        union(){
            // Plate
            translate([plate_x, 0, -plate_t/2])
                cube([plate_w, plate_len, plate_t]);

            // Knuckles (0-based indices)
            if(is_left){
                for(i=[0,2,4])
                    translate([0, i*kn_seg, 0]) knuckle_seg();
            } else {
                for(i=[1,3])
                    translate([0, i*kn_seg, 0]) knuckle_seg();
            }
        }

        // Screw holes – Y positions 7 mm, 15 mm, 23 mm  (8 mm pitch)
        for(y=[7,15,23])
            translate([hole_x, y, 0]) countersunk_hole();
    }
}

// ---------- Pin ----------
module pin(){
    // Shift –1 mm so it projects 1 mm beyond each end of the 30 mm knuckle stack
    translate([0,-1,0]) cyl_y(pin_len, pin_d/2, false);
}

// ---------- Assembly ----------
union(){
    leaf(true);   // left leaf (x < 0)
    leaf(false);  // right leaf (x > 0)
    pin();        // shared pin
}
i3 success
iter 3
119.8s · 2140/7169t · $0.0616
diff vs i2: +0/-0
  // Butt hinge (opened 180°)
  
  // ---------- Parameters ----------
  plate_len = 30;          // Y-length of each leaf
  plate_w   = 25;          // X-width  of each leaf
  plate_t   = 2;           // thickness (Z)
  
  kn_seg    = 6;           // single knuckle length
  kn_count  = 5;           // total knuckles
  kn_od     = 8;           // knuckle outer Ø
  kn_id     = 4.6;         // knuckle inner Ø (pin Ø 4 + 0.3 clearance)
  
  pin_d     = 4;           // pin Ø
  pin_len   = plate_len+2; // 32 mm  (1 mm over-hang each end)
  
  // ---------- Rendering quality ----------
  $fn = 64;
  
  // ---------- Helper : cylinder along Y ----------
  module cyl_y(h, r, center=false)
      rotate([90,0,0]) cylinder(h=h, r=r, center=center);
  
  // ---------- Knuckle segment (hollow) ----------
  module knuckle_seg()
  difference(){
      cyl_y(kn_seg, kn_od/2);
      cyl_y(kn_seg + 0.2, kn_id/2);   // slightly longer for clean cut
  }
  
  // ---------- Countersunk M3 hole (6 mm Ø, 1 mm deep 90° taper + Ø3.2 through) ----------
  module countersunk_hole(){
      union(){
          // 3.2 mm through hole (slightly longer than plate thickness)
          translate([0,0,-(plate_t/2+0.2)])
              cylinder(h=plate_t+0.4, r=3.2/2, $fn=32);
          // Conical countersink: Ø6 mm → Ø3.2 mm, depth 1 mm from top surface
          translate([0,0,plate_t/2-1])
              cylinder(h=1, r1=6/2, r2=3.2/2, $fn=64);
      }
  }
  
  // ---------- Leaf (left / right) ----------
  module leaf(is_left=true){
      // X-offsets
      plate_x = is_left ? -(kn_od/2) - plate_w :  kn_od/2;          // plate anchor
      hole_x  = is_left ? -(kn_od/2) - plate_w/2 : kn_od/2 + plate_w/2; // hole line
  
      difference(){
          // Solid part (plate + knuckles)
          union(){
              // Plate
              translate([plate_x, 0, -plate_t/2])
                  cube([plate_w, plate_len, plate_t]);
  
              // Knuckles (0-based indices)
              if(is_left){
                  for(i=[0,2,4])
                      translate([0, i*kn_seg, 0]) knuckle_seg();
              } else {
                  for(i=[1,3])
                      translate([0, i*kn_seg, 0]) knuckle_seg();
              }
          }
  
          // Screw holes – Y positions 7 mm, 15 mm, 23 mm  (8 mm pitch)
          for(y=[7,15,23])
              translate([hole_x, y, 0]) countersunk_hole();
      }
  }
  
  // ---------- Pin ----------
  module pin(){
      // Shift –1 mm so it projects 1 mm beyond each end of the 30 mm knuckle stack
      translate([0,-1,0]) cyl_y(pin_len, pin_d/2, false);
  }
  
  // ---------- Assembly ----------
  union(){
      leaf(true);   // left leaf (x < 0)
      leaf(false);  // right leaf (x > 0)
      pin();        // shared pin
  }
SCAD (82 lines)
// Butt hinge (opened 180°)

// ---------- Parameters ----------
plate_len = 30;          // Y-length of each leaf
plate_w   = 25;          // X-width  of each leaf
plate_t   = 2;           // thickness (Z)

kn_seg    = 6;           // single knuckle length
kn_count  = 5;           // total knuckles
kn_od     = 8;           // knuckle outer Ø
kn_id     = 4.6;         // knuckle inner Ø (pin Ø 4 + 0.3 clearance)

pin_d     = 4;           // pin Ø
pin_len   = plate_len+2; // 32 mm  (1 mm over-hang each end)

// ---------- Rendering quality ----------
$fn = 64;

// ---------- Helper : cylinder along Y ----------
module cyl_y(h, r, center=false)
    rotate([90,0,0]) cylinder(h=h, r=r, center=center);

// ---------- Knuckle segment (hollow) ----------
module knuckle_seg()
difference(){
    cyl_y(kn_seg, kn_od/2);
    cyl_y(kn_seg + 0.2, kn_id/2);   // slightly longer for clean cut
}

// ---------- Countersunk M3 hole (6 mm Ø, 1 mm deep 90° taper + Ø3.2 through) ----------
module countersunk_hole(){
    union(){
        // 3.2 mm through hole (slightly longer than plate thickness)
        translate([0,0,-(plate_t/2+0.2)])
            cylinder(h=plate_t+0.4, r=3.2/2, $fn=32);
        // Conical countersink: Ø6 mm → Ø3.2 mm, depth 1 mm from top surface
        translate([0,0,plate_t/2-1])
            cylinder(h=1, r1=6/2, r2=3.2/2, $fn=64);
    }
}

// ---------- Leaf (left / right) ----------
module leaf(is_left=true){
    // X-offsets
    plate_x = is_left ? -(kn_od/2) - plate_w :  kn_od/2;          // plate anchor
    hole_x  = is_left ? -(kn_od/2) - plate_w/2 : kn_od/2 + plate_w/2; // hole line

    difference(){
        // Solid part (plate + knuckles)
        union(){
            // Plate
            translate([plate_x, 0, -plate_t/2])
                cube([plate_w, plate_len, plate_t]);

            // Knuckles (0-based indices)
            if(is_left){
                for(i=[0,2,4])
                    translate([0, i*kn_seg, 0]) knuckle_seg();
            } else {
                for(i=[1,3])
                    translate([0, i*kn_seg, 0]) knuckle_seg();
            }
        }

        // Screw holes – Y positions 7 mm, 15 mm, 23 mm  (8 mm pitch)
        for(y=[7,15,23])
            translate([hole_x, y, 0]) countersunk_hole();
    }
}

// ---------- Pin ----------
module pin(){
    // Shift –1 mm so it projects 1 mm beyond each end of the 30 mm knuckle stack
    translate([0,-1,0]) cyl_y(pin_len, pin_d/2, false);
}

// ---------- Assembly ----------
union(){
    leaf(true);   // left leaf (x < 0)
    leaf(false);  // right leaf (x > 0)
    pin();        // shared pin
}