vibe-openscad

tier-3-butt-hinge / gpt-5-2025-08-07

7 run / 累計 823.8s / 累計 $0.6009

openai gpt 5 2025-08-07 bare

bare (provider default effort)

run detail →
render
bare render of tier-3-butt-hinge
loading STL…
success 185.9s · 592/10130t · $0.1020
SCAD (121 lines)
// Small butt hinge (furniture) - 180° open assembly

$fn = 96;

eps = 0.02;

// Dimensions
plate_len_y   = 30;   // along Y
plate_width_x = 25;   // along X (extends away from hinge axis)
plate_thick   = 2;    // along Z

kn_seg_len = 6;       // each knuckle segment length along Y
kn_od      = 8;       // knuckle outer diameter
kn_id      = 4.6;     // knuckle inner diameter (pin + 0.3 clearance)

pin_d   = 4;
pin_len = 32;         // sticks out 1mm each end (30 + 1 + 1)

hole_pitch    = 8;    // along Y
hole_y_list   = [-8, 0, 8];
hole_x_left   = -17;  // place holes on side away from knuckle (outer side)
hole_x_right  =  17;
cs_top_d      = 6;    // countersink top diameter
cs_depth      = 1;    // countersink depth
hole_thru_d   = 3.2;  // through diameter (M3 clearance)

// Knuckle Y centers (total 30mm split into 5x6mm: centers at -12, -6, 0, 6, 12)
kn_centers_left  = [-12, 0, 12];  // outer two + center one
kn_centers_right = [-6, 6];       // intermediate two

//---------------- Modules ----------------//

module pin_axis() {
  // Along +Y, centered so ends at y=±16 (knuckles at ±15)
  rotate([-90,0,0])
    cylinder(h=pin_len, r=pin_d/2, center=true);
}

module knuckle_segment(yc) {
  // A hollow cylinder segment along Y at center yc
  translate([0, yc, 0])
    rotate([-90,0,0])
      difference() {
        cylinder(h=kn_seg_len, r=kn_od/2, center=true);
        cylinder(h=kn_seg_len + 2*eps, r=kn_id/2, center=true);
      }
}

module countersunk_hole(xc, yc) {
  // Negative shape to subtract from a plate
  union() {
    // Countersink frustum: from z=(+1 - cs_depth) up to z=+1
    translate([xc, yc, 1 - cs_depth])
      cylinder(h=cs_depth, r1=hole_thru_d/2, r2=cs_top_d/2);
    // Through hole: make it longer than plate to ensure clean subtraction
    translate([xc, yc, -3])
      cylinder(h=6, r=hole_thru_d/2);
  }
}

module plate_base(side = "left") {
  // Rectangular plate: left x∈[-25,0], right x∈[0,25], y∈[-15,15], z∈[-1,1]
  if (side == "left")
    translate([-plate_width_x, -plate_len_y/2, -plate_thick/2])
      cube([plate_width_x, plate_len_y, plate_thick], center=false);
  else
    translate([0, -plate_len_y/2, -plate_thick/2])
      cube([plate_width_x, plate_len_y, plate_thick], center=false);
}

module plate_with_features(side = "left") {
  // Subtract countersunk holes and cutouts for the opposite knuckle segments
  difference() {
    plate_base(side);

    // Countersunk holes (on the far side from knuckle)
    if (side == "left")
      for (yy = hole_y_list)
        countersunk_hole(hole_x_left, yy);
    else
      for (yy = hole_y_list)
        countersunk_hole(hole_x_right, yy);

    // Cutouts to avoid interference with the opposite leaf's knuckles
    if (side == "left") {
      for (yc = kn_centers_right)
        translate([0, yc, 0])
          rotate([-90,0,0])
            cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
    } else {
      for (yc = kn_centers_left)
        translate([0, yc, 0])
          rotate([-90,0,0])
            cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
    }
  }
}

module leaf_assembly(side = "left") {
  union() {
    plate_with_features(side);
    if (side == "left") {
      for (yc = kn_centers_left)
        knuckle_segment(yc);
    } else {
      for (yc = kn_centers_right)
        knuckle_segment(yc);
    }
  }
}

//---------------- Assembly ----------------//

// Left leaf (x < 0)
color([0.7,0.7,0.75]) leaf_assembly("left");

// Right leaf (x > 0)
color([0.7,0.7,0.75]) leaf_assembly("right");

// Shared pin axis
color([0.85,0.85,0.85]) pin_axis();
パラメータ (15)
スライダを動かすと 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
77.4s · 592/6271t · $0.0635
SCAD (108 lines)
// Small furniture butt hinge (opened 180°)
// Dimensions per spec

// Global parameters
plate_len_y = 30;          // along hinge axis (Y)
plate_len_x = 25;          // extends away from axis (X)
plate_th   = 2;            // thickness (Z)

pin_d      = 4;
pin_r      = pin_d/2;
pin_len    = 32;           // protrudes 1 mm each end beyond 30 mm knuckle stack

knuckle_outer_d = 8;
knuckle_outer_r = knuckle_outer_d/2;
knuckle_inner_d = pin_d + 0.6; // 0.3 mm clearance all around -> +0.6 mm diameter
knuckle_h   = 6;           // segment height along Y
knuckle_pos = [-12, -6, 0, 6, 12]; // centers over 30 mm, 5 equal segments

