vibe-openscad

tier-2-offset-handle-mug / gemini-2.5-pro

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

gemini pro 2.5 bare

bare (provider default effort)

run detail →
render
bare render of tier-2-offset-handle-mug
loading STL…
success 85.7s · 232/720t · $0.0075
SCAD (57 lines)
$fn = 100; // 滑らかな曲線にするための解像度

// --- 本体パラメータ ---
mug_outer_d = 80;
mug_inner_d = 70;
mug_h = 90;
mug_bottom_thickness = 6;

// --- 取手パラメータ ---
handle_inner_h = 30;        // 指を入れる空間の高さ
handle_inner_w = 25;        // 指を入れる空間の幅 (本体からの距離)
handle_thickness = 8;       // 取手の肉厚
handle_y_width = 12;        // 取手の奥行き (Y軸方向の太さ)

// 本体と取手を結合
union() {
    // 1. マグ本体
    difference() {
        // 外側の円筒
        cylinder(h = mug_h, d = mug_outer_d);
        
        // 内側をくり抜くための円筒
        // 底面の厚みを残すために Z 方向にずらす
        translate([0, 0, mug_bottom_thickness])
            cylinder(h = mug_h + 1, d = mug_inner_d); // 確実に貫通させるため少し高くする
    }

    // 2. 取手
    // D字形状を CSG (Constructive Solid Geometry) で作成
    // - hull() を使って、本体側の平面部と外側の円筒部を滑らかに繋ぐ
    // - difference() で指を入れる穴を空ける
    
    // 取手全体の高さを計算
    handle_total_h = handle_inner_h + 2 * handle_thickness;
    // 取手をマグカップの高さ方向中央に配置するためのZ座標を計算
    handle_z_pos = (mug_h - handle_total_h) / 2;

    difference() {
        // D字の外形 (ソリッド)
        hull() {
            // 本体との接続部分 (平らな面を作るための薄い直方体)
            // 確実に結合させるために1mmめり込ませる
            translate([mug_outer_d/2 - 1, -handle_y_width/2, handle_z_pos])
                cube([1, handle_y_width, handle_total_h]);

            // D字のカーブ部分 (円筒)
            translate([mug_outer_d/2 + handle_inner_w, 0, handle_z_pos + handle_total_h/2])
                rotate([0, 90, 0])
                    cylinder(h = handle_y_width, r = handle_total_h/2, center = true);
        }
        
        // くり抜く内側の穴 (直方体)
        // 確実に貫通させるため、各軸で少しだけ大きくする
        translate([mug_outer_d/2, -handle_y_width, handle_z_pos + handle_thickness])
            cube([handle_inner_w + handle_thickness + 1, handle_y_width * 2, handle_inner_h]);
    }
}
パラメータ (8)
スライダを動かすと openscad-wasm で再レンダリング

prompt

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

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

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

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

variant: thinking

offnot run
adaptivenot run
dynamic (default) success
dynamic
85.7s · 232/720t · $0.0075
SCAD (57 lines)
$fn = 100; // 滑らかな曲線にするための解像度

// --- 本体パラメータ ---
mug_outer_d = 80;
mug_inner_d = 70;
mug_h = 90;
mug_bottom_thickness = 6;

// --- 取手パラメータ ---
handle_inner_h = 30;        // 指を入れる空間の高さ
handle_inner_w = 25;        // 指を入れる空間の幅 (本体からの距離)
handle_thickness = 8;       // 取手の肉厚
handle_y_width = 12;        // 取手の奥行き (Y軸方向の太さ)

// 本体と取手を結合
union() {
    // 1. マグ本体
    difference() {
        // 外側の円筒
        cylinder(h = mug_h, d = mug_outer_d);
        
        // 内側をくり抜くための円筒
        // 底面の厚みを残すために Z 方向にずらす
        translate([0, 0, mug_bottom_thickness])
            cylinder(h = mug_h + 1, d = mug_inner_d); // 確実に貫通させるため少し高くする
    }

    // 2. 取手
    // D字形状を CSG (Constructive Solid Geometry) で作成
    // - hull() を使って、本体側の平面部と外側の円筒部を滑らかに繋ぐ
    // - difference() で指を入れる穴を空ける
    
