vibe-openscad

tier-2-offset-handle-mug / gpt-4.1-2025-04-14

4 run / 累計 50.0s / 累計 $0.0394

openai gpt 4.1 2025-04-14 bare

bare (provider default effort)

run detail →
render
no render
render_error 15.9s · 274/1015t · $0.0087
openscad stl render failed (exit 1): ERROR: Recursion detected calling module 'cylinder' in file input.scad, line 80
TRACE: called by 'cylinder' in file input.scad, line 92
TRACE: called by 'if' in file input.scad, line 91
TRACE: call of 'builtin_cylinder(h = 90, r = 40, $fn = 128, center = false)' in file input.scad, line 89
TRACE: called by 'builtin_cylinder' in file input.scad, line 82
TRACE: called by 'if' in file input.scad, line 81
TRACE: call of 'cylinder(h = 90, r = 40, segment1 = false, $fn = 128, center = false)' in file input.scad, line 80
TRACE: called by 'cylinder' in file input.scad, line 92
TRACE: called by 'if' in file input.scad, line 91
TRACE: call of 'builtin_cylinder(h = 90, r = 40, $fn = 128, center = false)' in file input.scad, line 89
TRACE: called by 'builtin_cylinder' in file input.scad, line 82
TRACE: called by 'if' in file input.scad, line 81
TRACE: call of 'cylinder(h = 90, r = 40, segment1 = false, $fn = 128, center = false)' in file input.scad, line 80
TRACE:   *** Excluding 14999 frames ***
TRACE: call of 'cylinder(h = 90, r = 40, segment1 = false, $fn = 128, center = false)' in file input.scad, line 80
TRACE: called by 'cylinder' in file input.scad, line 92
TRACE: called by 'if' in file input.scad, line 91
TRACE: call of 'builtin_cylinder(h = 90, r = 40, $fn = 128, center = false)' in file input.scad, line 89
TRACE: called by 'builtin_cylinder' in file input.scad, line 82
TRACE: called by 'if' in file input.scad, line 81
TRACE: call of 'cylinder(h = 90, r = 40, segment1 = false, $fn = 128, center = false)' in file input.scad, line 80
TRACE: called by 'cylinder' in file input.scad, line 26
TRACE: called by 'difference' in file input.scad, line 24
TRACE: call of 'mug_body()' in file input.scad, line 23
TRACE: called by 'mug_body' in file input.scad, line 74
TRACE: called by 'union' in file input.scad, line 73
Current top level object is empty.
SCAD (104 lines)
// マグ本体パラメータ
mug_outer_diameter = 80;    // mm
mug_inner_diameter = 70;    // mm
mug_height = 90;            // mm
mug_wall_thickness = 5;     // mm
mug_bottom_thickness = 6;   // mm

// 取手パラメータ
handle_inner_height = 30;   // mm
handle_inner_width  = 25;   // mm
handle_thickness    = 12;   // mm (グリップの厚み)
handle_clearance    = 3;    // mm (マグと取手のすき間:0でぴったり)

// 共通計算
mug_radius = mug_outer_diameter / 2;
mug_inner_radius = mug_inner_diameter / 2;
handle_top = (mug_height + handle_inner_height) / 2;
handle_bottom = (mug_height - handle_inner_height) / 2;
handle_center_y = 0;
handle_center_z = mug_height / 2;

// マグのメインモジュール
module mug_body() {
    difference() {
        // 外側
        cylinder(h = mug_height, r = mug_radius, $fn = 128);
        // 内部空間(底厚分上げる)
        translate([0, 0, mug_bottom_thickness])
            cylinder(h = mug_height - mug_bottom_thickness, r = mug_inner_radius, $fn = 128);
    }
}

// D字ハンドル
module mug_handle() {
    // D字の中心半径: (内幅+厚み)/2
    handle_outer_radius = (handle_inner_width + handle_thickness) / 2;
    handle_inner_radius = handle_inner_width / 2;

    // 上下の位置
    z_pos = mug_height / 2 - handle_inner_height / 2;