// Screw holes (countersunk) per leaf
hole_pitch_y = 8;                  // along Y
hole_centers_y = [-hole_pitch_y, 0, hole_pitch_y];
drill_d   = 3.2;
drill_r   = drill_d/2;
csk_top_d = 6;
csk_top_r = csk_top_d/2;
csk_depth = 1;

// Utilities
module cyl_y(d=1,h=1,center=true){
  // Cylinder oriented along Y axis
  rotate([90,0,0]) cylinder(d=d, h=h, center=center, $fn=64);
}

module cone_y(d1=1,d2=1,h=1,center=true){
  // Conical frustum along Y axis
  rotate([90,0,0]) cylinder(d1=d1, d2=d2, h=h, center=center, $fn=64);
}

module knuckle_segment(yc=0){
  // One hollow knuckle ring segment centered at [0,yc,1]
  translate([0,yc,plate_th/2])
  difference(){
    cyl_y(d=knuckle_outer_d, h=knuckle_h, center=true);
    cyl_y(d=knuckle_inner_d, h=knuckle_h+0.2, center=true);
  }
}

module leaf_plate(side="left"){
  // Base plate 30 (Y) x 25 (X) x 2 (Z), positioned from y=-15..+15, z=0..2
  // Left occupies x in [-25..0], Right in [0..25]
  translate([ (side=="left") ? -plate_len_x : 0,
              -plate_len_y/2,
              0])
    cube([plate_len_x, plate_len_y, plate_th], center=false);
}

module countersunk_holes(side="left"){
  // Create countersunk through holes (to subtract) at 3 positions along Y
  for(yc = hole_centers_y){
    // Hole X position centered within leaf width
    xh = (side=="left") ? -plate_len_x/2 : plate_len_x/2;
    // Through hole (Z)
    translate([xh, yc, 0])
      cylinder(d=drill_d, h=plate_th+0.2, center=false, $fn=48);
    // Countersink from top surface (z=2 down by 1 mm), conical 6 mm -> 3.2 mm
    // Implemented as a cone in Z
    translate([xh, yc, plate_th - csk_depth])
      cylinder(h=csk_depth, r1=drill_r, r2=csk_top_r, center=false, $fn=48);
  }
}

module leaf(side="left"){
  // Assemble plate + own knuckles, subtract holes and relief for opposite knuckles
  own_idx   = (side=="left") ? [0,2,4] : [1,3];
  other_idx = (side=="left") ? [1,3]   : [0,2,4];

  difference(){
    // Union: plate + own knuckles
    union(){
      leaf_plate(side);
      for(i = own_idx){
        knuckle_segment(knuckle_pos[i]);
      }
    }
    // Countersunk holes
    countersunk_holes(side);

    // Relief notches for the opposite leaf's knuckles to avoid interpenetration:
    // subtract the cylindrical envelope of the other knuckle segments
    for(i = other_idx){
      translate([0, knuckle_pos[i], plate_th/2])
        cyl_y(d=knuckle_outer_d, h=knuckle_h+0.2, center=true);
    }
  }
}

module pin(){
  // Pin along Y, centered at y=0, z=1; length 32 mm (protrudes 1 mm each end)
  translate([0, 0, plate_th/2])
    cyl_y(d=pin_d, h=pin_len, center=true);
}

// Final assembly: opened 180°, leaves coplanar with flat faces in same Z plane
union(){
  leaf("left");   // extends to x<0
  leaf("right");  // extends to x>0
  pin();          // shared pin axis along Y
}
medium (default) success
medium
185.9s · 592/10130t · $0.1020
SCAD (121 lines)
// Small butt hinge (furniture) - 180° open assembly

$fn = 96;

eps = 0.02;

// Dimensions
plate_len_y   = 30;   // along Y
plate_width_x = 25;   // along X (extends away from hinge axis)
plate_thick   = 2;    // along Z

kn_seg_len = 6;       // each knuckle segment length along Y
kn_od      = 8;       // knuckle outer diameter
kn_id      = 4.6;     // knuckle inner diameter (pin + 0.3 clearance)

pin_d   = 4;
pin_len = 32;         // sticks out 1mm each end (30 + 1 + 1)

hole_pitch    = 8;    // along Y
hole_y_list   = [-8, 0, 8];
hole_x_left   = -17;  // place holes on side away from knuckle (outer side)
hole_x_right  =  17;
cs_top_d      = 6;    // countersink top diameter
cs_depth      = 1;    // countersink depth
hole_thru_d   = 3.2;  // through diameter (M3 clearance)

// Knuckle Y centers (total 30mm split into 5x6mm: centers at -12, -6, 0, 6, 12)
kn_centers_left  = [-12, 0, 12];  // outer two + center one
kn_centers_right = [-6, 6];       // intermediate two

//---------------- Modules ----------------//

module pin_axis() {
  // Along +Y, centered so ends at y=±16 (knuckles at ±15)
  rotate([-90,0,0])
    cylinder(h=pin_len, r=pin_d/2, center=true);
}

module knuckle_segment(yc) {
  // A hollow cylinder segment along Y at center yc
  translate([0, yc, 0])
    rotate([-90,0,0])
      difference() {
        cylinder(h=kn_seg_len, r=kn_od/2, center=true);
        cylinder(h=kn_seg_len + 2*eps, r=kn_id/2, center=true);
      }
}

module countersunk_hole(xc, yc) {
  // Negative shape to subtract from a plate
  union() {
    // Countersink frustum: from z=(+1 - cs_depth) up to z=+1
    translate([xc, yc, 1 - cs_depth])
      cylinder(h=cs_depth, r1=hole_thru_d/2, r2=cs_top_d/2);
    // Through hole: make it longer than plate to ensure clean subtraction
    translate([xc, yc, -3])
      cylinder(h=6, r=hole_thru_d/2);
  }
}