    // 取手全体の高さを計算
    handle_total_h = handle_inner_h + 2 * handle_thickness;
    // 取手をマグカップの高さ方向中央に配置するためのZ座標を計算
    handle_z_pos = (mug_h - handle_total_h) / 2;

    difference() {
        // D字の外形 (ソリッド)
        hull() {
            // 本体との接続部分 (平らな面を作るための薄い直方体)
            // 確実に結合させるために1mmめり込ませる
            translate([mug_outer_d/2 - 1, -handle_y_width/2, handle_z_pos])
                cube([1, handle_y_width, handle_total_h]);

            // D字のカーブ部分 (円筒)
            translate([mug_outer_d/2 + handle_inner_w, 0, handle_z_pos + handle_total_h/2])
                rotate([0, 90, 0])
                    cylinder(h = handle_y_width, r = handle_total_h/2, center = true);
        }
        
        // くり抜く内側の穴 (直方体)
        // 確実に貫通させるため、各軸で少しだけ大きくする
        translate([mug_outer_d/2, -handle_y_width, handle_z_pos + handle_thickness])
            cube([handle_inner_w + handle_thickness + 1, handle_y_width * 2, handle_inner_h]);
    }
}

iteration: iter-png

i1 success
iter 1
54.2s · 1278/1050t · $0.0121
diff vs bare: +20/-11
  $fn = 100; // 滑らかな曲線にするための解像度
  
  // --- 本体パラメータ ---
  mug_outer_d = 80;
  mug_inner_d = 70;
  mug_h = 90;
  mug_bottom_thickness = 6;
  
  // --- 取手パラメータ ---
  handle_inner_h = 30;        // 指を入れる空間の高さ
  handle_inner_w = 25;        // 指を入れる空間の幅 (本体からの距離)
  handle_thickness = 8;       // 取手の肉厚
  handle_y_width = 12;        // 取手の奥行き (Y軸方向の太さ)
  
  // 本体と取手を結合
  union() {
      // 1. マグ本体
      difference() {
          // 外側の円筒
          cylinder(h = mug_h, d = mug_outer_d);
          
          // 内側をくり抜くための円筒
          // 底面の厚みを残すために Z 方向にずらす
          translate([0, 0, mug_bottom_thickness])
              cylinder(h = mug_h + 1, d = mug_inner_d); // 確実に貫通させるため少し高くする
      }
  
      // 2. 取手
-     // D字形状を CSG (Constructive Solid Geometry) で作成
-     // - hull() を使って、本体側の平面部と外側の円筒部を滑らかに繋ぐ
-     // - difference() で指を入れる穴を空ける
-     
      // 取手全体の高さを計算
      handle_total_h = handle_inner_h + 2 * handle_thickness;
      // 取手をマグカップの高さ方向中央に配置するためのZ座標を計算
      handle_z_pos = (mug_h - handle_total_h) / 2;
  
+     // difference() を使って、ソリッドのD字形状から内側の穴をくり抜く
      difference() {
-         // D字の外形 (ソリッド)
+         // 外側のD字形状 (ソリッド)
+         // 本体側面の薄い板と、外側の円筒を hull() で滑らかに繋いで作成
          hull() {
-             // 本体との接続部分 (平らな面を作るための薄い直方体)
-             // 確実に結合させるために1mmめり込ませる
+             // 本体との接続部分 (アンカーとなる薄い直方体)
+             // 確実に結合させるためにX方向に1mmめり込ませる
              translate([mug_outer_d/2 - 1, -handle_y_width/2, handle_z_pos])
                  cube([1, handle_y_width, handle_total_h]);
  
              // D字のカーブ部分 (円筒)
+             // 中心を handle_inner_w だけ離れた位置に置くことで、内側の空間幅を確保
              translate([mug_outer_d/2 + handle_inner_w, 0, handle_z_pos + handle_total_h/2])
                  rotate([0, 90, 0])
                      cylinder(h = handle_y_width, r = handle_total_h/2, center = true);
          }
          
-         // くり抜く内側の穴 (直方体)
-         // 確実に貫通させるため、各軸で少しだけ大きくする
-         translate([mug_outer_d/2, -handle_y_width, handle_z_pos + handle_thickness])
-             cube([handle_inner_w + handle_thickness + 1, handle_y_width * 2, handle_inner_h]);
+         // 【修正点】くり抜く内側の穴もD字形状にする
+         // 直方体と円筒を union して作成
+         union() {
+             // 指が入る主要な空間 (直方体)
+             // マグ本体に少しめり込ませ、Y方向に少し大きくして確実に貫通させる
+             translate([mug_outer_d/2 - 1, -handle_y_width/2 - 1, handle_z_pos + handle_thickness])
+                 cube([handle_inner_w + 1, handle_y_width + 2, handle_inner_h]);
+ 
+             // 指先のカーブに合わせた空間 (円筒)
+             // Y軸方向に少し大きくして確実に貫通させる
+             translate([mug_outer_d/2 + handle_inner_w, 0, handle_z_pos + handle_thickness + handle_inner_h/2])
+                 rotate([0, 90, 0])
+                     cylinder(h = handle_y_width + 2, r = handle_inner_h/2, center = true);
+         }
      }
  }
