vibe-openscad

tier-2-offset-handle-mug / gpt-5.3-codex

5 run / 累計 49.4s / 累計 $0.0477

openai gpt 5.3 codex bare

bare (provider default effort)

run detail →
render
bare render of tier-2-offset-handle-mug
loading STL…
success 11.2s · 273/703t · $0.0088
SCAD (72 lines)
$fn = 128;

// Mug dimensions
outer_d = 80;
inner_d = 70;
mug_h   = 90;
bottom_t = 6;

// Handle target opening (inner void)
handle_void_h = 30;
handle_void_w = 25;

// Handle placement
z_center = mug_h / 2;
z0 = z_center - handle_void_h / 2;

// Derived
r_outer = outer_d / 2;
r_inner = inner_d / 2;

// Build
union() {
    // Mug body (hollow with bottom thickness)
    difference() {
        cylinder(h = mug_h, d = outer_d);
        translate([0, 0, bottom_t])
            cylinder(h = mug_h - bottom_t + 0.01, d = inner_d);
    }

    // Handle on +X side only: D-shape in XZ profile, extruded along Y
    // Inner opening: 25 (X) x 30 (Z)
    // Ring thickness around opening:
    t_radial = 5;   // along X/Z profile
    t_depth  = 10;  // along Y (grip thickness)

    // Place so inner flat side lies on mug outer tangent plane at x = r_outer
    x_inner_flat = r_outer;
    x_outer_flat = x_inner_flat + t_radial;

    // Inner profile center (for semicircle cap)
    xi_c = x_inner_flat + handle_void_w;       // center x of inner semicircle
    zi_c = z_center;

    // Outer profile center
    xo_c = x_outer_flat + handle_void_w + t_radial;
    zo_c = z_center;

    // Depth placement: centered at y=0
    y0 = - (handle_void_h + 0) / 2; // not used directly; keep symmetry intent

    // Construct as outer D minus inner D, then union with mug
    translate([0, 0, 0])
    difference() {
        // Outer D, extruded in Y
        translate([0, -t_depth/2, 0])
        rotate([-90, 0, 0])
        linear_extrude(height = t_depth)
        polygon(points = concat(
            [[x_outer_flat, z0 - t_radial], [x_outer_flat, z0 + handle_void_h + t_radial]],
            [ for (a = [90 : -2 : -90]) [ xo_c + (handle_void_h/2 + t_radial) * cos(a), zo_c + (handle_void_h/2 + t_radial) * sin(a) ] ]
        ));

        // Inner D void, extruded slightly larger in Y to ensure clean subtraction
        translate([0, -(t_depth/2 + 0.1), 0])
        rotate([-90, 0, 0])
        linear_extrude(height = t_depth + 0.2)
        polygon(points = concat(
            [[x_inner_flat, z0], [x_inner_flat, z0 + handle_void_h]],
            [ for (a = [90 : -2 : -90]) [ xi_c + (handle_void_h/2) * cos(a), zi_c + (handle_void_h/2) * sin(a) ] ]
        ));
    }
}
パラメータ (6)
スライダを動かすと openscad-wasm で再レンダリング

prompt

OpenSCAD で、向きが指定されたマグカップを作ってください。

本体:
- 外径 80mm、内径 70mm(肉厚 5mm)、高さ 90mm の円筒形マグ
- 底面の厚みは 6mm
- 内側は飲み物を入れられるよう中空

取手(handle):
- マグの **+X 軸方向の側面のみ** に付ける(他の方向には付けない)
- 取手は D 字形状(外側が半円、本体側が直線)で、本体外周にしっかり接続する
- 取手の内側の空間は高さ 30mm × 幅 25mm(指 3 本ぐらい入る)
- 取手はマグの高さ方向の中央付近に付ける
- 本体と取手は確実に union され、マニフォールド(隙間や宙吊りなし)を保つ

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

variant: effort