module plate_base(side = "left") {
  // Rectangular plate: left x∈[-25,0], right x∈[0,25], y∈[-15,15], z∈[-1,1]
  if (side == "left")
    translate([-plate_width_x, -plate_len_y/2, -plate_thick/2])
      cube([plate_width_x, plate_len_y, plate_thick], center=false);
  else
    translate([0, -plate_len_y/2, -plate_thick/2])
      cube([plate_width_x, plate_len_y, plate_thick], center=false);
}

module plate_with_features(side = "left") {
  // Subtract countersunk holes and cutouts for the opposite knuckle segments
  difference() {
    plate_base(side);

    // Countersunk holes (on the far side from knuckle)
    if (side == "left")
      for (yy = hole_y_list)
        countersunk_hole(hole_x_left, yy);
    else
      for (yy = hole_y_list)
        countersunk_hole(hole_x_right, yy);

    // Cutouts to avoid interference with the opposite leaf's knuckles
    if (side == "left") {
      for (yc = kn_centers_right)
        translate([0, yc, 0])
          rotate([-90,0,0])
            cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
    } else {
      for (yc = kn_centers_left)
        translate([0, yc, 0])
          rotate([-90,0,0])
            cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
    }
  }
}

module leaf_assembly(side = "left") {
  union() {
    plate_with_features(side);
    if (side == "left") {
      for (yc = kn_centers_left)
        knuckle_segment(yc);
    } else {
      for (yc = kn_centers_right)
        knuckle_segment(yc);
    }
  }
}

//---------------- Assembly ----------------//

// Left leaf (x < 0)
color([0.7,0.7,0.75]) leaf_assembly("left");

// Right leaf (x > 0)
color([0.7,0.7,0.75]) leaf_assembly("right");

// Shared pin axis
color([0.85,0.85,0.85]) pin_axis();
high success
high
171.1s · 592/12727t · $0.1280
SCAD (137 lines)
// 小型バット蝶番 (butt hinge) - 180° 開状態
// 単位: mm

$fn = 96;

// 基本寸法
leaf_w = 25;            // 板の横幅 (X)
leaf_h = 30;            // 板の縦高さ (Y)
leaf_t = 2;             // 板厚 (Z)

knuckle_od = 8;         // knuckle 外径
knuckle_r  = knuckle_od/2;
knuckle_id = 4.6;       // ピン + 0.3mm クリアランス

seg_len = 6;            // knuckle セグメント長
y_centers = [-12,-6,0,6,12]; // 30mm を 5 等分した中心位置

// knuckle 所有: 左(外側2 + 中央1), 右(中間2)
left_idx  = [0,2,4];
right_idx = [1,3];

pin_d  = 4;
pin_L  = 32;            // 両端 1mm ずつ突出 (knuckle計30mm -> 30+2)
z_mid  = 1;             // Z の中心 (板厚中央に合わせる)

// 皿穴寸法 (M3 用)
screw_d   = 3.2;        // 貫通穴
cs_d      = 6;          // 皿頭外径
cs_depth  = 1;          // 皿部深さ
hole_ys   = [-8,0,8];   // ピッチ 8mm
hole_x_L  = -leaf_w/2;  // 左板の穴 X
hole_x_R  =  leaf_w/2;  // 右板の穴 X

//======================== ユーティリティ ========================//
module pin_hole(len=40) {
    // knuckle 内のピン用の貫通空間 (削り取り用)
    translate([0,0,z_mid]) rotate([90,0,0])
        cylinder(d=knuckle_id, h=len, center=true);
}

module knuckle_segment(yc, d=knuckle_od, h=seg_len) {
    // Y 軸向きの円筒 (中心 Y=yc, Z は z_mid を中心)
    translate([0,yc,z_mid]) rotate([90,0,0])
        cylinder(d=d, h=h, center=true);
}

module knuckle_union(y_idxs) {
    union() {
        for(i = y_idxs) knuckle_segment(y_centers[i], d=knuckle_od, h=seg_len);
    }
}

module knuckles_with_bore(y_idxs) {
    difference() {
        knuckle_union(y_idxs);
        pin_hole(40);
    }
}

module countersunk_hole(xc, yc) {
    // 皿穴 (上面Z=leaf_tから深さ1mmのテーパ) + 3.2mm 貫通
    // 皿部 (上:直径6, 下:直径3.2, 高さ1)
    translate([xc,yc,leaf_t - cs_depth])
        cylinder(h=cs_depth, d1=cs_d, d2=screw_d, center=false);
    // 貫通穴
    translate([xc,yc,0])
        cylinder(h=leaf_t + 0.2, d=screw_d, center=false);
}

//======================== 左右の板 ========================//
module left_plate_core() {
    // 左板ベース: x ∈ [-25,0], y ∈ [-15,15], z ∈ [0,2]
    translate([-leaf_w, -leaf_h/2, 0])
        cube([leaf_w, leaf_h, leaf_t], center=false);
}

module right_plate_core() {
    // 右板ベース: x ∈ [0,25], y ∈ [-15,15], z ∈ [0,2]
    translate([0, -leaf_h/2, 0])
        cube([leaf_w, leaf_h, leaf_t], center=false);
}