    // ハンドル中心(x 座標: 本体外半径 + handle_thickness/2)
    translate([mug_radius + handle_thickness / 2 - handle_clearance, 0, handle_bottom]) {
        // D字全体
        difference() {
            // 外側D
            union() {
                // 半円部分
                rotate([90,0,0])
                    translate([0, 0, handle_inner_height/2])
                        cylinder(h = handle_thickness, r = handle_outer_radius, center=true, $fn=64, segment1=true);
                // 直線部分(上下のバー)
                for (sign=[-1,1])
                    translate([0, sign*(handle_inner_height/2), 0])
                        cube([handle_outer_radius, handle_thickness, handle_thickness], center = true);
            }
            // 内側カット
            union() {
                // 半円部分
                rotate([90,0,0])
                    translate([0, 0, handle_inner_height/2])
                        cylinder(h = handle_thickness+0.1, r = handle_inner_radius, center=true, $fn=64, segment1=true);
                // 直線部分
                for (sign=[-1,1])
                    translate([0, sign*(handle_inner_height/2), 0])
                        cube([handle_inner_radius+0.1, handle_thickness+0.1, handle_thickness+0.1], center = true);
            }
        }
    }
}

// マグとハンドルの合成
union() {
    mug_body();
    mug_handle();
}

// 円柱の半円(セグメント)を描画するための segment1=true 拡張
// OpenSCADの標準 cylinder では使えません。互換目的のヘルパー:
module cylinder(h, r, segment1=false, $fn=64, center=false) {
    if (!segment1)
        builtin_cylinder(h=h, r=r, $fn=$fn, center=center);
    else
        rotate([0,0,90])
            linear_extrude(height=h, center=center)
                offset(0)
                arc(r, 180);
}
module builtin_cylinder(h, r, $fn=64, center=false) {
    // シンプルな円
    if (!center)
        cylinder(h=h, r=r, $fn=$fn);
    else
        translate([0,0,-h/2]) cylinder(h=h, r=r, $fn=$fn);
}
module arc(r, angle) {
    polygon(
        concat(
            [[0,0]],
            [ for (a = [0:angle/($fn-1):angle]) [ r*cos(a), r*sin(a) ] ],
            [[0,0]]
        )
    );
}

prompt

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

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

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

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

iteration: iter-png

i1 success
iter 1
12.0s · 1976/851t · $0.0108
diff vs bare: +32/-50
  // マグ本体パラメータ
  mug_outer_diameter = 80;    // mm
  mug_inner_diameter = 70;    // mm
  mug_height = 90;            // mm
  mug_wall_thickness = 5;     // mm
  mug_bottom_thickness = 6;   // mm
  
  // 取手パラメータ
  handle_inner_height = 30;   // mm
  handle_inner_width  = 25;   // mm
  handle_thickness    = 12;   // mm (グリップの厚み)