lownot run
medium (default) success
medium
11.2s · 273/703t · $0.0088
SCAD (72 lines)
$fn = 128;

// Mug dimensions
outer_d = 80;
inner_d = 70;
mug_h   = 90;
bottom_t = 6;

// Handle target opening (inner void)
handle_void_h = 30;
handle_void_w = 25;

// Handle placement
z_center = mug_h / 2;
z0 = z_center - handle_void_h / 2;

// Derived
r_outer = outer_d / 2;
r_inner = inner_d / 2;

// Build
union() {
    // Mug body (hollow with bottom thickness)
    difference() {
        cylinder(h = mug_h, d = outer_d);
        translate([0, 0, bottom_t])
            cylinder(h = mug_h - bottom_t + 0.01, d = inner_d);
    }

    // Handle on +X side only: D-shape in XZ profile, extruded along Y
    // Inner opening: 25 (X) x 30 (Z)
    // Ring thickness around opening:
    t_radial = 5;   // along X/Z profile
    t_depth  = 10;  // along Y (grip thickness)

    // Place so inner flat side lies on mug outer tangent plane at x = r_outer
    x_inner_flat = r_outer;
    x_outer_flat = x_inner_flat + t_radial;

    // Inner profile center (for semicircle cap)
    xi_c = x_inner_flat + handle_void_w;       // center x of inner semicircle
    zi_c = z_center;

    // Outer profile center
    xo_c = x_outer_flat + handle_void_w + t_radial;
    zo_c = z_center;

    // Depth placement: centered at y=0
    y0 = - (handle_void_h + 0) / 2; // not used directly; keep symmetry intent

    // Construct as outer D minus inner D, then union with mug
    translate([0, 0, 0])
    difference() {
        // Outer D, extruded in Y
        translate([0, -t_depth/2, 0])
        rotate([-90, 0, 0])
        linear_extrude(height = t_depth)
        polygon(points = concat(
            [[x_outer_flat, z0 - t_radial], [x_outer_flat, z0 + handle_void_h + t_radial]],
            [ for (a = [90 : -2 : -90]) [ xo_c + (handle_void_h/2 + t_radial) * cos(a), zo_c + (handle_void_h/2 + t_radial) * sin(a) ] ]
        ));

        // Inner D void, extruded slightly larger in Y to ensure clean subtraction
        translate([0, -(t_depth/2 + 0.1), 0])
        rotate([-90, 0, 0])
        linear_extrude(height = t_depth + 0.2)
        polygon(points = concat(
            [[x_inner_flat, z0], [x_inner_flat, z0 + handle_void_h]],
            [ for (a = [90 : -2 : -90]) [ xi_c + (handle_void_h/2) * cos(a), zi_c + (handle_void_h/2) * sin(a) ] ]
        ));
    }
}
highnot run
maxnot run
xhighnot run

iteration: iter-png

i1 success
iter 1
8.8s · 1641/603t · $0.0097
diff vs bare: +50/-53
  $fn = 128;
  
- // Mug dimensions
- outer_d = 80;
- inner_d = 70;
- mug_h   = 90;
- bottom_t = 6;
+ // ===== Mug dimensions =====
+ outer_d  = 80;   // mm
+ inner_d  = 70;   // mm
+ mug_h    = 90;   // mm
+ bottom_t = 6;    // mm
  
- // Handle target opening (inner void)
- handle_void_h = 30;
- handle_void_w = 25;
+ // ===== Handle inner opening requirement =====
+ // inner void: height 30mm (Z) x width 25mm (radial X)
+ void_h = 30;
+ void_w = 25;
  
- // Handle placement
- z_center = mug_h / 2;
- z0 = z_center - handle_void_h / 2;
+ // ===== Handle thickness =====
+ t_radial = 5;    // ring thickness in XZ profile
+ t_depth  = 10;   // thickness along Y
  
- // Derived
  r_outer = outer_d / 2;
- r_inner = inner_d / 2;
  