module left_plate_with_cutouts_and_holes() {
    difference() {
        // ベース
        left_plate_core();
        // 右側が持つ knuckle の外径で左板を逃がす (Y = -6, +6 の位置)
        for (i = right_idx)
            knuckle_segment(y_centers[i], d=knuckle_od, h=seg_len);
        // 皿穴 3 個 (X は板の中央)
        for (yy = hole_ys)
            countersunk_hole(hole_x_L, yy);
    }
}

module right_plate_with_cutouts_and_holes() {
    difference() {
        // ベース
        right_plate_core();
        // 左側が持つ knuckle の外径で右板を逃がす (Y = -12, 0, +12 の位置)
        for (i = left_idx)
            knuckle_segment(y_centers[i], d=knuckle_od, h=seg_len);
        // 皿穴 3 個 (X は板の中央)
        for (yy = hole_ys)
            countersunk_hole(hole_x_R, yy);
    }
}

module left_leaf() {
    union() {
        // 板本体 (カットアウト + 皿穴)
        left_plate_with_cutouts_and_holes();
        // 左側 knuckle (内径 4.6mm でくり抜き)
        knuckles_with_bore(left_idx);
    }
}

module right_leaf() {
    union() {
        // 板本体 (カットアウト + 皿穴)
        right_plate_with_cutouts_and_holes();
        // 右側 knuckle (内径 4.6mm でくり抜き)
        knuckles_with_bore(right_idx);
    }
}

module hinge_pin() {
    // ピン軸: 直径4, 長さ32 (Y方向), Z中心は z_mid
    translate([0,0,z_mid]) rotate([90,0,0])
        cylinder(d=pin_d, h=pin_L, center=true);
}

//======================== アセンブリ ========================//
// 180° 開いた状態: 左板は x<0 側、右板は x>0 側。板面は Z=0..2 で共面。
left_leaf();
right_leaf();
hinge_pin();
maxnot run
xhighnot run

iteration: iter-png

i1 success
iter 1
58.6s · 2475/6047t · $0.0636
diff vs bare: +0/-0
  // Small butt hinge (furniture) - 180° open assembly
  
  $fn = 96;
  
  eps = 0.02;
  
  // Dimensions
  plate_len_y   = 30;   // along Y
  plate_width_x = 25;   // along X (extends away from hinge axis)
  plate_thick   = 2;    // along Z
  
  kn_seg_len = 6;       // each knuckle segment length along Y
  kn_od      = 8;       // knuckle outer diameter
  kn_id      = 4.6;     // knuckle inner diameter (pin + 0.3 clearance)
  
  pin_d   = 4;
  pin_len = 32;         // sticks out 1mm each end (30 + 1 + 1)
  
  hole_pitch    = 8;    // along Y
  hole_y_list   = [-8, 0, 8];
  hole_x_left   = -17;  // place holes on side away from knuckle (outer side)
  hole_x_right  =  17;
  cs_top_d      = 6;    // countersink top diameter
  cs_depth      = 1;    // countersink depth
  hole_thru_d   = 3.2;  // through diameter (M3 clearance)
  
  // Knuckle Y centers (total 30mm split into 5x6mm: centers at -12, -6, 0, 6, 12)
  kn_centers_left  = [-12, 0, 12];  // outer two + center one
  kn_centers_right = [-6, 6];       // intermediate two
  
  //---------------- Modules ----------------//
  
  module pin_axis() {
    // Along +Y, centered so ends at y=±16 (knuckles at ±15)
    rotate([-90,0,0])
      cylinder(h=pin_len, r=pin_d/2, center=true);
  }
  
  module knuckle_segment(yc) {
    // A hollow cylinder segment along Y at center yc
    translate([0, yc, 0])
      rotate([-90,0,0])
        difference() {
          cylinder(h=kn_seg_len, r=kn_od/2, center=true);
          cylinder(h=kn_seg_len + 2*eps, r=kn_id/2, center=true);
        }
  }
  
  module countersunk_hole(xc, yc) {
    // Negative shape to subtract from a plate
    union() {
      // Countersink frustum: from z=(+1 - cs_depth) up to z=+1
      translate([xc, yc, 1 - cs_depth])
        cylinder(h=cs_depth, r1=hole_thru_d/2, r2=cs_top_d/2);
      // Through hole: make it longer than plate to ensure clean subtraction
      translate([xc, yc, -3])
        cylinder(h=6, r=hole_thru_d/2);
    }
  }
  
  module plate_base(side = "left") {
    // Rectangular plate: left x∈[-25,0], right x∈[0,25], y∈[-15,15], z∈[-1,1]
    if (side == "left")
      translate([-plate_width_x, -plate_len_y/2, -plate_thick/2])
        cube([plate_width_x, plate_len_y, plate_thick], center=false);
    else
      translate([0, -plate_len_y/2, -plate_thick/2])
        cube([plate_width_x, plate_len_y, plate_thick], center=false);
  }
  
  module plate_with_features(side = "left") {
    // Subtract countersunk holes and cutouts for the opposite knuckle segments
    difference() {
      plate_base(side);
  
      // Countersunk holes (on the far side from knuckle)
      if (side == "left")
        for (yy = hole_y_list)
          countersunk_hole(hole_x_left, yy);
      else
        for (yy = hole_y_list)
          countersunk_hole(hole_x_right, yy);
  
      // Cutouts to avoid interference with the opposite leaf's knuckles
      if (side == "left") {
        for (yc = kn_centers_right)
          translate([0, yc, 0])
            rotate([-90,0,0])
              cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
      } else {
        for (yc = kn_centers_left)
          translate([0, yc, 0])
            rotate([-90,0,0])
              cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
      }
    }
  }
  
  module leaf_assembly(side = "left") {
    union() {
      plate_with_features(side);
      if (side == "left") {
        for (yc = kn_centers_left)
          knuckle_segment(yc);
      } else {
        for (yc = kn_centers_right)
          knuckle_segment(yc);
      }
    }
  }
  
  //---------------- Assembly ----------------//
  
  // Left leaf (x < 0)
  color([0.7,0.7,0.75]) leaf_assembly("left");
  
  // Right leaf (x > 0)
  color([0.7,0.7,0.75]) leaf_assembly("right");
  
  // Shared pin axis
  color([0.85,0.85,0.85]) pin_axis();
