vibe-openscad

tier-3-butt-hinge / gpt-5.3-codex

5 run / 累計 62.0s / 累計 $0.0702

openai gpt 5.3 codex bare

bare (provider default effort)

run detail →
render
bare render of tier-3-butt-hinge
loading STL…
success 14.9s · 592/975t · $0.0126
SCAD (104 lines)
$fn = 96;

// ===== Parameters =====
leaf_len_y      = 30;    // along hinge axis
leaf_width_x    = 25;    // opening direction
leaf_thick_z    = 2;

pin_d           = 4;
pin_r           = pin_d/2;
pin_len         = 32;

knuckle_od      = 8;
knuckle_or      = knuckle_od/2;
knuckle_id      = 4.6;   // pin + 0.3 clearance
knuckle_ir      = knuckle_id/2;
knuckle_seg     = 6;     // 30/5

csk_thru_d      = 3.2;
csk_head_d      = 6;
csk_depth       = 1;

y0 = -leaf_len_y/2;      // start of knuckle stack (-15)
z_face = leaf_thick_z/2; // plates occupy z in [-1, +1]

// Knuckle segment centers (5 equal 6mm segments across 30mm)
function seg_center(i) = y0 + knuckle_seg*i + knuckle_seg/2;

// Left leaf has segments: 0,2,4
left_idx  = [0,2,4];
// Right leaf has segments: 1,3
right_idx = [1,3];

// Screw hole Y positions (8mm pitch, centered)
hole_y = [-8, 0, 8];

// ===== Modules =====
module countersunk_hole(z0, z1) {
    // through hole
    translate([0,0,z0-0.1])
        cylinder(h=(z1-z0)+0.2, r=csk_thru_d/2);

    // tapered countersink from top surface
    // top diameter 6, bottom diameter 3.2, depth 1
    translate([0,0,z1-csk_depth])
        cylinder(h=csk_depth+0.01, r1=csk_thru_d/2, r2=csk_head_d/2);
}

module leaf_base(side=1) {
    // side=+1 => right leaf (x>0), side=-1 => left leaf (x<0)
    x0 = (side > 0) ? 0 : -leaf_width_x;
    translate([x0, y0, -leaf_thick_z/2])
        cube([leaf_width_x, leaf_len_y, leaf_thick_z], center=false);
}