- // Build
- union() {
-     // Mug body (hollow with bottom thickness)
-     difference() {
-         cylinder(h = mug_h, d = outer_d);
-         translate([0, 0, bottom_t])
-             cylinder(h = mug_h - bottom_t + 0.01, d = inner_d);
-     }
+ // Centers for vertical placement (middle of mug)
+ zc = mug_h / 2;
+ zi0 = zc - void_h/2;
+ zi1 = zc + void_h/2;
  
-     // Handle on +X side only: D-shape in XZ profile, extruded along Y
-     // Inner opening: 25 (X) x 30 (Z)
-     // Ring thickness around opening:
-     t_radial = 5;   // along X/Z profile
-     t_depth  = 10;  // along Y (grip thickness)
+ // D-profile radii (in XZ)
+ ri = void_h / 2;          // inner semicircle radius = 15
+ ro = ri + t_radial;       // outer semicircle radius = 20
  
-     // Place so inner flat side lies on mug outer tangent plane at x = r_outer
-     x_inner_flat = r_outer;
-     x_outer_flat = x_inner_flat + t_radial;
+ // X positions so inner flat side touches mug at +X tangent plane
+ x_flat_inner = r_outer;               // contact plane with mug
+ x_flat_outer = x_flat_inner + t_radial;
  
-     // Inner profile center (for semicircle cap)
-     xi_c = x_inner_flat + handle_void_w;       // center x of inner semicircle
-     zi_c = z_center;
+ x_ci = x_flat_inner + void_w;         // inner semicircle center x
+ x_co = x_flat_outer + void_w + t_radial; // outer semicircle center x
  
-     // Outer profile center
-     xo_c = x_outer_flat + handle_void_w + t_radial;
-     zo_c = z_center;
+ module d_profile(x_flat, z0, z1, x_c, r) {
+     polygon(points = concat(
+         [[x_flat, z0], [x_flat, z1]],
+         [for (a = [90:-2:-90]) [x_c + r*cos(a), zc + r*sin(a)]]
+     ));
+ }
  
-     // Depth placement: centered at y=0
-     y0 = - (handle_void_h + 0) / 2; // not used directly; keep symmetry intent
+ module mug_body() {
+     difference() {
+         cylinder(h = mug_h, d = outer_d);
+         translate([0,0,bottom_t])
+             cylinder(h = mug_h - bottom_t + 0.01, d = inner_d);
+     }
+ }
  
-     // Construct as outer D minus inner D, then union with mug
-     translate([0, 0, 0])
+ module handle() {
+     // D-ring extruded along Y and centered at y=0
      difference() {
-         // Outer D, extruded in Y
          translate([0, -t_depth/2, 0])
-         rotate([-90, 0, 0])
-         linear_extrude(height = t_depth)
-         polygon(points = concat(
-             [[x_outer_flat, z0 - t_radial], [x_outer_flat, z0 + handle_void_h + t_radial]],
-             [ for (a = [90 : -2 : -90]) [ xo_c + (handle_void_h/2 + t_radial) * cos(a), zo_c + (handle_void_h/2 + t_radial) * sin(a) ] ]
-         ));
+             rotate([-90,0,0])
+                 linear_extrude(height = t_depth)
+                     d_profile(x_flat_outer, zi0 - t_radial, zi1 + t_radial, x_co, ro);
  
-         // Inner D void, extruded slightly larger in Y to ensure clean subtraction
          translate([0, -(t_depth/2 + 0.1), 0])
-         rotate([-90, 0, 0])
-         linear_extrude(height = t_depth + 0.2)
-         polygon(points = concat(
-             [[x_inner_flat, z0], [x_inner_flat, z0 + handle_void_h]],
-             [ for (a = [90 : -2 : -90]) [ xi_c + (handle_void_h/2) * cos(a), zi_c + (handle_void_h/2) * sin(a) ] ]
-         ));
+             rotate([-90,0,0])
+                 linear_extrude(height = t_depth + 0.2)
+                     d_profile(x_flat_inner, zi0, zi1, x_ci, ri);
      }
+ }
+ 
+ union() {
+     mug_body();
+     handle();   // attached on +X side only
  }
SCAD (69 lines)
$fn = 128;

// ===== Mug dimensions =====
outer_d  = 80;   // mm
inner_d  = 70;   // mm
mug_h    = 90;   // mm
bottom_t = 6;    // mm

// ===== Handle inner opening requirement =====
// inner void: height 30mm (Z) x width 25mm (radial X)
void_h = 30;
void_w = 25;

// ===== Handle thickness =====
t_radial = 5;    // ring thickness in XZ profile
t_depth  = 10;   // thickness along Y

r_outer = outer_d / 2;

// Centers for vertical placement (middle of mug)
zc = mug_h / 2;
zi0 = zc - void_h/2;
zi1 = zc + void_h/2;

// D-profile radii (in XZ)
ri = void_h / 2;          // inner semicircle radius = 15
ro = ri + t_radial;       // outer semicircle radius = 20

// X positions so inner flat side touches mug at +X tangent plane
x_flat_inner = r_outer;               // contact plane with mug
x_flat_outer = x_flat_inner + t_radial;

x_ci = x_flat_inner + void_w;         // inner semicircle center x
x_co = x_flat_outer + void_w + t_radial; // outer semicircle center x

module d_profile(x_flat, z0, z1, x_c, r) {
    polygon(points = concat(
        [[x_flat, z0], [x_flat, z1]],
        [for (a = [90:-2:-90]) [x_c + r*cos(a), zc + r*sin(a)]]
    ));
}

module mug_body() {
    difference() {
        cylinder(h = mug_h, d = outer_d);
        translate([0,0,bottom_t])
            cylinder(h = mug_h - bottom_t + 0.01, d = inner_d);
    }
}

module handle() {
    // D-ring extruded along Y and centered at y=0
    difference() {
        translate([0, -t_depth/2, 0])
            rotate([-90,0,0])
                linear_extrude(height = t_depth)
                    d_profile(x_flat_outer, zi0 - t_radial, zi1 + t_radial, x_co, ro);

        translate([0, -(t_depth/2 + 0.1), 0])
            rotate([-90,0,0])
                linear_extrude(height = t_depth + 0.2)
                    d_profile(x_flat_inner, zi0, zi1, x_ci, ri);
    }
}

union() {
    mug_body();
    handle();   // attached on +X side only
}
i2 success
iter 2
8.2s · 1540/632t · $0.0099
diff vs i1: +34/-27
  $fn = 128;
  
  // ===== Mug dimensions =====
  outer_d  = 80;   // mm
  inner_d  = 70;   // mm
  mug_h    = 90;   // mm
  bottom_t = 6;    // mm
  
  // ===== Handle inner opening requirement =====
  // inner void: height 30mm (Z) x width 25mm (radial X)
  void_h = 30;
  void_w = 25;
  
  // ===== Handle thickness =====
- t_radial = 5;    // ring thickness in XZ profile
- t_depth  = 10;   // thickness along Y
+ t_radial = 5;    // wall thickness in XZ profile
+ t_depth  = 10;   // thickness along Y (grip depth)
  
+ // Vertical center of handle
+ zc = mug_h / 2;
+ 
+ // Mug outer radius
  r_outer = outer_d / 2;
  
- // Centers for vertical placement (middle of mug)
- zc = mug_h / 2;
- zi0 = zc - void_h/2;
- zi1 = zc + void_h/2;
+ // Inner D profile (opening)
+ ri   = void_h / 2;         // 15
+ x_ci = r_outer + void_w;   // inner semicircle center X
+ zi0  = zc - void_h/2;
+ zi1  = zc + void_h/2;
  
- // D-profile radii (in XZ)
- ri = void_h / 2;          // inner semicircle radius = 15
- ro = ri + t_radial;       // outer semicircle radius = 20
+ // Outer D profile (handle body), offset by t_radial
+ ro   = ri + t_radial;                 // 20
+ x_co = x_ci + t_radial;               // keep constant radial thickness
+ zo0  = zi0 - t_radial;
+ zo1  = zi1 + t_radial;
  
- // X positions so inner flat side touches mug at +X tangent plane
- x_flat_inner = r_outer;               // contact plane with mug
+ // Ensure manifold union with mug: overlap into mug wall by epsilon
+ eps = 0.6;                            // small penetration for robust union
+ x_flat_inner = r_outer - eps;         // inner flat of handle body
  x_flat_outer = x_flat_inner + t_radial;
  
- x_ci = x_flat_inner + void_w;         // inner semicircle center x
- x_co = x_flat_outer + void_w + t_radial; // outer semicircle center x
- 
  module d_profile(x_flat, z0, z1, x_c, r) {
      polygon(points = concat(
          [[x_flat, z0], [x_flat, z1]],
          [for (a = [90:-2:-90]) [x_c + r*cos(a), zc + r*sin(a)]]
      ));
  }
  
  module mug_body() {
      difference() {
          cylinder(h = mug_h, d = outer_d);
          translate([0,0,bottom_t])
              cylinder(h = mug_h - bottom_t + 0.01, d = inner_d);
      }
  }
  
- module handle() {
-     // D-ring extruded along Y and centered at y=0
-     difference() {
-         translate([0, -t_depth/2, 0])
-             rotate([-90,0,0])
-                 linear_extrude(height = t_depth)
-                     d_profile(x_flat_outer, zi0 - t_radial, zi1 + t_radial, x_co, ro);
+ module handle_body() {
+     translate([0, -t_depth/2, 0])
+         rotate([-90,0,0])
+             linear_extrude(height = t_depth)
+                 d_profile(x_flat_outer, zo0, zo1, x_co, ro);
+ }
  
-         translate([0, -(t_depth/2 + 0.1), 0])
-             rotate([-90,0,0])
-                 linear_extrude(height = t_depth + 0.2)
-                     d_profile(x_flat_inner, zi0, zi1, x_ci, ri);
-     }
+ module handle_hole() {
+     translate([0, -(t_depth/2 + 0.1), 0])
+         rotate([-90,0,0])
+             linear_extrude(height = t_depth + 0.2)
+                 d_profile(r_outer, zi0, zi1, x_ci, ri); // flat side exactly at mug tangent
  }
  
  union() {
      mug_body();
-     handle();   // attached on +X side only
+     difference() {
+         handle_body();
+         handle_hole();
+     }
  }
SCAD (76 lines)
$fn = 128;

// ===== Mug dimensions =====
outer_d  = 80;   // mm
inner_d  = 70;   // mm
mug_h    = 90;   // mm
bottom_t = 6;    // mm

// ===== Handle inner opening requirement =====
// inner void: height 30mm (Z) x width 25mm (radial X)
void_h = 30;
void_w = 25;

// ===== Handle thickness =====
t_radial = 5;    // wall thickness in XZ profile
t_depth  = 10;   // thickness along Y (grip depth)

// Vertical center of handle
zc = mug_h / 2;

// Mug outer radius
r_outer = outer_d / 2;

// Inner D profile (opening)
ri   = void_h / 2;         // 15
x_ci = r_outer + void_w;   // inner semicircle center X
zi0  = zc - void_h/2;
zi1  = zc + void_h/2;

// Outer D profile (handle body), offset by t_radial
ro   = ri + t_radial;                 // 20
x_co = x_ci + t_radial;               // keep constant radial thickness
zo0  = zi0 - t_radial;
zo1  = zi1 + t_radial;

// Ensure manifold union with mug: overlap into mug wall by epsilon
eps = 0.6;                            // small penetration for robust union
x_flat_inner = r_outer - eps;         // inner flat of handle body
x_flat_outer = x_flat_inner + t_radial;

module d_profile(x_flat, z0, z1, x_c, r) {
    polygon(points = concat(
        [[x_flat, z0], [x_flat, z1]],
        [for (a = [90:-2:-90]) [x_c + r*cos(a), zc + r*sin(a)]]
    ));
}

module mug_body() {
    difference() {
        cylinder(h = mug_h, d = outer_d);
        translate([0,0,bottom_t])
            cylinder(h = mug_h - bottom_t + 0.01, d = inner_d);
    }
}

module handle_body() {
    translate([0, -t_depth/2, 0])
        rotate([-90,0,0])
            linear_extrude(height = t_depth)
                d_profile(x_flat_outer, zo0, zo1, x_co, ro);
}

module handle_hole() {
    translate([0, -(t_depth/2 + 0.1), 0])
        rotate([-90,0,0])
            linear_extrude(height = t_depth + 0.2)
                d_profile(r_outer, zi0, zi1, x_ci, ri); // flat side exactly at mug tangent
}

union() {
    mug_body();
    difference() {
        handle_body();
        handle_hole();
    }
}
i3 success
iter 3
10.0s · 1570/668t · $0.0104
diff vs i2: +27/-22
  $fn = 128;
  
  // ===== Mug dimensions =====
  outer_d  = 80;   // mm
  inner_d  = 70;   // mm
  mug_h    = 90;   // mm
  bottom_t = 6;    // mm
  
  // ===== Handle inner opening requirement =====
  // inner void: height 30mm (Z) x width 25mm (radial X)
  void_h = 30;
  void_w = 25;
  
  // ===== Handle thickness =====
  t_radial = 5;    // wall thickness in XZ profile
- t_depth  = 10;   // thickness along Y (grip depth)
+ t_depth  = 12;   // thickness along Y (grip depth)
  
  // Vertical center of handle
  zc = mug_h / 2;
  
  // Mug outer radius
  r_outer = outer_d / 2;
  
- // Inner D profile (opening)
- ri   = void_h / 2;         // 15
- x_ci = r_outer + void_w;   // inner semicircle center X
- zi0  = zc - void_h/2;
- zi1  = zc + void_h/2;
+ // ----- D profile parameters (in XZ plane) -----
+ ri = void_h / 2;            // 15 (inner semicircle radius)
+ x_ci = r_outer + void_w;    // inner semicircle center X
+ zi0 = zc - void_h/2;
+ zi1 = zc + void_h/2;
  
- // Outer D profile (handle body), offset by t_radial
- ro   = ri + t_radial;                 // 20
- x_co = x_ci + t_radial;               // keep constant radial thickness
- zo0  = zi0 - t_radial;
- zo1  = zi1 + t_radial;
+ // outer profile offset from inner profile
+ ro = ri + t_radial;         // 20
+ x_co = x_ci + t_radial;
+ zo0 = zi0 - t_radial;
+ zo1 = zi1 + t_radial;
  
- // Ensure manifold union with mug: overlap into mug wall by epsilon
- eps = 0.6;                            // small penetration for robust union
- x_flat_inner = r_outer - eps;         // inner flat of handle body
+ // overlap into mug to guarantee manifold union
+ eps = 1.0;
+ x_flat_inner = r_outer - eps;          // inner flat of handle body enters mug
  x_flat_outer = x_flat_inner + t_radial;
  
+ // D-shape polygon: flat side at x_flat, semicircle bulging to +X
  module d_profile(x_flat, z0, z1, x_c, r) {
      polygon(points = concat(
          [[x_flat, z0], [x_flat, z1]],
          [for (a = [90:-2:-90]) [x_c + r*cos(a), zc + r*sin(a)]]
      ));
  }
  
+ // Mug body with hollow interior and bottom thickness
  module mug_body() {
      difference() {
          cylinder(h = mug_h, d = outer_d);
-         translate([0,0,bottom_t])
+         translate([0, 0, bottom_t])
              cylinder(h = mug_h - bottom_t + 0.01, d = inner_d);
      }
  }
  
- module handle_body() {
+ // Handle solid (before carving its opening), centered on +X side
+ module handle_outer() {
      translate([0, -t_depth/2, 0])
-         rotate([-90,0,0])
+         rotate([-90, 0, 0])
              linear_extrude(height = t_depth)
                  d_profile(x_flat_outer, zo0, zo1, x_co, ro);
  }
  
- module handle_hole() {
+ // Inner void of handle (kept tangent at mug outer surface)
+ module handle_inner_void() {
      translate([0, -(t_depth/2 + 0.1), 0])
-         rotate([-90,0,0])
+         rotate([-90, 0, 0])
              linear_extrude(height = t_depth + 0.2)
-                 d_profile(r_outer, zi0, zi1, x_ci, ri); // flat side exactly at mug tangent
+                 d_profile(r_outer, zi0, zi1, x_ci, ri);
  }
  
+ // Final model
  union() {
      mug_body();
      difference() {
-         handle_body();
-         handle_hole();
+         handle_outer();
+         handle_inner_void();
      }
  }
SCAD (81 lines)
$fn = 128;

// ===== Mug dimensions =====
outer_d  = 80;   // mm
inner_d  = 70;   // mm
mug_h    = 90;   // mm
bottom_t = 6;    // mm

// ===== Handle inner opening requirement =====
// inner void: height 30mm (Z) x width 25mm (radial X)
void_h = 30;
void_w = 25;

// ===== Handle thickness =====
t_radial = 5;    // wall thickness in XZ profile
t_depth  = 12;   // thickness along Y (grip depth)

// Vertical center of handle
zc = mug_h / 2;

// Mug outer radius
r_outer = outer_d / 2;

// ----- D profile parameters (in XZ plane) -----
ri = void_h / 2;            // 15 (inner semicircle radius)
x_ci = r_outer + void_w;    // inner semicircle center X
zi0 = zc - void_h/2;
zi1 = zc + void_h/2;

// outer profile offset from inner profile
ro = ri + t_radial;         // 20
x_co = x_ci + t_radial;
zo0 = zi0 - t_radial;
zo1 = zi1 + t_radial;

// overlap into mug to guarantee manifold union
eps = 1.0;
x_flat_inner = r_outer - eps;          // inner flat of handle body enters mug
x_flat_outer = x_flat_inner + t_radial;

// D-shape polygon: flat side at x_flat, semicircle bulging to +X
module d_profile(x_flat, z0, z1, x_c, r) {
    polygon(points = concat(
        [[x_flat, z0], [x_flat, z1]],
        [for (a = [90:-2:-90]) [x_c + r*cos(a), zc + r*sin(a)]]
    ));
}

// Mug body with hollow interior and bottom thickness
module mug_body() {
    difference() {
        cylinder(h = mug_h, d = outer_d);
        translate([0, 0, bottom_t])
            cylinder(h = mug_h - bottom_t + 0.01, d = inner_d);
    }
}

// Handle solid (before carving its opening), centered on +X side
module handle_outer() {
    translate([0, -t_depth/2, 0])
        rotate([-90, 0, 0])
            linear_extrude(height = t_depth)
                d_profile(x_flat_outer, zo0, zo1, x_co, ro);
}

// Inner void of handle (kept tangent at mug outer surface)
module handle_inner_void() {
    translate([0, -(t_depth/2 + 0.1), 0])
        rotate([-90, 0, 0])
            linear_extrude(height = t_depth + 0.2)
                d_profile(r_outer, zi0, zi1, x_ci, ri);
}

// Final model
union() {
    mug_body();
    difference() {
        handle_outer();
        handle_inner_void();
    }
}