SCAD (66 lines)
$fn = 100; // 滑らかな曲線にするための解像度

// --- 本体パラメータ ---
mug_outer_d = 80;
mug_inner_d = 70;
mug_h = 90;
mug_bottom_thickness = 6;

// --- 取手パラメータ ---
handle_inner_h = 30;        // 指を入れる空間の高さ
handle_inner_w = 25;        // 指を入れる空間の幅 (本体からの距離)
handle_thickness = 8;       // 取手の肉厚
handle_y_width = 12;        // 取手の奥行き (Y軸方向の太さ)

// 本体と取手を結合
union() {
    // 1. マグ本体
    difference() {
        // 外側の円筒
        cylinder(h = mug_h, d = mug_outer_d);
        
        // 内側をくり抜くための円筒
        // 底面の厚みを残すために Z 方向にずらす
        translate([0, 0, mug_bottom_thickness])
            cylinder(h = mug_h + 1, d = mug_inner_d); // 確実に貫通させるため少し高くする
    }

    // 2. 取手
    // 取手全体の高さを計算
    handle_total_h = handle_inner_h + 2 * handle_thickness;
    // 取手をマグカップの高さ方向中央に配置するためのZ座標を計算
    handle_z_pos = (mug_h - handle_total_h) / 2;

    // difference() を使って、ソリッドのD字形状から内側の穴をくり抜く
    difference() {
        // 外側のD字形状 (ソリッド)
        // 本体側面の薄い板と、外側の円筒を hull() で滑らかに繋いで作成
        hull() {
            // 本体との接続部分 (アンカーとなる薄い直方体)
            // 確実に結合させるためにX方向に1mmめり込ませる
            translate([mug_outer_d/2 - 1, -handle_y_width/2, handle_z_pos])
                cube([1, handle_y_width, handle_total_h]);

            // D字のカーブ部分 (円筒)
            // 中心を handle_inner_w だけ離れた位置に置くことで、内側の空間幅を確保
            translate([mug_outer_d/2 + handle_inner_w, 0, handle_z_pos + handle_total_h/2])
                rotate([0, 90, 0])
                    cylinder(h = handle_y_width, r = handle_total_h/2, center = true);
        }
        
        // 【修正点】くり抜く内側の穴もD字形状にする
        // 直方体と円筒を union して作成
        union() {
            // 指が入る主要な空間 (直方体)
            // マグ本体に少しめり込ませ、Y方向に少し大きくして確実に貫通させる
            translate([mug_outer_d/2 - 1, -handle_y_width/2 - 1, handle_z_pos + handle_thickness])
                cube([handle_inner_w + 1, handle_y_width + 2, handle_inner_h]);

            // 指先のカーブに合わせた空間 (円筒)
            // Y軸方向に少し大きくして確実に貫通させる
            translate([mug_outer_d/2 + handle_inner_w, 0, handle_z_pos + handle_thickness + handle_inner_h/2])
                rotate([0, 90, 0])
                    cylinder(h = handle_y_width + 2, r = handle_inner_h/2, center = true);
        }
    }
}
i2 success
iter 2
48.5s · 1449/822t · $0.0100
diff vs i1: +34/-32
  $fn = 100; // 滑らかな曲線にするための解像度
  
  // --- 本体パラメータ ---
  mug_outer_d = 80;
  mug_inner_d = 70;
  mug_h = 90;
  mug_bottom_thickness = 6;
  
  // --- 取手パラメータ ---
  handle_inner_h = 30;        // 指を入れる空間の高さ
  handle_inner_w = 25;        // 指を入れる空間の幅 (本体からの距離)
  handle_thickness = 8;       // 取手の肉厚
  handle_y_width = 12;        // 取手の奥行き (Y軸方向の太さ)
  
  // 本体と取手を結合
  union() {
      // 1. マグ本体
      difference() {
          // 外側の円筒
          cylinder(h = mug_h, d = mug_outer_d);
          
          // 内側をくり抜くための円筒
          // 底面の厚みを残すために Z 方向にずらす
          translate([0, 0, mug_bottom_thickness])
              cylinder(h = mug_h + 1, d = mug_inner_d); // 確実に貫通させるため少し高くする
      }
  
      // 2. 取手
      // 取手全体の高さを計算
-     handle_total_h = handle_inner_h + 2 * handle_thickness;
+     handle_outer_h = handle_inner_h + 2 * handle_thickness;
      // 取手をマグカップの高さ方向中央に配置するためのZ座標を計算
-     handle_z_pos = (mug_h - handle_total_h) / 2;
+     handle_z_pos = (mug_h - handle_outer_h) / 2;
  
-     // difference() を使って、ソリッドのD字形状から内側の穴をくり抜く
-     difference() {
-         // 外側のD字形状 (ソリッド)
-         // 本体側面の薄い板と、外側の円筒を hull() で滑らかに繋いで作成
-         hull() {
-             // 本体との接続部分 (アンカーとなる薄い直方体)
-             // 確実に結合させるためにX方向に1mmめり込ませる
-             translate([mug_outer_d/2 - 1, -handle_y_width/2, handle_z_pos])
-                 cube([1, handle_y_width, handle_total_h]);
- 
-             // D字のカーブ部分 (円筒)
-             // 中心を handle_inner_w だけ離れた位置に置くことで、内側の空間幅を確保
-             translate([mug_outer_d/2 + handle_inner_w, 0, handle_z_pos + handle_total_h/2])
-                 rotate([0, 90, 0])
-                     cylinder(h = handle_y_width, r = handle_total_h/2, center = true);
+     // 取手を+X軸方向に配置
+     // 本体に少しめり込ませて確実に接続する
+     translate([mug_outer_d/2 - 1, 0, handle_z_pos]) {
+         // difference() を使って、ソリッドのD字形状から内側の穴をくり抜く
+         difference() {
+             // --- 外側のソリッドD字形状 ---
+             // hull() を使い、直線部(cube)と曲線部(cylinder)を滑らかに繋ぐ
+             hull() {
+                 // 本体との接続部 (D字の直線部分)
+                 translate([0, -handle_y_width/2, 0])
+                     cube([handle_thickness, handle_y_width, handle_outer_h]);
+                 
+                 // D字のカーブ部分
+                 // 円筒の中心を、指を入れる空間のさらに奥に配置
+                 translate([handle_thickness + handle_inner_w, 0, handle_outer_h / 2])
+                     rotate([0, 90, 0])
+                         cylinder(h = handle_y_width, r = handle_outer_h / 2, center = true);
+             }
+             
+             // --- 内側のくり抜き穴 ---
+             // 確実に貫通させるためにX,Y方向に少し大きくする
+             translate([-2, -handle_y_width/2 - 1, handle_thickness]) {
+                  // くり抜く形状もhullで作成し、内側の角を滑らかにする
+                  hull() {
+                     // 直線部分の穴
+                     cube([handle_inner_w, handle_y_width + 2, handle_inner_h]);
+                     
+                     // 曲線部分の穴
+                     translate([handle_inner_w, 0, handle_inner_h / 2])
+                         cylinder(h = handle_y_width + 2, r = handle_inner_h / 2, center=true);
+                  }
+             }
          }
-         
-         // 【修正点】くり抜く内側の穴もD字形状にする
-         // 直方体と円筒を union して作成
-         union() {
-             // 指が入る主要な空間 (直方体)
-             // マグ本体に少しめり込ませ、Y方向に少し大きくして確実に貫通させる
-             translate([mug_outer_d/2 - 1, -handle_y_width/2 - 1, handle_z_pos + handle_thickness])
-                 cube([handle_inner_w + 1, handle_y_width + 2, handle_inner_h]);
- 
-             // 指先のカーブに合わせた空間 (円筒)
-             // Y軸方向に少し大きくして確実に貫通させる
-             translate([mug_outer_d/2 + handle_inner_w, 0, handle_z_pos + handle_thickness + handle_inner_h/2])
-                 rotate([0, 90, 0])
-                     cylinder(h = handle_y_width + 2, r = handle_inner_h/2, center = true);
-         }
      }
  }
SCAD (68 lines)
$fn = 100; // 滑らかな曲線にするための解像度

// --- 本体パラメータ ---
mug_outer_d = 80;
mug_inner_d = 70;
mug_h = 90;
mug_bottom_thickness = 6;

// --- 取手パラメータ ---
handle_inner_h = 30;        // 指を入れる空間の高さ
handle_inner_w = 25;        // 指を入れる空間の幅 (本体からの距離)
handle_thickness = 8;       // 取手の肉厚
handle_y_width = 12;        // 取手の奥行き (Y軸方向の太さ)

// 本体と取手を結合
union() {
    // 1. マグ本体
    difference() {
        // 外側の円筒
        cylinder(h = mug_h, d = mug_outer_d);
        
        // 内側をくり抜くための円筒
        // 底面の厚みを残すために Z 方向にずらす
        translate([0, 0, mug_bottom_thickness])
            cylinder(h = mug_h + 1, d = mug_inner_d); // 確実に貫通させるため少し高くする
    }

    // 2. 取手
    // 取手全体の高さを計算
    handle_outer_h = handle_inner_h + 2 * handle_thickness;
    // 取手をマグカップの高さ方向中央に配置するためのZ座標を計算
    handle_z_pos = (mug_h - handle_outer_h) / 2;

    // 取手を+X軸方向に配置
    // 本体に少しめり込ませて確実に接続する
    translate([mug_outer_d/2 - 1, 0, handle_z_pos]) {
        // difference() を使って、ソリッドのD字形状から内側の穴をくり抜く
        difference() {
            // --- 外側のソリッドD字形状 ---
            // hull() を使い、直線部(cube)と曲線部(cylinder)を滑らかに繋ぐ
            hull() {
                // 本体との接続部 (D字の直線部分)
                translate([0, -handle_y_width/2, 0])
                    cube([handle_thickness, handle_y_width, handle_outer_h]);
                
                // D字のカーブ部分
                // 円筒の中心を、指を入れる空間のさらに奥に配置
                translate([handle_thickness + handle_inner_w, 0, handle_outer_h / 2])
                    rotate([0, 90, 0])
                        cylinder(h = handle_y_width, r = handle_outer_h / 2, center = true);
            }
            
            // --- 内側のくり抜き穴 ---
            // 確実に貫通させるためにX,Y方向に少し大きくする
            translate([-2, -handle_y_width/2 - 1, handle_thickness]) {
                 // くり抜く形状もhullで作成し、内側の角を滑らかにする
                 hull() {
                    // 直線部分の穴
                    cube([handle_inner_w, handle_y_width + 2, handle_inner_h]);
                    
                    // 曲線部分の穴
                    translate([handle_inner_w, 0, handle_inner_h / 2])
                        cylinder(h = handle_y_width + 2, r = handle_inner_h / 2, center=true);
                 }
            }
        }
    }
}
i3 success
iter 3
66.1s · 1380/885t · $0.0106
diff vs i2: +44/-35
  $fn = 100; // 滑らかな曲線にするための解像度
  
  // --- 本体パラメータ ---
  mug_outer_d = 80;
  mug_inner_d = 70;
  mug_h = 90;
  mug_bottom_thickness = 6;
  
  // --- 取手パラメータ ---
- handle_inner_h = 30;        // 指を入れる空間の高さ
- handle_inner_w = 25;        // 指を入れる空間の幅 (本体からの距離)
- handle_thickness = 8;       // 取手の肉厚
+ handle_inner_h = 30;        // 指を入れる空間の高さ (Z軸方向)
+ handle_inner_w = 25;        // 指を入れる空間の幅 (X軸方向、本体からの距離)
+ handle_thickness = 8;       // 取手の肉厚 (XZ平面上)
  handle_y_width = 12;        // 取手の奥行き (Y軸方向の太さ)
  
  // 本体と取手を結合
  union() {
      // 1. マグ本体
      difference() {
          // 外側の円筒
          cylinder(h = mug_h, d = mug_outer_d);
          
          // 内側をくり抜くための円筒
          // 底面の厚みを残すために Z 方向にずらす
          translate([0, 0, mug_bottom_thickness])
              cylinder(h = mug_h + 1, d = mug_inner_d); // 確実に貫通させるため少し高くする
      }
  
      // 2. 取手
-     // 取手全体の高さを計算
+     // 2DのD形状を押し出す方式で作成。これにより、画像のようなテーパー形状を修正します。
+     
+     // --- 取手寸法の計算 ---
+     // 内側D形状の寸法
+     handle_inner_radius = handle_inner_h / 2;
+     handle_inner_rect_w = handle_inner_w - handle_inner_radius;
+     
+     // 外側D形状の寸法
      handle_outer_h = handle_inner_h + 2 * handle_thickness;
-     // 取手をマグカップの高さ方向中央に配置するためのZ座標を計算
+     handle_outer_radius = handle_outer_h / 2;
+     handle_outer_rect_w = handle_inner_rect_w + handle_thickness;
+ 
+     // --- 取手の配置 ---
+     // Z方向:マグカップの高さ方向中央に配置
      handle_z_pos = (mug_h - handle_outer_h) / 2;
+     // X方向:+X軸側面に配置し、確実に接続するために1mmめり込ませる
+     handle_x_pos = mug_outer_d / 2 - 1;
  
-     // 取手を+X軸方向に配置
-     // 本体に少しめり込ませて確実に接続する
-     translate([mug_outer_d/2 - 1, 0, handle_z_pos]) {
-         // difference() を使って、ソリッドのD字形状から内側の穴をくり抜く
-         difference() {
-             // --- 外側のソリッドD字形状 ---
-             // hull() を使い、直線部(cube)と曲線部(cylinder)を滑らかに繋ぐ
-             hull() {
-                 // 本体との接続部 (D字の直線部分)
-                 translate([0, -handle_y_width/2, 0])
-                     cube([handle_thickness, handle_y_width, handle_outer_h]);
-                 
-                 // D字のカーブ部分
-                 // 円筒の中心を、指を入れる空間のさらに奥に配置
-                 translate([handle_thickness + handle_inner_w, 0, handle_outer_h / 2])
-                     rotate([0, 90, 0])
-                         cylinder(h = handle_y_width, r = handle_outer_h / 2, center = true);
-             }
-             
-             // --- 内側のくり抜き穴 ---
-             // 確実に貫通させるためにX,Y方向に少し大きくする
-             translate([-2, -handle_y_width/2 - 1, handle_thickness]) {
-                  // くり抜く形状もhullで作成し、内側の角を滑らかにする
-                  hull() {
-                     // 直線部分の穴
-                     cube([handle_inner_w, handle_y_width + 2, handle_inner_h]);
+     translate([handle_x_pos, 0, handle_z_pos]) {
+         // 取手のD形状はXZ平面上にあるため、XY平面で2D形状を作成し90度回転させる
+         rotate([90, 0, 0]) {
+             // Y軸方向に押し出して厚みを付ける
+             linear_extrude(height = handle_y_width, center = true) {
+                 difference() {
+                     // --- 外側のソリッドD形状 ---
+                     union() {
+                         // Dの直線部分 (2DのXY平面上で、Xが幅、Yが高さに対応)
+                         square([handle_outer_rect_w, handle_outer_h]);
+                         // Dの曲線部分
+                         translate([handle_outer_rect_w, handle_outer_radius, 0])
+                             circle(r = handle_outer_radius);
+                     }
                      
-                     // 曲線部分の穴
-                     translate([handle_inner_w, 0, handle_inner_h / 2])
-                         cylinder(h = handle_y_width + 2, r = handle_inner_h / 2, center=true);
-                  }
+                     // --- 内側のくり抜きD形状 ---
+                     // 外側の形状からのオフセットとして配置
+                     translate([handle_thickness, handle_thickness, 0]) {
+                         union() {
+                             // Dの直線部分
+                             square([handle_inner_rect_w, handle_inner_h]);
+                             // Dの曲線部分
+                             translate([handle_inner_rect_w, handle_inner_radius, 0])
+                                 circle(r = handle_inner_radius);
+                         }
+                     }
+                 }
              }
          }
      }
  }
SCAD (77 lines)
$fn = 100; // 滑らかな曲線にするための解像度

// --- 本体パラメータ ---
mug_outer_d = 80;
mug_inner_d = 70;
mug_h = 90;
mug_bottom_thickness = 6;

// --- 取手パラメータ ---
handle_inner_h = 30;        // 指を入れる空間の高さ (Z軸方向)
handle_inner_w = 25;        // 指を入れる空間の幅 (X軸方向、本体からの距離)
handle_thickness = 8;       // 取手の肉厚 (XZ平面上)
handle_y_width = 12;        // 取手の奥行き (Y軸方向の太さ)

// 本体と取手を結合
union() {
    // 1. マグ本体
    difference() {
        // 外側の円筒
        cylinder(h = mug_h, d = mug_outer_d);
        
        // 内側をくり抜くための円筒
        // 底面の厚みを残すために Z 方向にずらす
        translate([0, 0, mug_bottom_thickness])
            cylinder(h = mug_h + 1, d = mug_inner_d); // 確実に貫通させるため少し高くする
    }

    // 2. 取手
    // 2DのD形状を押し出す方式で作成。これにより、画像のようなテーパー形状を修正します。
    
    // --- 取手寸法の計算 ---
    // 内側D形状の寸法
    handle_inner_radius = handle_inner_h / 2;
    handle_inner_rect_w = handle_inner_w - handle_inner_radius;
    
    // 外側D形状の寸法
    handle_outer_h = handle_inner_h + 2 * handle_thickness;
    handle_outer_radius = handle_outer_h / 2;
    handle_outer_rect_w = handle_inner_rect_w + handle_thickness;

    // --- 取手の配置 ---
    // Z方向:マグカップの高さ方向中央に配置
    handle_z_pos = (mug_h - handle_outer_h) / 2;
    // X方向:+X軸側面に配置し、確実に接続するために1mmめり込ませる
    handle_x_pos = mug_outer_d / 2 - 1;

    translate([handle_x_pos, 0, handle_z_pos]) {
        // 取手のD形状はXZ平面上にあるため、XY平面で2D形状を作成し90度回転させる
        rotate([90, 0, 0]) {
            // Y軸方向に押し出して厚みを付ける
            linear_extrude(height = handle_y_width, center = true) {
                difference() {
                    // --- 外側のソリッドD形状 ---
                    union() {
                        // Dの直線部分 (2DのXY平面上で、Xが幅、Yが高さに対応)
                        square([handle_outer_rect_w, handle_outer_h]);
                        // Dの曲線部分
                        translate([handle_outer_rect_w, handle_outer_radius, 0])
                            circle(r = handle_outer_radius);
                    }
                    
                    // --- 内側のくり抜きD形状 ---
                    // 外側の形状からのオフセットとして配置
                    translate([handle_thickness, handle_thickness, 0]) {
                        union() {
                            // Dの直線部分
                            square([handle_inner_rect_w, handle_inner_h]);
                            // Dの曲線部分
                            translate([handle_inner_rect_w, handle_inner_radius, 0])
                                circle(r = handle_inner_radius);
                        }
                    }
                }
            }
        }
    }
}