SCAD (121 lines)
// Small butt hinge (furniture) - 180° open assembly

$fn = 96;

eps = 0.02;

// Dimensions
plate_len_y   = 30;   // along Y
plate_width_x = 25;   // along X (extends away from hinge axis)
plate_thick   = 2;    // along Z

kn_seg_len = 6;       // each knuckle segment length along Y
kn_od      = 8;       // knuckle outer diameter
kn_id      = 4.6;     // knuckle inner diameter (pin + 0.3 clearance)

pin_d   = 4;
pin_len = 32;         // sticks out 1mm each end (30 + 1 + 1)

hole_pitch    = 8;    // along Y
hole_y_list   = [-8, 0, 8];
hole_x_left   = -17;  // place holes on side away from knuckle (outer side)
hole_x_right  =  17;
cs_top_d      = 6;    // countersink top diameter
cs_depth      = 1;    // countersink depth
hole_thru_d   = 3.2;  // through diameter (M3 clearance)

// Knuckle Y centers (total 30mm split into 5x6mm: centers at -12, -6, 0, 6, 12)
kn_centers_left  = [-12, 0, 12];  // outer two + center one
kn_centers_right = [-6, 6];       // intermediate two

//---------------- Modules ----------------//

module pin_axis() {
  // Along +Y, centered so ends at y=±16 (knuckles at ±15)
  rotate([-90,0,0])
    cylinder(h=pin_len, r=pin_d/2, center=true);
}

module knuckle_segment(yc) {
  // A hollow cylinder segment along Y at center yc
  translate([0, yc, 0])
    rotate([-90,0,0])
      difference() {
        cylinder(h=kn_seg_len, r=kn_od/2, center=true);
        cylinder(h=kn_seg_len + 2*eps, r=kn_id/2, center=true);
      }
}

module countersunk_hole(xc, yc) {
  // Negative shape to subtract from a plate
  union() {
    // Countersink frustum: from z=(+1 - cs_depth) up to z=+1
    translate([xc, yc, 1 - cs_depth])
      cylinder(h=cs_depth, r1=hole_thru_d/2, r2=cs_top_d/2);
    // Through hole: make it longer than plate to ensure clean subtraction
    translate([xc, yc, -3])
      cylinder(h=6, r=hole_thru_d/2);
  }
}

module plate_base(side = "left") {
  // Rectangular plate: left x∈[-25,0], right x∈[0,25], y∈[-15,15], z∈[-1,1]
  if (side == "left")
    translate([-plate_width_x, -plate_len_y/2, -plate_thick/2])
      cube([plate_width_x, plate_len_y, plate_thick], center=false);
  else
    translate([0, -plate_len_y/2, -plate_thick/2])
      cube([plate_width_x, plate_len_y, plate_thick], center=false);
}

module plate_with_features(side = "left") {
  // Subtract countersunk holes and cutouts for the opposite knuckle segments
  difference() {
    plate_base(side);

    // Countersunk holes (on the far side from knuckle)
    if (side == "left")
      for (yy = hole_y_list)
        countersunk_hole(hole_x_left, yy);
    else
      for (yy = hole_y_list)
        countersunk_hole(hole_x_right, yy);

    // Cutouts to avoid interference with the opposite leaf's knuckles
    if (side == "left") {
      for (yc = kn_centers_right)
        translate([0, yc, 0])
          rotate([-90,0,0])
            cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
    } else {
      for (yc = kn_centers_left)
        translate([0, yc, 0])
          rotate([-90,0,0])
            cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
    }
  }
}

module leaf_assembly(side = "left") {
  union() {
    plate_with_features(side);
    if (side == "left") {
      for (yc = kn_centers_left)
        knuckle_segment(yc);
    } else {
      for (yc = kn_centers_right)
        knuckle_segment(yc);
    }
  }
}

//---------------- Assembly ----------------//

// Left leaf (x < 0)
color([0.7,0.7,0.75]) leaf_assembly("left");

// Right leaf (x > 0)
color([0.7,0.7,0.75]) leaf_assembly("right");