- handle_clearance    = 3;    // mm (マグと取手のすき間:0でぴったり)
+ handle_clearance    = 0;    // mm (マグと取手のすき間:0でぴったり)
  
  // 共通計算
  mug_radius = mug_outer_diameter / 2;
  mug_inner_radius = mug_inner_diameter / 2;
  handle_top = (mug_height + handle_inner_height) / 2;
  handle_bottom = (mug_height - handle_inner_height) / 2;
  handle_center_y = 0;
  handle_center_z = mug_height / 2;
  
  // マグのメインモジュール
  module mug_body() {
      difference() {
          // 外側
          cylinder(h = mug_height, r = mug_radius, $fn = 128);
          // 内部空間(底厚分上げる)
          translate([0, 0, mug_bottom_thickness])
              cylinder(h = mug_height - mug_bottom_thickness, r = mug_inner_radius, $fn = 128);
      }
  }
  
  // D字ハンドル
  module mug_handle() {
-     // D字の中心半径: (内幅+厚み)/2
+     // D字グリップの円弧半径
      handle_outer_radius = (handle_inner_width + handle_thickness) / 2;
-     handle_inner_radius = handle_inner_width / 2;
+     handle_inner_radius = handle_outer_radius - handle_thickness;
  
-     // 上下の位置
-     z_pos = mug_height / 2 - handle_inner_height / 2;
+     // ハンドル中心の x 方向座標(マグ外縁+取っ手外半径、隙間なし)
+     handle_center_x = mug_radius + handle_outer_radius;
  
-     // ハンドル中心(x 座標: 本体外半径 + handle_thickness/2)
-     translate([mug_radius + handle_thickness / 2 - handle_clearance, 0, handle_bottom]) {
-         // D字全体
+     // ハンドルの中心高さ
+     handle_center_z = mug_height / 2;
+ 
+     // D字部分(半円部分+上下の直線バー)
+     translate([handle_center_x, 0, handle_center_z]) {
          difference() {
-             // 外側D
+             // 外側(D字: 半円弧+直線)
              union() {
-                 // 半円部分
-                 rotate([90,0,0])
-                     translate([0, 0, handle_inner_height/2])
-                         cylinder(h = handle_thickness, r = handle_outer_radius, center=true, $fn=64, segment1=true);
-                 // 直線部分(上下のバー)
+                 // 半円弧
+                 rotate([0,90,0])
+                     rotate([0,0,90])
+                         linear_extrude(height=handle_thickness, center=true)
+                             offset(0)
+                                 arc_points(handle_outer_radius, 180);
+                 // 上下の直線バー
                  for (sign=[-1,1])
-                     translate([0, sign*(handle_inner_height/2), 0])
+                     translate([0, sign*handle_inner_height/2, 0])
                          cube([handle_outer_radius, handle_thickness, handle_thickness], center = true);
              }
              // 内側カット
              union() {
-                 // 半円部分
-                 rotate([90,0,0])
-                     translate([0, 0, handle_inner_height/2])
-                         cylinder(h = handle_thickness+0.1, r = handle_inner_radius, center=true, $fn=64, segment1=true);
-                 // 直線部分
+                 // 半円弧
+                 rotate([0,90,0])
+                     rotate([0,0,90])
+                         linear_extrude(height=handle_thickness+0.2, center=true)
+                             offset(0)
+                                 arc_points(handle_inner_radius, 180);
+                 // 上下の直線バー
                  for (sign=[-1,1])
-                     translate([0, sign*(handle_inner_height/2), 0])
-                         cube([handle_inner_radius+0.1, handle_thickness+0.1, handle_thickness+0.1], center = true);
+                     translate([0, sign*handle_inner_height/2, 0])
+                         cube([handle_inner_radius+0.2, handle_thickness+0.2, handle_thickness+0.2], center = true);
              }
          }
      }
  }
  
+ // 2D半円弧のポリゴン(中心始点+極座標)
+ function arc_points(r, deg=180, steps=64) =
+     concat([[0,0]], [for (a = [0 : deg/(steps-1) : deg]) [r*cos(a), r*sin(a)]]);
+ 
  // マグとハンドルの合成
  union() {
      mug_body();
      mug_handle();
- }
- 
- // 円柱の半円(セグメント)を描画するための segment1=true 拡張
- // OpenSCADの標準 cylinder では使えません。互換目的のヘルパー:
- module cylinder(h, r, segment1=false, $fn=64, center=false) {
-     if (!segment1)
-         builtin_cylinder(h=h, r=r, $fn=$fn, center=center);
-     else
-         rotate([0,0,90])
-             linear_extrude(height=h, center=center)
-                 offset(0)
-                 arc(r, 180);
- }
- module builtin_cylinder(h, r, $fn=64, center=false) {
-     // シンプルな円
-     if (!center)
-         cylinder(h=h, r=r, $fn=$fn);
-     else
-         translate([0,0,-h/2]) cylinder(h=h, r=r, $fn=$fn);
- }
- module arc(r, angle) {
-     polygon(
-         concat(
-             [[0,0]],
-             [ for (a = [0:angle/($fn-1):angle]) [ r*cos(a), r*sin(a) ] ],
-             [[0,0]]
-         )
-     );
  }
SCAD (86 lines)
// マグ本体パラメータ
mug_outer_diameter = 80;    // mm
mug_inner_diameter = 70;    // mm
mug_height = 90;            // mm
mug_wall_thickness = 5;     // mm
mug_bottom_thickness = 6;   // mm

// 取手パラメータ
handle_inner_height = 30;   // mm
handle_inner_width  = 25;   // mm
handle_thickness    = 12;   // mm (グリップの厚み)
handle_clearance    = 0;    // mm (マグと取手のすき間:0でぴったり)

// 共通計算
mug_radius = mug_outer_diameter / 2;
mug_inner_radius = mug_inner_diameter / 2;
handle_top = (mug_height + handle_inner_height) / 2;
handle_bottom = (mug_height - handle_inner_height) / 2;
handle_center_y = 0;
handle_center_z = mug_height / 2;

// マグのメインモジュール
module mug_body() {
    difference() {
        // 外側
        cylinder(h = mug_height, r = mug_radius, $fn = 128);
        // 内部空間(底厚分上げる)
        translate([0, 0, mug_bottom_thickness])
            cylinder(h = mug_height - mug_bottom_thickness, r = mug_inner_radius, $fn = 128);
    }
}

// D字ハンドル
module mug_handle() {
    // D字グリップの円弧半径
    handle_outer_radius = (handle_inner_width + handle_thickness) / 2;
    handle_inner_radius = handle_outer_radius - handle_thickness;

    // ハンドル中心の x 方向座標(マグ外縁+取っ手外半径、隙間なし)
    handle_center_x = mug_radius + handle_outer_radius;

    // ハンドルの中心高さ
    handle_center_z = mug_height / 2;

    // D字部分(半円部分+上下の直線バー)
    translate([handle_center_x, 0, handle_center_z]) {
        difference() {
            // 外側(D字: 半円弧+直線)
            union() {
                // 半円弧
                rotate([0,90,0])
                    rotate([0,0,90])
                        linear_extrude(height=handle_thickness, center=true)
                            offset(0)
                                arc_points(handle_outer_radius, 180);
                // 上下の直線バー
                for (sign=[-1,1])
                    translate([0, sign*handle_inner_height/2, 0])
                        cube([handle_outer_radius, handle_thickness, handle_thickness], center = true);
            }
            // 内側カット
            union() {
                // 半円弧
                rotate([0,90,0])
                    rotate([0,0,90])
                        linear_extrude(height=handle_thickness+0.2, center=true)
                            offset(0)
                                arc_points(handle_inner_radius, 180);
                // 上下の直線バー
                for (sign=[-1,1])
                    translate([0, sign*handle_inner_height/2, 0])
                        cube([handle_inner_radius+0.2, handle_thickness+0.2, handle_thickness+0.2], center = true);
            }
        }
    }
}

// 2D半円弧のポリゴン(中心始点+極座標)
function arc_points(r, deg=180, steps=64) =
    concat([[0,0]], [for (a = [0 : deg/(steps-1) : deg]) [r*cos(a), r*sin(a)]]);

// マグとハンドルの合成
union() {
    mug_body();
    mug_handle();
}
i2 success
iter 2
10.0s · 1985/708t · $0.0096
diff vs i1: +27/-56
  // マグ本体パラメータ
  mug_outer_diameter = 80;    // mm
  mug_inner_diameter = 70;    // mm
  mug_height = 90;            // mm
  mug_wall_thickness = 5;     // mm
  mug_bottom_thickness = 6;   // mm
  
  // 取手パラメータ
- handle_inner_height = 30;   // mm
- handle_inner_width  = 25;   // mm
- handle_thickness    = 12;   // mm (グリップの厚み)
- handle_clearance    = 0;    // mm (マグと取手のすき間:0でぴったり)
+ handle_inner_height = 30;    // mm
+ handle_inner_width  = 25;    // mm
+ handle_thickness    = 12;    // mm (グリップ断面の太さ)
  
- // 共通計算
+ // マグ座標
  mug_radius = mug_outer_diameter / 2;
  mug_inner_radius = mug_inner_diameter / 2;
- handle_top = (mug_height + handle_inner_height) / 2;
- handle_bottom = (mug_height - handle_inner_height) / 2;
- handle_center_y = 0;
- handle_center_z = mug_height / 2;
  
- // マグのメインモジュール
+ // 取手座標・D字生成用
+ handle_profile_top    = handle_inner_height / 2;
+ handle_profile_bottom = -handle_inner_height / 2;
+ handle_profile_right  = mug_radius + handle_inner_width;
+ handle_profile_left   = mug_radius;
+ 
  module mug_body() {
      difference() {
          // 外側
          cylinder(h = mug_height, r = mug_radius, $fn = 128);
-         // 内部空間(底厚分上げる)
+         // 内容器
          translate([0, 0, mug_bottom_thickness])
              cylinder(h = mug_height - mug_bottom_thickness, r = mug_inner_radius, $fn = 128);
      }
  }
  
- // D字ハンドル
- module mug_handle() {
-     // D字グリップの円弧半径
-     handle_outer_radius = (handle_inner_width + handle_thickness) / 2;
-     handle_inner_radius = handle_outer_radius - handle_thickness;
- 
-     // ハンドル中心の x 方向座標(マグ外縁+取っ手外半径、隙間なし)
-     handle_center_x = mug_radius + handle_outer_radius;
- 
-     // ハンドルの中心高さ
+ module d_handle() {
+     // D字2Dプロファイル作成
+     // 縦方向がhandle_inner_heightの長方形+右に半円
      handle_center_z = mug_height / 2;
+     translate([0, 0, handle_center_z])  // マグ中央高さに配置
+     rotate([90,0,0])
+     translate([0, 0, 0]) {
+         rotate_extrude(angle=180, $fn=64)
+             translate([mug_radius + handle_inner_width, 0, 0])
+                 circle(handle_inner_height/2, $fn=64);
  
-     // D字部分(半円部分+上下の直線バー)
-     translate([handle_center_x, 0, handle_center_z]) {
-         difference() {
-             // 外側(D字: 半円弧+直線)
-             union() {
-                 // 半円弧
-                 rotate([0,90,0])
-                     rotate([0,0,90])
-                         linear_extrude(height=handle_thickness, center=true)
-                             offset(0)
-                                 arc_points(handle_outer_radius, 180);
-                 // 上下の直線バー
-                 for (sign=[-1,1])
-                     translate([0, sign*handle_inner_height/2, 0])
-                         cube([handle_outer_radius, handle_thickness, handle_thickness], center = true);
-             }
-             // 内側カット
-             union() {
-                 // 半円弧
-                 rotate([0,90,0])
-                     rotate([0,0,90])
-                         linear_extrude(height=handle_thickness+0.2, center=true)
-                             offset(0)
-                                 arc_points(handle_inner_radius, 180);
-                 // 上下の直線バー
-                 for (sign=[-1,1])
-                     translate([0, sign*handle_inner_height/2, 0])
-                         cube([handle_inner_radius+0.2, handle_thickness+0.2, handle_thickness+0.2], center = true);
-             }
+         // ハンドルの直線部分(マグ側に接するストレート部分)
+         hull() {
+             translate([mug_radius, handle_profile_top]) circle(handle_thickness/2, $fn=32);
+             translate([mug_radius, handle_profile_bottom]) circle(handle_thickness/2, $fn=32);
          }
      }
  }
  
- // 2D半円弧のポリゴン(中心始点+極座標)
- function arc_points(r, deg=180, steps=64) =
-     concat([[0,0]], [for (a = [0 : deg/(steps-1) : deg]) [r*cos(a), r*sin(a)]]);
- 
- // マグとハンドルの合成
  union() {
      mug_body();
-     mug_handle();
+     // 取手を-90度回転して+X側に設置し、太さ分拡げる
+     rotate([0,0,0])
+         d_handle();
  }
SCAD (57 lines)
// マグ本体パラメータ
mug_outer_diameter = 80;    // mm
mug_inner_diameter = 70;    // mm
mug_height = 90;            // mm
mug_wall_thickness = 5;     // mm
mug_bottom_thickness = 6;   // mm

// 取手パラメータ
handle_inner_height = 30;    // mm
handle_inner_width  = 25;    // mm
handle_thickness    = 12;    // mm (グリップ断面の太さ)

// マグ座標
mug_radius = mug_outer_diameter / 2;
mug_inner_radius = mug_inner_diameter / 2;

// 取手座標・D字生成用
handle_profile_top    = handle_inner_height / 2;
handle_profile_bottom = -handle_inner_height / 2;
handle_profile_right  = mug_radius + handle_inner_width;
handle_profile_left   = mug_radius;

module mug_body() {
    difference() {
        // 外側
        cylinder(h = mug_height, r = mug_radius, $fn = 128);
        // 内容器
        translate([0, 0, mug_bottom_thickness])
            cylinder(h = mug_height - mug_bottom_thickness, r = mug_inner_radius, $fn = 128);
    }
}

module d_handle() {
    // D字2Dプロファイル作成
    // 縦方向がhandle_inner_heightの長方形+右に半円
    handle_center_z = mug_height / 2;
    translate([0, 0, handle_center_z])  // マグ中央高さに配置
    rotate([90,0,0])
    translate([0, 0, 0]) {
        rotate_extrude(angle=180, $fn=64)
            translate([mug_radius + handle_inner_width, 0, 0])
                circle(handle_inner_height/2, $fn=64);

        // ハンドルの直線部分(マグ側に接するストレート部分)
        hull() {
            translate([mug_radius, handle_profile_top]) circle(handle_thickness/2, $fn=32);
            translate([mug_radius, handle_profile_bottom]) circle(handle_thickness/2, $fn=32);
        }
    }
}

union() {
    mug_body();
    // 取手を-90度回転して+X側に設置し、太さ分拡げる
    rotate([0,0,0])
        d_handle();
}
i3 success
iter 3
12.2s · 1687/870t · $0.0103
diff vs i2: +38/-28
  // マグ本体パラメータ
  mug_outer_diameter = 80;    // mm
  mug_inner_diameter = 70;    // mm
  mug_height = 90;            // mm
  mug_wall_thickness = 5;     // mm
  mug_bottom_thickness = 6;   // mm
  
  // 取手パラメータ
  handle_inner_height = 30;    // mm
  handle_inner_width  = 25;    // mm
- handle_thickness    = 12;    // mm (グリップ断面の太さ)
+ handle_thickness    = 12;    // mm  // 指が入りつつ頑丈さ優先
  
- // マグ座標
  mug_radius = mug_outer_diameter / 2;
  mug_inner_radius = mug_inner_diameter / 2;
  
- // 取手座標・D字生成用
- handle_profile_top    = handle_inner_height / 2;
- handle_profile_bottom = -handle_inner_height / 2;
- handle_profile_right  = mug_radius + handle_inner_width;
- handle_profile_left   = mug_radius;
+ // 取手スケッチ中心位置
+ handle_center_z = mug_height/2;
  
  module mug_body() {
      difference() {
-         // 外側
          cylinder(h = mug_height, r = mug_radius, $fn = 128);
-         // 内容器
          translate([0, 0, mug_bottom_thickness])
              cylinder(h = mug_height - mug_bottom_thickness, r = mug_inner_radius, $fn = 128);
      }
  }
  
- module d_handle() {
-     // D字2Dプロファイル作成
-     // 縦方向がhandle_inner_heightの長方形+右に半円
-     handle_center_z = mug_height / 2;
-     translate([0, 0, handle_center_z])  // マグ中央高さに配置
-     rotate([90,0,0])
-     translate([0, 0, 0]) {
-         rotate_extrude(angle=180, $fn=64)
-             translate([mug_radius + handle_inner_width, 0, 0])
-                 circle(handle_inner_height/2, $fn=64);
+ module handle_D() {
+     // D字断面の外周
+     inner_r = handle_inner_height/2;  // D字の半円内半径
+     outer_r = inner_r + handle_thickness;
  
-         // ハンドルの直線部分(マグ側に接するストレート部分)
-         hull() {
-             translate([mug_radius, handle_profile_top]) circle(handle_thickness/2, $fn=32);
-             translate([mug_radius, handle_profile_bottom]) circle(handle_thickness/2, $fn=32);
-         }
-     }
+     // D字2Dプロファイル
+     //   左辺(本体接触)が直線、右辺が半円
+     handle_profile = 
+         concat( // 下から上への直線
+             [ [0, -inner_r], [0, inner_r] ],
+             [ for (a = [90 : -1 : -90])
+                 [handle_inner_width/2 + inner_r * cos(a), inner_r * sin(a)] ],
+             [ [handle_inner_width, -inner_r] ]
+         );
+     // 外周も同様にオフセット
+     handle_outer_profile = 
+         concat(
+             [ [0, -outer_r], [0, outer_r] ],
+             [ for (a = [90 : -1 : -90]) 
+                   [handle_inner_width/2 + outer_r * cos(a), outer_r * sin(a)] ],
+             [ [handle_inner_width, -outer_r] ]
+         );
+     // 2Dハンドル断面
+     polygon(
+         concat(
+             handle_outer_profile,
+             [for (i = [len(handle_profile)-1 : -1 : 0]) handle_profile[i]] // 内周を逆順で結ぶ
+         )
+     );
  }
  
+ // 実体化
  union() {
      mug_body();
-     // 取手を-90度回転して+X側に設置し、太さ分拡げる
-     rotate([0,0,0])
-         d_handle();
+ 
+     // 取手: X軸方向に平行で、マグ高さ中央に配置
+     translate([mug_radius, 0, handle_center_z])  // 本体外周に密着
+         rotate([90,0,0])  // 平面をY-Zに(マグ円筒に垂直に)
+         linear_extrude(height=handle_inner_width, center=true)
+             handle_D();
  }
SCAD (67 lines)
// マグ本体パラメータ
mug_outer_diameter = 80;    // mm
mug_inner_diameter = 70;    // mm
mug_height = 90;            // mm
mug_wall_thickness = 5;     // mm
mug_bottom_thickness = 6;   // mm

// 取手パラメータ
handle_inner_height = 30;    // mm
handle_inner_width  = 25;    // mm
handle_thickness    = 12;    // mm  // 指が入りつつ頑丈さ優先

mug_radius = mug_outer_diameter / 2;
mug_inner_radius = mug_inner_diameter / 2;

// 取手スケッチ中心位置
handle_center_z = mug_height/2;

module mug_body() {
    difference() {
        cylinder(h = mug_height, r = mug_radius, $fn = 128);
        translate([0, 0, mug_bottom_thickness])
            cylinder(h = mug_height - mug_bottom_thickness, r = mug_inner_radius, $fn = 128);
    }
}

module handle_D() {
    // D字断面の外周
    inner_r = handle_inner_height/2;  // D字の半円内半径
    outer_r = inner_r + handle_thickness;

    // D字2Dプロファイル
    //   左辺(本体接触)が直線、右辺が半円
    handle_profile = 
        concat( // 下から上への直線
            [ [0, -inner_r], [0, inner_r] ],
            [ for (a = [90 : -1 : -90])
                [handle_inner_width/2 + inner_r * cos(a), inner_r * sin(a)] ],
            [ [handle_inner_width, -inner_r] ]
        );
    // 外周も同様にオフセット
    handle_outer_profile = 
        concat(
            [ [0, -outer_r], [0, outer_r] ],
            [ for (a = [90 : -1 : -90]) 
                  [handle_inner_width/2 + outer_r * cos(a), outer_r * sin(a)] ],
            [ [handle_inner_width, -outer_r] ]
        );
    // 2Dハンドル断面
    polygon(
        concat(
            handle_outer_profile,
            [for (i = [len(handle_profile)-1 : -1 : 0]) handle_profile[i]] // 内周を逆順で結ぶ
        )
    );
}

// 実体化
union() {
    mug_body();

    // 取手: X軸方向に平行で、マグ高さ中央に配置
    translate([mug_radius, 0, handle_center_z])  // 本体外周に密着
        rotate([90,0,0])  // 平面をY-Zに(マグ円筒に垂直に)
        linear_extrude(height=handle_inner_width, center=true)
            handle_D();
}