module knuckle_shell(yc, side=1) {
    // Outer knuckle body attached to leaf edge at x=0
    intersection() {
        translate([0, yc, 0])
            rotate([90,0,0])
                cylinder(h=knuckle_seg, r=knuckle_or, center=true);
        // keep half by side
        translate([(side>0)?0:-knuckle_or, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
            cube([knuckle_or, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
    }
}

module leaf_with_knuckles(side=1) {
    difference() {
        union() {
            leaf_base(side);

            idxs = (side > 0) ? right_idx : left_idx;
            for (i = idxs)
                knuckle_shell(seg_center(i), side);
        }

        // knuckle bore (only where material exists)
        for (i = (side > 0) ? right_idx : left_idx) {
            translate([0, seg_center(i), 0])
                rotate([90,0,0])
                    cylinder(h=knuckle_seg+0.2, r=knuckle_ir, center=true);
        }

        // 3 countersunk holes near free edge of each leaf
        hx = (side > 0) ? (leaf_width_x - 5) : (-leaf_width_x + 5);
        for (yy = hole_y) {
            translate([hx, yy, 0])
                countersunk_hole(-leaf_thick_z/2, leaf_thick_z/2);
        }
    }
}

module pin_axis() {
    translate([0, 0, 0])
        rotate([90,0,0])
            cylinder(h=pin_len, r=pin_r, center=true);
}

// ===== Assembly (180° open) =====
union() {
    leaf_with_knuckles(-1); // left, x<0
    leaf_with_knuckles( 1); // right, x>0
    pin_axis();
}
パラメータ (11)
スライダを動かすと 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

lownot run
medium (default) success
medium
14.9s · 592/975t · $0.0126
SCAD (104 lines)
$fn = 96;

// ===== Parameters =====
leaf_len_y      = 30;    // along hinge axis
leaf_width_x    = 25;    // opening direction
leaf_thick_z    = 2;

pin_d           = 4;
pin_r           = pin_d/2;
pin_len         = 32;

knuckle_od      = 8;
knuckle_or      = knuckle_od/2;
knuckle_id      = 4.6;   // pin + 0.3 clearance
knuckle_ir      = knuckle_id/2;
knuckle_seg     = 6;     // 30/5

csk_thru_d      = 3.2;
csk_head_d      = 6;
csk_depth       = 1;

y0 = -leaf_len_y/2;      // start of knuckle stack (-15)
z_face = leaf_thick_z/2; // plates occupy z in [-1, +1]

// Knuckle segment centers (5 equal 6mm segments across 30mm)
function seg_center(i) = y0 + knuckle_seg*i + knuckle_seg/2;

// Left leaf has segments: 0,2,4
left_idx  = [0,2,4];
// Right leaf has segments: 1,3
right_idx = [1,3];

// Screw hole Y positions (8mm pitch, centered)
hole_y = [-8, 0, 8];

// ===== Modules =====
module countersunk_hole(z0, z1) {
    // through hole
    translate([0,0,z0-0.1])
        cylinder(h=(z1-z0)+0.2, r=csk_thru_d/2);

    // tapered countersink from top surface
    // top diameter 6, bottom diameter 3.2, depth 1
    translate([0,0,z1-csk_depth])
        cylinder(h=csk_depth+0.01, r1=csk_thru_d/2, r2=csk_head_d/2);
}

module leaf_base(side=1) {
    // side=+1 => right leaf (x>0), side=-1 => left leaf (x<0)
    x0 = (side > 0) ? 0 : -leaf_width_x;
    translate([x0, y0, -leaf_thick_z/2])
        cube([leaf_width_x, leaf_len_y, leaf_thick_z], center=false);
}

module knuckle_shell(yc, side=1) {
    // Outer knuckle body attached to leaf edge at x=0
    intersection() {
        translate([0, yc, 0])
            rotate([90,0,0])
                cylinder(h=knuckle_seg, r=knuckle_or, center=true);
        // keep half by side
        translate([(side>0)?0:-knuckle_or, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
            cube([knuckle_or, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
    }
}

module leaf_with_knuckles(side=1) {
    difference() {
        union() {
            leaf_base(side);

            idxs = (side > 0) ? right_idx : left_idx;
            for (i = idxs)
                knuckle_shell(seg_center(i), side);
        }

        // knuckle bore (only where material exists)
        for (i = (side > 0) ? right_idx : left_idx) {
            translate([0, seg_center(i), 0])
                rotate([90,0,0])
                    cylinder(h=knuckle_seg+0.2, r=knuckle_ir, center=true);
        }

        // 3 countersunk holes near free edge of each leaf
        hx = (side > 0) ? (leaf_width_x - 5) : (-leaf_width_x + 5);
        for (yy = hole_y) {
            translate([hx, yy, 0])
                countersunk_hole(-leaf_thick_z/2, leaf_thick_z/2);
        }
    }
}

module pin_axis() {
    translate([0, 0, 0])
        rotate([90,0,0])
            cylinder(h=pin_len, r=pin_r, center=true);
}

// ===== Assembly (180° open) =====
union() {
    leaf_with_knuckles(-1); // left, x<0
    leaf_with_knuckles( 1); // right, x>0
    pin_axis();
}
highnot run
maxnot run
xhighnot run

iteration: iter-png

i1 success
iter 1
9.9s · 2232/954t · $0.0148
diff vs bare: +0/-1
  $fn = 96;
  
  // ===== Parameters =====
  leaf_len_y      = 30;    // along hinge axis
  leaf_width_x    = 25;    // opening direction
  leaf_thick_z    = 2;
  
  pin_d           = 4;
  pin_r           = pin_d/2;
  pin_len         = 32;
  
  knuckle_od      = 8;
  knuckle_or      = knuckle_od/2;
  knuckle_id      = 4.6;   // pin + 0.3 clearance
  knuckle_ir      = knuckle_id/2;
  knuckle_seg     = 6;     // 30/5
  
  csk_thru_d      = 3.2;
  csk_head_d      = 6;
  csk_depth       = 1;
  
  y0 = -leaf_len_y/2;      // start of knuckle stack (-15)
- z_face = leaf_thick_z/2; // plates occupy z in [-1, +1]
  
  // Knuckle segment centers (5 equal 6mm segments across 30mm)
  function seg_center(i) = y0 + knuckle_seg*i + knuckle_seg/2;
  
  // Left leaf has segments: 0,2,4
  left_idx  = [0,2,4];
  // Right leaf has segments: 1,3
  right_idx = [1,3];
  
  // Screw hole Y positions (8mm pitch, centered)
  hole_y = [-8, 0, 8];
  
  // ===== Modules =====
  module countersunk_hole(z0, z1) {
      // through hole
      translate([0,0,z0-0.1])
          cylinder(h=(z1-z0)+0.2, r=csk_thru_d/2);
  
      // tapered countersink from top surface
      // top diameter 6, bottom diameter 3.2, depth 1
      translate([0,0,z1-csk_depth])
          cylinder(h=csk_depth+0.01, r1=csk_thru_d/2, r2=csk_head_d/2);
  }
  
  module leaf_base(side=1) {
      // side=+1 => right leaf (x>0), side=-1 => left leaf (x<0)
      x0 = (side > 0) ? 0 : -leaf_width_x;
      translate([x0, y0, -leaf_thick_z/2])
          cube([leaf_width_x, leaf_len_y, leaf_thick_z], center=false);
  }
  
  module knuckle_shell(yc, side=1) {
      // Outer knuckle body attached to leaf edge at x=0
      intersection() {
          translate([0, yc, 0])
              rotate([90,0,0])
                  cylinder(h=knuckle_seg, r=knuckle_or, center=true);
          // keep half by side
          translate([(side>0)?0:-knuckle_or, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
              cube([knuckle_or, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
      }
  }
  
  module leaf_with_knuckles(side=1) {
      difference() {
          union() {
              leaf_base(side);
  
              idxs = (side > 0) ? right_idx : left_idx;
              for (i = idxs)
                  knuckle_shell(seg_center(i), side);
          }
  
          // knuckle bore (only where material exists)
          for (i = (side > 0) ? right_idx : left_idx) {
              translate([0, seg_center(i), 0])
                  rotate([90,0,0])
                      cylinder(h=knuckle_seg+0.2, r=knuckle_ir, center=true);
          }
  
          // 3 countersunk holes near free edge of each leaf
          hx = (side > 0) ? (leaf_width_x - 5) : (-leaf_width_x + 5);
          for (yy = hole_y) {
              translate([hx, yy, 0])
                  countersunk_hole(-leaf_thick_z/2, leaf_thick_z/2);
          }
      }
  }
  
  module pin_axis() {
      translate([0, 0, 0])
          rotate([90,0,0])
              cylinder(h=pin_len, r=pin_r, center=true);
  }
  
  // ===== Assembly (180° open) =====
  union() {
      leaf_with_knuckles(-1); // left, x<0
      leaf_with_knuckles( 1); // right, x>0
      pin_axis();
  }
SCAD (103 lines)
$fn = 96;

// ===== Parameters =====
leaf_len_y      = 30;    // along hinge axis
leaf_width_x    = 25;    // opening direction
leaf_thick_z    = 2;

pin_d           = 4;
pin_r           = pin_d/2;
pin_len         = 32;

knuckle_od      = 8;
knuckle_or      = knuckle_od/2;
knuckle_id      = 4.6;   // pin + 0.3 clearance
knuckle_ir      = knuckle_id/2;
knuckle_seg     = 6;     // 30/5

csk_thru_d      = 3.2;
csk_head_d      = 6;
csk_depth       = 1;

y0 = -leaf_len_y/2;      // start of knuckle stack (-15)

// Knuckle segment centers (5 equal 6mm segments across 30mm)
function seg_center(i) = y0 + knuckle_seg*i + knuckle_seg/2;

// Left leaf has segments: 0,2,4
left_idx  = [0,2,4];
// Right leaf has segments: 1,3
right_idx = [1,3];

// Screw hole Y positions (8mm pitch, centered)
hole_y = [-8, 0, 8];

// ===== Modules =====
module countersunk_hole(z0, z1) {
    // through hole
    translate([0,0,z0-0.1])
        cylinder(h=(z1-z0)+0.2, r=csk_thru_d/2);

    // tapered countersink from top surface
    // top diameter 6, bottom diameter 3.2, depth 1
    translate([0,0,z1-csk_depth])
        cylinder(h=csk_depth+0.01, r1=csk_thru_d/2, r2=csk_head_d/2);
}

module leaf_base(side=1) {
    // side=+1 => right leaf (x>0), side=-1 => left leaf (x<0)
    x0 = (side > 0) ? 0 : -leaf_width_x;
    translate([x0, y0, -leaf_thick_z/2])
        cube([leaf_width_x, leaf_len_y, leaf_thick_z], center=false);
}

module knuckle_shell(yc, side=1) {
    // Outer knuckle body attached to leaf edge at x=0
    intersection() {
        translate([0, yc, 0])
            rotate([90,0,0])
                cylinder(h=knuckle_seg, r=knuckle_or, center=true);
        // keep half by side
        translate([(side>0)?0:-knuckle_or, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
            cube([knuckle_or, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
    }
}

module leaf_with_knuckles(side=1) {
    difference() {
        union() {
            leaf_base(side);

            idxs = (side > 0) ? right_idx : left_idx;
            for (i = idxs)
                knuckle_shell(seg_center(i), side);
        }

        // knuckle bore (only where material exists)
        for (i = (side > 0) ? right_idx : left_idx) {
            translate([0, seg_center(i), 0])
                rotate([90,0,0])
                    cylinder(h=knuckle_seg+0.2, r=knuckle_ir, center=true);
        }

        // 3 countersunk holes near free edge of each leaf
        hx = (side > 0) ? (leaf_width_x - 5) : (-leaf_width_x + 5);
        for (yy = hole_y) {
            translate([hx, yy, 0])
                countersunk_hole(-leaf_thick_z/2, leaf_thick_z/2);
        }
    }
}

module pin_axis() {
    translate([0, 0, 0])
        rotate([90,0,0])
            cylinder(h=pin_len, r=pin_r, center=true);
}

// ===== Assembly (180° open) =====
union() {
    leaf_with_knuckles(-1); // left, x<0
    leaf_with_knuckles( 1); // right, x>0
    pin_axis();
}
i2 success
iter 2
10.0s · 2211/954t · $0.0148
diff vs i1: +0/-0
  $fn = 96;
  
  // ===== Parameters =====
  leaf_len_y      = 30;    // along hinge axis
  leaf_width_x    = 25;    // opening direction
  leaf_thick_z    = 2;
  
  pin_d           = 4;
  pin_r           = pin_d/2;
  pin_len         = 32;
  
  knuckle_od      = 8;
  knuckle_or      = knuckle_od/2;
  knuckle_id      = 4.6;   // pin + 0.3 clearance
  knuckle_ir      = knuckle_id/2;
  knuckle_seg     = 6;     // 30/5
  
  csk_thru_d      = 3.2;
  csk_head_d      = 6;
  csk_depth       = 1;
  
  y0 = -leaf_len_y/2;      // start of knuckle stack (-15)
  
  // Knuckle segment centers (5 equal 6mm segments across 30mm)
  function seg_center(i) = y0 + knuckle_seg*i + knuckle_seg/2;
  
  // Left leaf has segments: 0,2,4
  left_idx  = [0,2,4];
  // Right leaf has segments: 1,3
  right_idx = [1,3];
  
  // Screw hole Y positions (8mm pitch, centered)
  hole_y = [-8, 0, 8];
  
  // ===== Modules =====
  module countersunk_hole(z0, z1) {
      // through hole
      translate([0,0,z0-0.1])
          cylinder(h=(z1-z0)+0.2, r=csk_thru_d/2);
  
      // tapered countersink from top surface
      // top diameter 6, bottom diameter 3.2, depth 1
      translate([0,0,z1-csk_depth])
          cylinder(h=csk_depth+0.01, r1=csk_thru_d/2, r2=csk_head_d/2);
  }
  
  module leaf_base(side=1) {
      // side=+1 => right leaf (x>0), side=-1 => left leaf (x<0)
      x0 = (side > 0) ? 0 : -leaf_width_x;
      translate([x0, y0, -leaf_thick_z/2])
          cube([leaf_width_x, leaf_len_y, leaf_thick_z], center=false);
  }
  
  module knuckle_shell(yc, side=1) {
      // Outer knuckle body attached to leaf edge at x=0
      intersection() {
          translate([0, yc, 0])
              rotate([90,0,0])
                  cylinder(h=knuckle_seg, r=knuckle_or, center=true);
          // keep half by side
          translate([(side>0)?0:-knuckle_or, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
              cube([knuckle_or, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
      }
  }
  
  module leaf_with_knuckles(side=1) {
      difference() {
          union() {
              leaf_base(side);
  
              idxs = (side > 0) ? right_idx : left_idx;
              for (i = idxs)
                  knuckle_shell(seg_center(i), side);
          }
  
          // knuckle bore (only where material exists)
          for (i = (side > 0) ? right_idx : left_idx) {
              translate([0, seg_center(i), 0])
                  rotate([90,0,0])
                      cylinder(h=knuckle_seg+0.2, r=knuckle_ir, center=true);
          }
  
          // 3 countersunk holes near free edge of each leaf
          hx = (side > 0) ? (leaf_width_x - 5) : (-leaf_width_x + 5);
          for (yy = hole_y) {
              translate([hx, yy, 0])
                  countersunk_hole(-leaf_thick_z/2, leaf_thick_z/2);
          }
      }
  }
  
  module pin_axis() {
      translate([0, 0, 0])
          rotate([90,0,0])
              cylinder(h=pin_len, r=pin_r, center=true);
  }
  
  // ===== Assembly (180° open) =====
  union() {
      leaf_with_knuckles(-1); // left, x<0
      leaf_with_knuckles( 1); // right, x>0
      pin_axis();
  }
SCAD (103 lines)
$fn = 96;

// ===== Parameters =====
leaf_len_y      = 30;    // along hinge axis
leaf_width_x    = 25;    // opening direction
leaf_thick_z    = 2;

pin_d           = 4;
pin_r           = pin_d/2;
pin_len         = 32;

knuckle_od      = 8;
knuckle_or      = knuckle_od/2;
knuckle_id      = 4.6;   // pin + 0.3 clearance
knuckle_ir      = knuckle_id/2;
knuckle_seg     = 6;     // 30/5

csk_thru_d      = 3.2;
csk_head_d      = 6;
csk_depth       = 1;

y0 = -leaf_len_y/2;      // start of knuckle stack (-15)

// Knuckle segment centers (5 equal 6mm segments across 30mm)
function seg_center(i) = y0 + knuckle_seg*i + knuckle_seg/2;

// Left leaf has segments: 0,2,4
left_idx  = [0,2,4];
// Right leaf has segments: 1,3
right_idx = [1,3];

// Screw hole Y positions (8mm pitch, centered)
hole_y = [-8, 0, 8];

// ===== Modules =====
module countersunk_hole(z0, z1) {
    // through hole
    translate([0,0,z0-0.1])
        cylinder(h=(z1-z0)+0.2, r=csk_thru_d/2);

    // tapered countersink from top surface
    // top diameter 6, bottom diameter 3.2, depth 1
    translate([0,0,z1-csk_depth])
        cylinder(h=csk_depth+0.01, r1=csk_thru_d/2, r2=csk_head_d/2);
}

module leaf_base(side=1) {
    // side=+1 => right leaf (x>0), side=-1 => left leaf (x<0)
    x0 = (side > 0) ? 0 : -leaf_width_x;
    translate([x0, y0, -leaf_thick_z/2])
        cube([leaf_width_x, leaf_len_y, leaf_thick_z], center=false);
}

module knuckle_shell(yc, side=1) {
    // Outer knuckle body attached to leaf edge at x=0
    intersection() {
        translate([0, yc, 0])
            rotate([90,0,0])
                cylinder(h=knuckle_seg, r=knuckle_or, center=true);
        // keep half by side
        translate([(side>0)?0:-knuckle_or, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
            cube([knuckle_or, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
    }
}

module leaf_with_knuckles(side=1) {
    difference() {
        union() {
            leaf_base(side);

            idxs = (side > 0) ? right_idx : left_idx;
            for (i = idxs)
                knuckle_shell(seg_center(i), side);
        }

        // knuckle bore (only where material exists)
        for (i = (side > 0) ? right_idx : left_idx) {
            translate([0, seg_center(i), 0])
                rotate([90,0,0])
                    cylinder(h=knuckle_seg+0.2, r=knuckle_ir, center=true);
        }

        // 3 countersunk holes near free edge of each leaf
        hx = (side > 0) ? (leaf_width_x - 5) : (-leaf_width_x + 5);
        for (yy = hole_y) {
            translate([hx, yy, 0])
                countersunk_hole(-leaf_thick_z/2, leaf_thick_z/2);
        }
    }
}

module pin_axis() {
    translate([0, 0, 0])
        rotate([90,0,0])
            cylinder(h=pin_len, r=pin_r, center=true);
}

// ===== Assembly (180° open) =====
union() {
    leaf_with_knuckles(-1); // left, x<0
    leaf_with_knuckles( 1); // right, x>0
    pin_axis();
}
i3 success
iter 3
12.3s · 2211/1013t · $0.0155
diff vs i2: +50/-52
  $fn = 96;
  
  // ===== Parameters =====
- leaf_len_y      = 30;    // along hinge axis
+ leaf_len_y      = 30;    // hinge axis direction
  leaf_width_x    = 25;    // opening direction
  leaf_thick_z    = 2;
  
  pin_d           = 4;
  pin_r           = pin_d/2;
- pin_len         = 32;
+ pin_len         = 32;    // 1mm protrusion each side from 30mm knuckle stack
  
  knuckle_od      = 8;
  knuckle_or      = knuckle_od/2;
  knuckle_id      = 4.6;   // pin + 0.3 clearance
  knuckle_ir      = knuckle_id/2;
  knuckle_seg     = 6;     // 30/5
  
  csk_thru_d      = 3.2;
  csk_head_d      = 6;
  csk_depth       = 1;
  
- y0 = -leaf_len_y/2;      // start of knuckle stack (-15)
+ y0 = -leaf_len_y/2;      // -15
  
- // Knuckle segment centers (5 equal 6mm segments across 30mm)
- function seg_center(i) = y0 + knuckle_seg*i + knuckle_seg/2;
+ // ===== Utilities =====
+ function seg_center(i) = y0 + knuckle_seg*i + knuckle_seg/2; // i=0..4
  
- // Left leaf has segments: 0,2,4
- left_idx  = [0,2,4];
- // Right leaf has segments: 1,3
- right_idx = [1,3];
+ left_idx  = [0,2,4]; // left leaf knuckles (outer, center, outer)
+ right_idx = [1,3];   // right leaf knuckles (middle two)
  
- // Screw hole Y positions (8mm pitch, centered)
- hole_y = [-8, 0, 8];
+ hole_y = [-8,0,8];   // 8mm pitch along Y
  
- // ===== Modules =====
- module countersunk_hole(z0, z1) {
-     // through hole
-     translate([0,0,z0-0.1])
-         cylinder(h=(z1-z0)+0.2, r=csk_thru_d/2);
+ // ===== Features =====
+ module countersunk_hole_through(plate_t=2) {
+     // Through hole
+     translate([0,0,-plate_t/2-0.05])
+         cylinder(h=plate_t+0.1, d=csk_thru_d);
  
-     // tapered countersink from top surface
-     // top diameter 6, bottom diameter 3.2, depth 1
-     translate([0,0,z1-csk_depth])
-         cylinder(h=csk_depth+0.01, r1=csk_thru_d/2, r2=csk_head_d/2);
+     // Countersink from +Z surface (top): tapered, depth 1mm
+     // top dia 6 -> bottom dia 3.2
+     translate([0,0,plate_t/2-csk_depth])
+         cylinder(h=csk_depth+0.01, d1=csk_thru_d, d2=csk_head_d);
  }
  
- module leaf_base(side=1) {
-     // side=+1 => right leaf (x>0), side=-1 => left leaf (x<0)
-     x0 = (side > 0) ? 0 : -leaf_width_x;
+ module leaf_plate(side=1) {
+     // side +1: right (x>0), side -1: left (x<0)
+     x0 = (side>0) ? 0 : -leaf_width_x;
      translate([x0, y0, -leaf_thick_z/2])
          cube([leaf_width_x, leaf_len_y, leaf_thick_z], center=false);
  }
  
- module knuckle_shell(yc, side=1) {
-     // Outer knuckle body attached to leaf edge at x=0
+ module knuckle_half(yc, side=1) {
+     // Half-cylinder shell centered at X=0, axis along Y, length=6
      intersection() {
-         translate([0, yc, 0])
+         translate([0,yc,0])
              rotate([90,0,0])
-                 cylinder(h=knuckle_seg, r=knuckle_or, center=true);
-         // keep half by side
-         translate([(side>0)?0:-knuckle_or, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
-             cube([knuckle_or, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
+                 cylinder(h=knuckle_seg, d=knuckle_od, center=true);
+         // keep x>=0 (right) or x<=0 (left)
+         if (side>0)
+             translate([0, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
+                 cube([knuckle_or+0.02, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
+         else
+             translate([-knuckle_or-0.01, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
+                 cube([knuckle_or+0.02, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
      }
  }
  
  module leaf_with_knuckles(side=1) {
+     idxs = (side>0) ? right_idx : left_idx;
+ 
      difference() {
          union() {
-             leaf_base(side);
- 
-             idxs = (side > 0) ? right_idx : left_idx;
-             for (i = idxs)
-                 knuckle_shell(seg_center(i), side);
+             leaf_plate(side);
+             for (i=idxs) knuckle_half(seg_center(i), side);
          }
  
-         // knuckle bore (only where material exists)
-         for (i = (side > 0) ? right_idx : left_idx) {
-             translate([0, seg_center(i), 0])
+         // Knuckle bore in each segment
+         for (i=idxs) {
+             translate([0,seg_center(i),0])
                  rotate([90,0,0])
-                     cylinder(h=knuckle_seg+0.2, r=knuckle_ir, center=true);
+                     cylinder(h=knuckle_seg+0.2, d=knuckle_id, center=true);
          }
  
-         // 3 countersunk holes near free edge of each leaf
-         hx = (side > 0) ? (leaf_width_x - 5) : (-leaf_width_x + 5);
-         for (yy = hole_y) {
-             translate([hx, yy, 0])
-                 countersunk_hole(-leaf_thick_z/2, leaf_thick_z/2);
+         // Screw holes near free edge
+         hx = (side>0) ? (leaf_width_x-5) : (-leaf_width_x+5);
+         for (yy=hole_y) {
+             translate([hx,yy,0]) countersunk_hole_through(leaf_thick_z);
          }
      }
  }
  
- module pin_axis() {
-     translate([0, 0, 0])
-         rotate([90,0,0])
-             cylinder(h=pin_len, r=pin_r, center=true);
+ module pin() {
+     // Pin axis on global Y axis
+     rotate([90,0,0]) cylinder(h=pin_len, d=pin_d, center=true);
  }
  
- // ===== Assembly (180° open) =====
+ // ===== Assembly (180° open, both leaves coplanar) =====
  union() {
-     leaf_with_knuckles(-1); // left, x<0
-     leaf_with_knuckles( 1); // right, x>0
-     pin_axis();
+     leaf_with_knuckles(-1); // left leaf to x<0
+     leaf_with_knuckles( 1); // right leaf to x>0
+     pin();
  }
SCAD (101 lines)
$fn = 96;

// ===== Parameters =====
leaf_len_y      = 30;    // hinge axis direction
leaf_width_x    = 25;    // opening direction
leaf_thick_z    = 2;

pin_d           = 4;
pin_r           = pin_d/2;
pin_len         = 32;    // 1mm protrusion each side from 30mm knuckle stack

knuckle_od      = 8;
knuckle_or      = knuckle_od/2;
knuckle_id      = 4.6;   // pin + 0.3 clearance
knuckle_ir      = knuckle_id/2;
knuckle_seg     = 6;     // 30/5

csk_thru_d      = 3.2;
csk_head_d      = 6;
csk_depth       = 1;

y0 = -leaf_len_y/2;      // -15

// ===== Utilities =====
function seg_center(i) = y0 + knuckle_seg*i + knuckle_seg/2; // i=0..4

left_idx  = [0,2,4]; // left leaf knuckles (outer, center, outer)
right_idx = [1,3];   // right leaf knuckles (middle two)

hole_y = [-8,0,8];   // 8mm pitch along Y

// ===== Features =====
module countersunk_hole_through(plate_t=2) {
    // Through hole
    translate([0,0,-plate_t/2-0.05])
        cylinder(h=plate_t+0.1, d=csk_thru_d);

    // Countersink from +Z surface (top): tapered, depth 1mm
    // top dia 6 -> bottom dia 3.2
    translate([0,0,plate_t/2-csk_depth])
        cylinder(h=csk_depth+0.01, d1=csk_thru_d, d2=csk_head_d);
}

module leaf_plate(side=1) {
    // side +1: right (x>0), side -1: left (x<0)
    x0 = (side>0) ? 0 : -leaf_width_x;
    translate([x0, y0, -leaf_thick_z/2])
        cube([leaf_width_x, leaf_len_y, leaf_thick_z], center=false);
}

module knuckle_half(yc, side=1) {
    // Half-cylinder shell centered at X=0, axis along Y, length=6
    intersection() {
        translate([0,yc,0])
            rotate([90,0,0])
                cylinder(h=knuckle_seg, d=knuckle_od, center=true);
        // keep x>=0 (right) or x<=0 (left)
        if (side>0)
            translate([0, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
                cube([knuckle_or+0.02, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
        else
            translate([-knuckle_or-0.01, yc-knuckle_seg/2-0.01, -knuckle_or-0.01])
                cube([knuckle_or+0.02, knuckle_seg+0.02, 2*knuckle_or+0.02], center=false);
    }
}

module leaf_with_knuckles(side=1) {
    idxs = (side>0) ? right_idx : left_idx;

    difference() {
        union() {
            leaf_plate(side);
            for (i=idxs) knuckle_half(seg_center(i), side);
        }

        // Knuckle bore in each segment
        for (i=idxs) {
            translate([0,seg_center(i),0])
                rotate([90,0,0])
                    cylinder(h=knuckle_seg+0.2, d=knuckle_id, center=true);
        }

        // Screw holes near free edge
        hx = (side>0) ? (leaf_width_x-5) : (-leaf_width_x+5);
        for (yy=hole_y) {
            translate([hx,yy,0]) countersunk_hole_through(leaf_thick_z);
        }
    }
}

module pin() {
    // Pin axis on global Y axis
    rotate([90,0,0]) cylinder(h=pin_len, d=pin_d, center=true);
}

// ===== Assembly (180° open, both leaves coplanar) =====
union() {
    leaf_with_knuckles(-1); // left leaf to x<0
    leaf_with_knuckles( 1); // right leaf to x>0
    pin();
}