// Shared pin axis
color([0.85,0.85,0.85]) pin_axis();
i2 success
iter 2
64.6s · 2475/5845t · $0.0615
diff vs i1: +0/-0
  // Small butt hinge (furniture) - 180° open assembly
  
  $fn = 96;
  
  eps = 0.02;
  
  // Dimensions
  plate_len_y   = 30;   // along Y
  plate_width_x = 25;   // along X (extends away from hinge axis)
  plate_thick   = 2;    // along Z
  
  kn_seg_len = 6;       // each knuckle segment length along Y
  kn_od      = 8;       // knuckle outer diameter
  kn_id      = 4.6;     // knuckle inner diameter (pin + 0.3 clearance)
  
  pin_d   = 4;
  pin_len = 32;         // sticks out 1mm each end (30 + 1 + 1)
  
  hole_pitch    = 8;    // along Y
  hole_y_list   = [-8, 0, 8];
  hole_x_left   = -17;  // place holes on side away from knuckle (outer side)
  hole_x_right  =  17;
  cs_top_d      = 6;    // countersink top diameter
  cs_depth      = 1;    // countersink depth
  hole_thru_d   = 3.2;  // through diameter (M3 clearance)
  
  // Knuckle Y centers (total 30mm split into 5x6mm: centers at -12, -6, 0, 6, 12)
  kn_centers_left  = [-12, 0, 12];  // outer two + center one
  kn_centers_right = [-6, 6];       // intermediate two
  
  //---------------- Modules ----------------//
  
  module pin_axis() {
    // Along +Y, centered so ends at y=±16 (knuckles at ±15)
    rotate([-90,0,0])
      cylinder(h=pin_len, r=pin_d/2, center=true);
  }
  
  module knuckle_segment(yc) {
    // A hollow cylinder segment along Y at center yc
    translate([0, yc, 0])
      rotate([-90,0,0])
        difference() {
          cylinder(h=kn_seg_len, r=kn_od/2, center=true);
          cylinder(h=kn_seg_len + 2*eps, r=kn_id/2, center=true);
        }
  }
  
  module countersunk_hole(xc, yc) {
    // Negative shape to subtract from a plate
    union() {
      // Countersink frustum: from z=(+1 - cs_depth) up to z=+1
      translate([xc, yc, 1 - cs_depth])
        cylinder(h=cs_depth, r1=hole_thru_d/2, r2=cs_top_d/2);
      // Through hole: make it longer than plate to ensure clean subtraction
      translate([xc, yc, -3])
        cylinder(h=6, r=hole_thru_d/2);
    }
  }
  
  module plate_base(side = "left") {
    // Rectangular plate: left x∈[-25,0], right x∈[0,25], y∈[-15,15], z∈[-1,1]
    if (side == "left")
      translate([-plate_width_x, -plate_len_y/2, -plate_thick/2])
        cube([plate_width_x, plate_len_y, plate_thick], center=false);
    else
      translate([0, -plate_len_y/2, -plate_thick/2])
        cube([plate_width_x, plate_len_y, plate_thick], center=false);
  }
  
  module plate_with_features(side = "left") {
    // Subtract countersunk holes and cutouts for the opposite knuckle segments
    difference() {
      plate_base(side);
  
      // Countersunk holes (on the far side from knuckle)
      if (side == "left")
        for (yy = hole_y_list)
          countersunk_hole(hole_x_left, yy);
      else
        for (yy = hole_y_list)
          countersunk_hole(hole_x_right, yy);
  
      // Cutouts to avoid interference with the opposite leaf's knuckles
      if (side == "left") {
        for (yc = kn_centers_right)
          translate([0, yc, 0])
            rotate([-90,0,0])
              cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
      } else {
        for (yc = kn_centers_left)
          translate([0, yc, 0])
            rotate([-90,0,0])
              cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
      }
    }
  }
  
  module leaf_assembly(side = "left") {
    union() {
      plate_with_features(side);
      if (side == "left") {
        for (yc = kn_centers_left)
          knuckle_segment(yc);
      } else {
        for (yc = kn_centers_right)
          knuckle_segment(yc);
      }
    }
  }
  
  //---------------- Assembly ----------------//
  
  // Left leaf (x < 0)
  color([0.7,0.7,0.75]) leaf_assembly("left");
  
  // Right leaf (x > 0)
  color([0.7,0.7,0.75]) leaf_assembly("right");
  
  // Shared pin axis
  color([0.85,0.85,0.85]) pin_axis();
SCAD (121 lines)
// Small butt hinge (furniture) - 180° open assembly

$fn = 96;

eps = 0.02;

// Dimensions
plate_len_y   = 30;   // along Y
plate_width_x = 25;   // along X (extends away from hinge axis)
plate_thick   = 2;    // along Z

kn_seg_len = 6;       // each knuckle segment length along Y
kn_od      = 8;       // knuckle outer diameter
kn_id      = 4.6;     // knuckle inner diameter (pin + 0.3 clearance)

pin_d   = 4;
pin_len = 32;         // sticks out 1mm each end (30 + 1 + 1)

hole_pitch    = 8;    // along Y
hole_y_list   = [-8, 0, 8];
hole_x_left   = -17;  // place holes on side away from knuckle (outer side)
hole_x_right  =  17;
cs_top_d      = 6;    // countersink top diameter
cs_depth      = 1;    // countersink depth
hole_thru_d   = 3.2;  // through diameter (M3 clearance)

// Knuckle Y centers (total 30mm split into 5x6mm: centers at -12, -6, 0, 6, 12)
kn_centers_left  = [-12, 0, 12];  // outer two + center one
kn_centers_right = [-6, 6];       // intermediate two

//---------------- Modules ----------------//

module pin_axis() {
  // Along +Y, centered so ends at y=±16 (knuckles at ±15)
  rotate([-90,0,0])
    cylinder(h=pin_len, r=pin_d/2, center=true);
}

module knuckle_segment(yc) {
  // A hollow cylinder segment along Y at center yc
  translate([0, yc, 0])
    rotate([-90,0,0])
      difference() {
        cylinder(h=kn_seg_len, r=kn_od/2, center=true);
        cylinder(h=kn_seg_len + 2*eps, r=kn_id/2, center=true);
      }
}

module countersunk_hole(xc, yc) {
  // Negative shape to subtract from a plate
  union() {
    // Countersink frustum: from z=(+1 - cs_depth) up to z=+1
    translate([xc, yc, 1 - cs_depth])
      cylinder(h=cs_depth, r1=hole_thru_d/2, r2=cs_top_d/2);
    // Through hole: make it longer than plate to ensure clean subtraction
    translate([xc, yc, -3])
      cylinder(h=6, r=hole_thru_d/2);
  }
}

module plate_base(side = "left") {
  // Rectangular plate: left x∈[-25,0], right x∈[0,25], y∈[-15,15], z∈[-1,1]
  if (side == "left")
    translate([-plate_width_x, -plate_len_y/2, -plate_thick/2])
      cube([plate_width_x, plate_len_y, plate_thick], center=false);
  else
    translate([0, -plate_len_y/2, -plate_thick/2])
      cube([plate_width_x, plate_len_y, plate_thick], center=false);
}

module plate_with_features(side = "left") {
  // Subtract countersunk holes and cutouts for the opposite knuckle segments
  difference() {
    plate_base(side);

    // Countersunk holes (on the far side from knuckle)
    if (side == "left")
      for (yy = hole_y_list)
        countersunk_hole(hole_x_left, yy);
    else
      for (yy = hole_y_list)
        countersunk_hole(hole_x_right, yy);

    // Cutouts to avoid interference with the opposite leaf's knuckles
    if (side == "left") {
      for (yc = kn_centers_right)
        translate([0, yc, 0])
          rotate([-90,0,0])
            cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
    } else {
      for (yc = kn_centers_left)
        translate([0, yc, 0])
          rotate([-90,0,0])
            cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
    }
  }
}

module leaf_assembly(side = "left") {
  union() {
    plate_with_features(side);
    if (side == "left") {
      for (yc = kn_centers_left)
        knuckle_segment(yc);
    } else {
      for (yc = kn_centers_right)
        knuckle_segment(yc);
    }
  }
}

//---------------- Assembly ----------------//

// Left leaf (x < 0)
color([0.7,0.7,0.75]) leaf_assembly("left");

// Right leaf (x > 0)
color([0.7,0.7,0.75]) leaf_assembly("right");

// Shared pin axis
color([0.85,0.85,0.85]) pin_axis();
i3 success
iter 3
80.2s · 2475/7718t · $0.0803
diff vs i2: +0/-0
  // Small butt hinge (furniture) - 180° open assembly
  
  $fn = 96;
  
  eps = 0.02;
  
  // Dimensions
  plate_len_y   = 30;   // along Y
  plate_width_x = 25;   // along X (extends away from hinge axis)
  plate_thick   = 2;    // along Z
  
  kn_seg_len = 6;       // each knuckle segment length along Y
  kn_od      = 8;       // knuckle outer diameter
  kn_id      = 4.6;     // knuckle inner diameter (pin + 0.3 clearance)
  
  pin_d   = 4;
  pin_len = 32;         // sticks out 1mm each end (30 + 1 + 1)
  
  hole_pitch    = 8;    // along Y
  hole_y_list   = [-8, 0, 8];
  hole_x_left   = -17;  // place holes on side away from knuckle (outer side)
  hole_x_right  =  17;
  cs_top_d      = 6;    // countersink top diameter
  cs_depth      = 1;    // countersink depth
  hole_thru_d   = 3.2;  // through diameter (M3 clearance)
  
  // Knuckle Y centers (total 30mm split into 5x6mm: centers at -12, -6, 0, 6, 12)
  kn_centers_left  = [-12, 0, 12];  // outer two + center one
  kn_centers_right = [-6, 6];       // intermediate two
  
  //---------------- Modules ----------------//
  
  module pin_axis() {
    // Along +Y, centered so ends at y=±16 (knuckles at ±15)
    rotate([-90,0,0])
      cylinder(h=pin_len, r=pin_d/2, center=true);
  }
  
  module knuckle_segment(yc) {
    // A hollow cylinder segment along Y at center yc
    translate([0, yc, 0])
      rotate([-90,0,0])
        difference() {
          cylinder(h=kn_seg_len, r=kn_od/2, center=true);
          cylinder(h=kn_seg_len + 2*eps, r=kn_id/2, center=true);
        }
  }
  
  module countersunk_hole(xc, yc) {
    // Negative shape to subtract from a plate
    union() {
      // Countersink frustum: from z=(+1 - cs_depth) up to z=+1
      translate([xc, yc, 1 - cs_depth])
        cylinder(h=cs_depth, r1=hole_thru_d/2, r2=cs_top_d/2);
      // Through hole: make it longer than plate to ensure clean subtraction
      translate([xc, yc, -3])
        cylinder(h=6, r=hole_thru_d/2);
    }
  }
  
  module plate_base(side = "left") {
    // Rectangular plate: left x∈[-25,0], right x∈[0,25], y∈[-15,15], z∈[-1,1]
    if (side == "left")
      translate([-plate_width_x, -plate_len_y/2, -plate_thick/2])
        cube([plate_width_x, plate_len_y, plate_thick], center=false);
    else
      translate([0, -plate_len_y/2, -plate_thick/2])
        cube([plate_width_x, plate_len_y, plate_thick], center=false);
  }
  
  module plate_with_features(side = "left") {
    // Subtract countersunk holes and cutouts for the opposite knuckle segments
    difference() {
      plate_base(side);
  
      // Countersunk holes (on the far side from knuckle)
      if (side == "left")
        for (yy = hole_y_list)
          countersunk_hole(hole_x_left, yy);
      else
        for (yy = hole_y_list)
          countersunk_hole(hole_x_right, yy);
  
      // Cutouts to avoid interference with the opposite leaf's knuckles
      if (side == "left") {
        for (yc = kn_centers_right)
          translate([0, yc, 0])
            rotate([-90,0,0])
              cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
      } else {
        for (yc = kn_centers_left)
          translate([0, yc, 0])
            rotate([-90,0,0])
              cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
      }
    }
  }
  
  module leaf_assembly(side = "left") {
    union() {
      plate_with_features(side);
      if (side == "left") {
        for (yc = kn_centers_left)
          knuckle_segment(yc);
      } else {
        for (yc = kn_centers_right)
          knuckle_segment(yc);
      }
    }
  }
  
  //---------------- Assembly ----------------//
  
  // Left leaf (x < 0)
  color([0.7,0.7,0.75]) leaf_assembly("left");
  
  // Right leaf (x > 0)
  color([0.7,0.7,0.75]) leaf_assembly("right");
  
  // Shared pin axis
  color([0.85,0.85,0.85]) pin_axis();
SCAD (121 lines)
// Small butt hinge (furniture) - 180° open assembly

$fn = 96;

eps = 0.02;

// Dimensions
plate_len_y   = 30;   // along Y
plate_width_x = 25;   // along X (extends away from hinge axis)
plate_thick   = 2;    // along Z

kn_seg_len = 6;       // each knuckle segment length along Y
kn_od      = 8;       // knuckle outer diameter
kn_id      = 4.6;     // knuckle inner diameter (pin + 0.3 clearance)

pin_d   = 4;
pin_len = 32;         // sticks out 1mm each end (30 + 1 + 1)

hole_pitch    = 8;    // along Y
hole_y_list   = [-8, 0, 8];
hole_x_left   = -17;  // place holes on side away from knuckle (outer side)
hole_x_right  =  17;
cs_top_d      = 6;    // countersink top diameter
cs_depth      = 1;    // countersink depth
hole_thru_d   = 3.2;  // through diameter (M3 clearance)

// Knuckle Y centers (total 30mm split into 5x6mm: centers at -12, -6, 0, 6, 12)
kn_centers_left  = [-12, 0, 12];  // outer two + center one
kn_centers_right = [-6, 6];       // intermediate two

//---------------- Modules ----------------//

module pin_axis() {
  // Along +Y, centered so ends at y=±16 (knuckles at ±15)
  rotate([-90,0,0])
    cylinder(h=pin_len, r=pin_d/2, center=true);
}

module knuckle_segment(yc) {
  // A hollow cylinder segment along Y at center yc
  translate([0, yc, 0])
    rotate([-90,0,0])
      difference() {
        cylinder(h=kn_seg_len, r=kn_od/2, center=true);
        cylinder(h=kn_seg_len + 2*eps, r=kn_id/2, center=true);
      }
}

module countersunk_hole(xc, yc) {
  // Negative shape to subtract from a plate
  union() {
    // Countersink frustum: from z=(+1 - cs_depth) up to z=+1
    translate([xc, yc, 1 - cs_depth])
      cylinder(h=cs_depth, r1=hole_thru_d/2, r2=cs_top_d/2);
    // Through hole: make it longer than plate to ensure clean subtraction
    translate([xc, yc, -3])
      cylinder(h=6, r=hole_thru_d/2);
  }
}

module plate_base(side = "left") {
  // Rectangular plate: left x∈[-25,0], right x∈[0,25], y∈[-15,15], z∈[-1,1]
  if (side == "left")
    translate([-plate_width_x, -plate_len_y/2, -plate_thick/2])
      cube([plate_width_x, plate_len_y, plate_thick], center=false);
  else
    translate([0, -plate_len_y/2, -plate_thick/2])
      cube([plate_width_x, plate_len_y, plate_thick], center=false);
}

module plate_with_features(side = "left") {
  // Subtract countersunk holes and cutouts for the opposite knuckle segments
  difference() {
    plate_base(side);

    // Countersunk holes (on the far side from knuckle)
    if (side == "left")
      for (yy = hole_y_list)
        countersunk_hole(hole_x_left, yy);
    else
      for (yy = hole_y_list)
        countersunk_hole(hole_x_right, yy);

    // Cutouts to avoid interference with the opposite leaf's knuckles
    if (side == "left") {
      for (yc = kn_centers_right)
        translate([0, yc, 0])
          rotate([-90,0,0])
            cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
    } else {
      for (yc = kn_centers_left)
        translate([0, yc, 0])
          rotate([-90,0,0])
            cylinder(h=kn_seg_len + 2*eps, r=kn_od/2 + eps, center=true);
    }
  }
}

module leaf_assembly(side = "left") {
  union() {
    plate_with_features(side);
    if (side == "left") {
      for (yc = kn_centers_left)
        knuckle_segment(yc);
    } else {
      for (yc = kn_centers_right)
        knuckle_segment(yc);
    }
  }
}

//---------------- Assembly ----------------//

// Left leaf (x < 0)
color([0.7,0.7,0.75]) leaf_assembly("left");

// Right leaf (x > 0)
color([0.7,0.7,0.75]) leaf_assembly("right");

// Shared pin axis
color([0.85,0.85,0.85]) pin_axis();