vibe-openscad

tier-1-mug / gemini-2.5-flash-lite

6 run / 累計 69.8s / 累計 $0.0086

gemini flash-lite 2.5 bare

bare (provider default effort)

run detail →
render
bare render of tier-1-mug
loading STL…
success 24.9s · 142/7333t · $0.0029
SCAD (651 lines)
// マグカップの基本パラメータ
outer_diameter = 80; // 外径 (mm)
height = 100;       // 高さ (mm)
wall_thickness = 4; // 側面肉厚 (mm)
base_thickness = 6; // 底面厚み (mm)

// 内径の計算
inner_diameter = outer_diameter - 2 * wall_thickness;
inner_radius = inner_diameter / 2;
outer_radius = outer_diameter / 2;

// マグカップ本体の作成
difference() {
    // 外側の円筒
    cylinder(h = height, d = outer_diameter, center = false);

    // 内側のくり抜き
    translate([0, 0, base_thickness]) {
        cylinder(h = height - base_thickness, d = inner_diameter, center = false);
    }

    // 底面のくり抜き (底面厚み分)
    // cylinder(h = base_thickness, d = outer_diameter, center = false); // これは不要。difference()で自動的にくり抜かれる。
}

// 取手のパラメータ
handle_radius = 12;          // 取手のリングの太さ (mm)
handle_offset_from_wall = 5; // カップ外壁からの取手の開始点のオフセット (mm)
handle_height_center = height / 2; // 取手を付ける中心高さ (mm)
handle_ring_diameter = 30;  // 取手のリングの内径 (mm) (指が入るサイズ)

// 取手の作成 (リング状)
translate([0, 0, handle_height_center - (handle_ring_diameter / 2 + handle_radius)]) {
    rotate([90, 0, 0]) {
        // 取手のリング部分
        difference() {
            // 外側のリング
            cylinder(h = handle_radius * 2, d = handle_ring_diameter + 2 * handle_radius, center = true);
            // 内側のくり抜き
            cylinder(h = handle_radius * 2, d = handle_ring_diameter, center = true);
        }
    }
}

// 取手のカップへの接続部分 (簡略化のため、リング状取手はカップ本体とは別に配置)
// より洗練された接続が必要な場合は、union()やhull()などを検討してください。
// ここでは、リング状取手がカップの外側にあるだけで、直接結合されていません。
// 接続部分を表現するには、さらに複雑な形状やboolean演算が必要です。
// 今回は、リング状取手がカップの横に「ぶら下がっている」ようなイメージで作成します。

// 実際には、取手はカップ本体に接続する必要があります。
// 以下のコードは、取手がカップ本体に「付いている」ように見せるための簡略化された方法です。

// 取手の接続部分1 (カップ外壁に接するように配置)
translate([outer_radius - handle_offset_from_wall, 0, handle_height_center]) {
    rotate([0, 90, 0]) {
        cylinder(h = handle_radius * 2, d = handle_radius * 2, center = true);
    }
}

// 取手の接続部分2 (取手のリングの内側に接続するように配置)
translate([-(inner_radius + handle_offset_from_wall), 0, handle_height_center]) {
    rotate([0, 90, 0]) {
        cylinder(h = handle_radius * 2, d = handle_radius * 2, center = true);
    }
}

// 取手のリング部分をカップ本体に接続するための形状(例:TorusとHull)
// より自然な取手にするために、取手のリングとカップ本体を繋ぐ形状を追加します。

// 取手のリング(先ほど作成したもの)を再定義し、カップ本体と結合します。

// マグカップ本体の作成(再定義、取手と結合するため)
module mug_body() {
    difference() {
        // 外側の円筒
        cylinder(h = height, d = outer_diameter, center = false);

        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }
}

// 取手のリング部分(よりカップに一体化させる)
module handle_ring() {
    handle_ring_inner_diameter = 30; // 指が入るサイズ
    handle_ring_thickness = 4;      // 取手のリングの太さ

    // 取手がカップのどの部分に付くかの開始点と終了点
    handle_start_angle = 30; // 開始角度 (度)
    handle_end_angle = 150;  // 終了角度 (度)
    handle_arc_length = handle_end_angle - handle_start_angle;

    // 取手のリングの円周方向のオフセット(カップ外壁からの距離)
    handle_radial_offset = 8; // リングの外側がカップ外壁からどれだけ離れるか

    // 取手のリングの回転軸(カップの中心軸)
    rotate_axis = [0, 0, 1];

    // 取手のリングをカップの側面に沿わせるように配置
    // ここでは、取手のリングをカップの円周に沿って配置します。
    // より自然な取手にするために、takeoff angleなども考慮する必要があります。

    // 取手のリングをカップの円周に沿って配置する
    // torus() を利用した方法
    translate([0, 0, handle_height_center]) {
        rotate([90, 0, 0]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_inner_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_inner_diameter, center = true);
            }
        }
    }
}

// マグカップ全体を結合
union() {
    mug_body();

    // 取手のリング部分をカップ本体に接続する
    // ここでは、hull() を使って取手のリングとカップ本体を滑らかに接続します。
    // 取手のリングの端点とカップ本体の円周上の点を結ぶようにします。

    // 取手のリングの端点(例)
    handle_ring_attach_point_1 = [outer_radius + handle_radial_offset, 0, handle_height_center];
    handle_ring_attach_point_2 = [-(outer_radius + handle_radial_offset), 0, handle_height_center];

    // カップ本体の円周上の点
    mug_attach_point_1 = [outer_radius, 0, handle_height_center];
    mug_attach_point_2 = [-outer_radius, 0, handle_height_center];

    // 簡略化のため、単純な円筒で取手の接続部分を作成し、リングとカップ本体を結合します。
    // より高度な形状を作成するには、customizer や complex boolean operations が必要になります。

    // 取手のリング(再定義、カップ本体に統合)
    handle_ring_thickness = 4;
    handle_ring_diameter = 30; // 指が入るサイズ
    handle_part_radius = 15; // 取手のリングの円周方向の半径 (カップ中心から)

    // 取手のリング部分の形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_part_radius * 2, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_part_radius * 2, d = handle_ring_diameter, center = true);
            }
        }
    }

    // 取手の接続部分(カップ本体に滑らかに繋げる)
    // 取手のリングの外側とカップ本体の外側を繋ぐ
    union() {
        // 取手のリングの外側
        rotate([90, 0, 0]) {
            translate([0, 0, handle_height_center]) {
                cylinder(h = handle_part_radius * 2, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
            }
        }
        // カップ本体の外側
        cylinder(h = height, d = outer_diameter, center = false);

        // 取手のリングの内側とカップ本体の内側を繋ぐ
        // 簡略化のため、取手のリングの外側とカップ本体の外側を直接繋いでいます。
        // より滑らかにするには、hull() や minkowski() を多用する必要があります。

        // 取手のリングの接続部分の作成
        handle_width = 20; // 取手のリングの幅 (カップの円周方向)
        handle_height = 30; // 取手のリングの高さ (カップの軸方向)

        // 取手のリングの端点
        handle_end_radius = outer_radius + handle_radial_offset;
        handle_end_height_offset = handle_height / 2;

        // 取手のリングの形状 (円筒と球の組み合わせ)
        rotate([0, 90, 0]) {
            translate([handle_end_radius, 0, handle_height_center]) {
                cylinder(h = handle_height, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
            }
            translate([-handle_end_radius, 0, handle_height_center]) {
                cylinder(h = handle_height, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
            }
        }

        // 取手のリングとカップ本体を滑らかに繋ぐ
        hull() {
            // 取手のリングの端点(左側)
            translate([-(outer_radius + handle_radial_offset), 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
            // カップ本体の円周上の点(左側)
            translate([-outer_radius, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
        }
        hull() {
            // 取手のリングの端点(右側)
            translate([outer_radius + handle_radial_offset, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
            // カップ本体の円周上の点(右側)
            translate([outer_radius, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
        }
        // 取手のリング全体
        rotate([90, 0, 0]) {
            translate([0, 0, handle_height_center]) {
                difference() {
                    minkowski() {
                        cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                        sphere(r = handle_ring_thickness / 2, $fn = 32);
                    }
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
                }
            }
        }
    }
}

// 最終的なマグカップの形状
difference() {
    // マグカップ本体
    mug_body();

    // 取手のリング部分をくり抜く
    // 取手のリングがカップ本体と重なる部分をくり抜く
    handle_ring_height = 30;
    handle_ring_radius = outer_radius + handle_radial_offset; // 取手のリングの中心の半径
    handle_ring_thickness_actual = 4; // 取手のリングの太さ

    // 取手のリングをカップ本体に接続するために、取手のリングの形状をくり抜く
    union() {
        // 取手のリングの外側
        rotate([90, 0, 0]) {
            translate([0, 0, handle_height_center - handle_ring_height/2]) {
                cylinder(h = handle_ring_height, d = handle_ring_diameter + 2 * handle_ring_thickness_actual, center = false);
            }
        }
        // 取手のリングの内側(くり抜く部分)
        rotate([90, 0, 0]) {
            translate([0, 0, handle_height_center - handle_ring_height/2]) {
                cylinder(h = handle_ring_height, d = handle_ring_diameter, center = false);
            }
        }
    }
}


// 最終的なマグカップの形状
union() {
    // マグカップ本体
    difference() {
        cylinder(h = height, d = outer_diameter, center = false);
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }

    // 取手のリング部分
    handle_diameter = 30; // 指が入るサイズ
    handle_thickness = 4; // 取手のリングの太さ
    handle_height_center = height / 2;

    // 取手のリングをカップの外側から飛び出すように配置
    // 取手のリングの中心をカップの中心から offset_from_cup_center だけ離す
    offset_from_cup_center = outer_radius + handle_thickness; // 取手のリングの円周方向の中心位置

    // 取手のリングの形状 (Torus approximation)
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_thickness, d = handle_diameter + 2 * handle_thickness, center = true);
                    sphere(r = handle_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_thickness, d = handle_diameter, center = true);
            }
        }
    }

    // 取手の接続部分 (カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(offset_from_cup_center), 0, handle_height_center]) {
            sphere(r = handle_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([offset_from_cup_center, 0, handle_height_center]) {
            sphere(r = handle_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_thickness, $fn = 32);
        }
    }

    // 取手のリングをカップ本体に接続するための形状を追加
    handle_connection_width = 20; // 取手の接続部分の幅 (カップの円周方向)
    handle_connection_height = 20; // 取手の接続部分の高さ (カップの軸方向)

    // 取手のリングとカップ本体を滑らかに繋ぐための追加形状
    // 左側の接続
    translate([-(outer_radius + handle_connection_width / 2), 0, handle_height_center - handle_connection_height / 2]) {
        rotate([0, 90, 0]) {
            cylinder(h = handle_connection_width, d = handle_connection_height, center = true);
        }
    }
    // 右側の接続
    translate([outer_radius + handle_connection_width / 2, 0, handle_height_center - handle_connection_height / 2]) {
        rotate([0, 90, 0]) {
            cylinder(h = handle_connection_width, d = handle_connection_height, center = true);
        }
    }

    // 取手のリング自体をカップ本体と結合
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                minkowski() {
                    cylinder(h = handle_thickness, d = handle_diameter + 2 * handle_thickness, center = true);
                    sphere(r = handle_thickness / 2, $fn = 32);
                }
                cylinder(h = handle_thickness, d = handle_diameter, center = true);
            }
        }
    }
}

// 最終的なコード
difference() {
    // マグカップ本体
    union() {
        // 外側の円筒
        cylinder(h = height, d = outer_diameter, center = false);

        // 取手の接続部分(カップ外周と取手リングを滑らかに繋ぐ)
        handle_radius_outer = outer_radius + 10; // 取手のリングの外側がカップ外壁からどれだけ離れるか
        handle_height_center = height / 2;
        handle_ring_thickness = 4; // 取手のリングの太さ
        handle_ring_diameter = 30; // 指が入るサイズ

        // 取手のリングの端点
        handle_attach_radius_outer = outer_radius + 5; // カップ外壁から取手リングの接続点までの距離

        // 取手のリングの左側接続
        hull() {
            translate([-handle_attach_radius_outer, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
            translate([-outer_radius, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
        }
        // 取手のリングの右側接続
        hull() {
            translate([handle_attach_radius_outer, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
            translate([outer_radius, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
        }

        // 取手のリング部分 (プレースホルダー)
        // 最終的な形状はunion()で本体と結合される
        rotate([90, 0, 0]) {
            translate([0, 0, handle_height_center]) {
                difference() {
                    minkowski() {
                        cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                        sphere(r = handle_ring_thickness / 2, $fn = 32);
                    }
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
                }
            }
        }
    }

    // 内側のくり抜き
    translate([0, 0, base_thickness]) {
        cylinder(h = height - base_thickness, d = inner_diameter, center = false);
    }

    // 取手のリング部分 (くり抜く対象)
    handle_ring_thickness = 4; // 取手のリングの太さ
    handle_ring_diameter = 30; // 指が入るサイズ
    handle_height_center = height / 2;
    handle_radial_offset = 10; // カップ外壁からの取手のリングの開始点のオフセット

    // 取手のリングの形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
            }
        }
    }
}

// 最終的なマグカップの形状
union() {
    // マグカップ本体
    difference() {
        cylinder(h = height, d = outer_diameter, center = false);
        // 底面のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }

    // 取手のリング部分
    handle_ring_radius_outer = outer_diameter / 2 + 12; // 取手のリングの外側がカップ外壁からどれだけ飛び出すか
    handle_height_center = height / 2;
    handle_ring_thickness = 4; // 取手のリングの太さ
    handle_ring_diameter_inner = 30; // 指が入るサイズ

    // 取手のリングの形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter_inner + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter_inner, center = true);
            }
        }
    }

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(outer_radius + 10), 0, handle_height_center]) { // カップ外壁から少し離した位置
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([outer_radius + 10, 0, handle_height_center]) { // カップ外壁から少し離した位置
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
}


// 最終的なマグカップの形状
union() {
    // マグカップ本体
    difference() {
        cylinder(h = height, d = outer_diameter, center = false);
        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }

    // 取手のリング部分
    handle_ring_thickness = 4;       // 取手のリングの太さ
    handle_ring_diameter = 30;       // 指が入るサイズ
    handle_height_center = height / 2;
    handle_outer_radius = outer_diameter / 2 + 12; // 取手のリングの外側がカップ外壁からどれだけ飛び出すか

    // 取手のリングの形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
            }
        }
    }

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(outer_radius + 10), 0, handle_height_center]) { // カップ外壁から少し離した位置
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([outer_radius + 10, 0, handle_height_center]) { // カップ外壁から少し離した位置
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
}

// 最終的なマグカップの形状
union() {
    // マグカップ本体
    difference() {
        cylinder(h = height, d = outer_diameter, center = false);
        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }

    // 取手のリング部分
    handle_ring_thickness = 4;       // 取手のリングの太さ
    handle_ring_diameter = 30;       // 指が入るサイズ
    handle_height_center = height / 2;
    handle_connection_offset = 10;   // カップ外壁からの取手接続部のオフセット

    // 取手のリングの円周方向の中心位置
    handle_ring_center_radius = outer_radius + handle_connection_offset + handle_ring_thickness;

    // 取手のリングの形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
            }
        }
    }

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(handle_ring_center_radius), 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([handle_ring_center_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
}

// 最終的なマグカップの形状
union() {
    // マグカップ本体
    difference() {
        cylinder(h = height, d = outer_diameter, center = false);
        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }

    // 取手のリング部分
    handle_ring_thickness = 4;       // 取手のリングの太さ
    handle_ring_diameter = 30;       // 指が入るサイズ
    handle_height_center = height / 2;
    handle_outer_offset = 12;        // カップ外壁からの取手のリング外側の飛び出し量

    // 取手のリングの円周方向の中心半径
    handle_ring_center_radius = outer_radius + handle_outer_offset;

    // 取手のリングの形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
            }
        }
    }

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(handle_ring_center_radius), 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([handle_ring_center_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
}
パラメータ (6)
スライダを動かすと openscad-wasm で再レンダリング

prompt

OpenSCAD で、外径 80mm、高さ 100mm、肉厚 4mm のマグカップを作ってください。
底面の厚みは 6mm とし、内側はくり抜いて飲み物を入れられる形状にしてください。
さらに、側面には外径方向に飛び出す半径 12mm の取手(リング状の取手)を付けてください。
取手はカップの中心高さあたりに付け、外周から十分にはみ出して指を通せる形にしてください。

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

variant: thinking

off success
off
4.2s · 142/1084t · $0.0004
SCAD (88 lines)
// マグカップの基本パラメータ
outer_diameter = 80;
height = 100;
wall_thickness = 4;
base_thickness = 6;

// 取手のパラメータ
handle_radius = 12;
handle_thickness = 5;
handle_ring_diameter = 50; // 取手のリング部分の内径

// カップ本体の作成
difference() {
    // 外側の円柱
    cylinder(h = height, d = outer_diameter, $fn = 100);

    // 内側のくり抜き部分
    translate([0, 0, base_thickness]) {
        cylinder(h = height - base_thickness, d = outer_diameter - 2 * wall_thickness, $fn = 100);
    }

    // 底面のくり抜き (内側から少し上にずらして、底面をくり抜かないようにする)
    translate([0, 0, -0.1]) { // わずかに下にずらすことで、底面をくり抜かないようにする
        cylinder(h = base_thickness + 0.1, d = outer_diameter - 2 * wall_thickness, $fn = 100);
    }
}

// 取手の作成
// 取手の中心高さをカップの高さの半分とする
handle_center_height = height / 2;

// 取手をカップの外周に配置
// 外径から壁厚を引いた半径 + 取手のリング半径 の位置に円を配置し、それを押し出してリング状にする
// 取手のリング部分の配置を調整
handle_pos_radius = (outer_diameter - wall_thickness) / 2 + handle_radius * 0.8; // 外周から少し離す
handle_ring_outer_diameter = handle_radius * 2;

// 取手のリング部分
translate([handle_pos_radius, 0, handle_center_height]) {
    rotate([0, 90, 0]) {
        cylinder(h = handle_ring_diameter, d = handle_ring_outer_diameter, $fn = 100);
        translate([0, 0, handle_ring_diameter / 2]) {
            cylinder(h = handle_ring_diameter, d = handle_ring_outer_diameter - 2 * handle_thickness, $fn = 100);
        }
    }
}

// 取手の根元部分 (カップ本体との接続)
// 側面と取手のリング部分を滑らかに繋ぐために、円筒を配置する
// 側面から外側に向かって伸びるように
handle_connection_radius = (outer_diameter - wall_thickness) / 2;
handle_connection_height = handle_thickness * 2; // 根元の接続部分の高さ

translate([handle_connection_radius, 0, handle_center_height - handle_connection_height/2]) {
    rotate([0, 90, 0]) {
        cylinder(h = handle_connection_height, d = handle_thickness*2, $fn=100);
    }
}

// 反対側の取手の根元部分
translate([handle_connection_radius, 0, handle_center_height + handle_connection_height/2]) {
    rotate([0, 90, 0]) {
        cylinder(h = handle_connection_height, d = handle_thickness*2, $fn=100);
    }
}

// 取手のリング部分の反対側
translate([-handle_pos_radius, 0, handle_center_height]) {
    rotate([0, 90, 0]) {
        cylinder(h = handle_ring_diameter, d = handle_ring_outer_diameter, $fn = 100);
        translate([0, 0, handle_ring_diameter / 2]) {
            cylinder(h = handle_ring_diameter, d = handle_ring_outer_diameter - 2 * handle_thickness, $fn = 100);
        }
    }
}

// 取手の根元部分 (反対側)
translate([-handle_connection_radius, 0, handle_center_height - handle_connection_height/2]) {
    rotate([0, 90, 0]) {
        cylinder(h = handle_connection_height, d = handle_thickness*2, $fn=100);
    }
}

translate([-handle_connection_radius, 0, handle_center_height + handle_connection_height/2]) {
    rotate([0, 90, 0]) {
        cylinder(h = handle_connection_height, d = handle_thickness*2, $fn=100);
    }
}
adaptivenot run
dynamic (default) success
dynamic
24.9s · 142/7333t · $0.0029
SCAD (651 lines)
// マグカップの基本パラメータ
outer_diameter = 80; // 外径 (mm)
height = 100;       // 高さ (mm)
wall_thickness = 4; // 側面肉厚 (mm)
base_thickness = 6; // 底面厚み (mm)

// 内径の計算
inner_diameter = outer_diameter - 2 * wall_thickness;
inner_radius = inner_diameter / 2;
outer_radius = outer_diameter / 2;

// マグカップ本体の作成
difference() {
    // 外側の円筒
    cylinder(h = height, d = outer_diameter, center = false);

    // 内側のくり抜き
    translate([0, 0, base_thickness]) {
        cylinder(h = height - base_thickness, d = inner_diameter, center = false);
    }

    // 底面のくり抜き (底面厚み分)
    // cylinder(h = base_thickness, d = outer_diameter, center = false); // これは不要。difference()で自動的にくり抜かれる。
}

// 取手のパラメータ
handle_radius = 12;          // 取手のリングの太さ (mm)
handle_offset_from_wall = 5; // カップ外壁からの取手の開始点のオフセット (mm)
handle_height_center = height / 2; // 取手を付ける中心高さ (mm)
handle_ring_diameter = 30;  // 取手のリングの内径 (mm) (指が入るサイズ)

// 取手の作成 (リング状)
translate([0, 0, handle_height_center - (handle_ring_diameter / 2 + handle_radius)]) {
    rotate([90, 0, 0]) {
        // 取手のリング部分
        difference() {
            // 外側のリング
            cylinder(h = handle_radius * 2, d = handle_ring_diameter + 2 * handle_radius, center = true);
            // 内側のくり抜き
            cylinder(h = handle_radius * 2, d = handle_ring_diameter, center = true);
        }
    }
}

// 取手のカップへの接続部分 (簡略化のため、リング状取手はカップ本体とは別に配置)
// より洗練された接続が必要な場合は、union()やhull()などを検討してください。
// ここでは、リング状取手がカップの外側にあるだけで、直接結合されていません。
// 接続部分を表現するには、さらに複雑な形状やboolean演算が必要です。
// 今回は、リング状取手がカップの横に「ぶら下がっている」ようなイメージで作成します。

// 実際には、取手はカップ本体に接続する必要があります。
// 以下のコードは、取手がカップ本体に「付いている」ように見せるための簡略化された方法です。

// 取手の接続部分1 (カップ外壁に接するように配置)
translate([outer_radius - handle_offset_from_wall, 0, handle_height_center]) {
    rotate([0, 90, 0]) {
        cylinder(h = handle_radius * 2, d = handle_radius * 2, center = true);
    }
}

// 取手の接続部分2 (取手のリングの内側に接続するように配置)
translate([-(inner_radius + handle_offset_from_wall), 0, handle_height_center]) {
    rotate([0, 90, 0]) {
        cylinder(h = handle_radius * 2, d = handle_radius * 2, center = true);
    }
}

// 取手のリング部分をカップ本体に接続するための形状(例:TorusとHull)
// より自然な取手にするために、取手のリングとカップ本体を繋ぐ形状を追加します。

// 取手のリング(先ほど作成したもの)を再定義し、カップ本体と結合します。

// マグカップ本体の作成(再定義、取手と結合するため)
module mug_body() {
    difference() {
        // 外側の円筒
        cylinder(h = height, d = outer_diameter, center = false);

        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }
}

// 取手のリング部分(よりカップに一体化させる)
module handle_ring() {
    handle_ring_inner_diameter = 30; // 指が入るサイズ
    handle_ring_thickness = 4;      // 取手のリングの太さ

    // 取手がカップのどの部分に付くかの開始点と終了点
    handle_start_angle = 30; // 開始角度 (度)
    handle_end_angle = 150;  // 終了角度 (度)
    handle_arc_length = handle_end_angle - handle_start_angle;

    // 取手のリングの円周方向のオフセット(カップ外壁からの距離)
    handle_radial_offset = 8; // リングの外側がカップ外壁からどれだけ離れるか

    // 取手のリングの回転軸(カップの中心軸)
    rotate_axis = [0, 0, 1];

    // 取手のリングをカップの側面に沿わせるように配置
    // ここでは、取手のリングをカップの円周に沿って配置します。
    // より自然な取手にするために、takeoff angleなども考慮する必要があります。

    // 取手のリングをカップの円周に沿って配置する
    // torus() を利用した方法
    translate([0, 0, handle_height_center]) {
        rotate([90, 0, 0]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_inner_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_inner_diameter, center = true);
            }
        }
    }
}

// マグカップ全体を結合
union() {
    mug_body();

    // 取手のリング部分をカップ本体に接続する
    // ここでは、hull() を使って取手のリングとカップ本体を滑らかに接続します。
    // 取手のリングの端点とカップ本体の円周上の点を結ぶようにします。

    // 取手のリングの端点(例)
    handle_ring_attach_point_1 = [outer_radius + handle_radial_offset, 0, handle_height_center];
    handle_ring_attach_point_2 = [-(outer_radius + handle_radial_offset), 0, handle_height_center];

    // カップ本体の円周上の点
    mug_attach_point_1 = [outer_radius, 0, handle_height_center];
    mug_attach_point_2 = [-outer_radius, 0, handle_height_center];

    // 簡略化のため、単純な円筒で取手の接続部分を作成し、リングとカップ本体を結合します。
    // より高度な形状を作成するには、customizer や complex boolean operations が必要になります。

    // 取手のリング(再定義、カップ本体に統合)
    handle_ring_thickness = 4;
    handle_ring_diameter = 30; // 指が入るサイズ
    handle_part_radius = 15; // 取手のリングの円周方向の半径 (カップ中心から)

    // 取手のリング部分の形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_part_radius * 2, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_part_radius * 2, d = handle_ring_diameter, center = true);
            }
        }
    }

    // 取手の接続部分(カップ本体に滑らかに繋げる)
    // 取手のリングの外側とカップ本体の外側を繋ぐ
    union() {
        // 取手のリングの外側
        rotate([90, 0, 0]) {
            translate([0, 0, handle_height_center]) {
                cylinder(h = handle_part_radius * 2, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
            }
        }
        // カップ本体の外側
        cylinder(h = height, d = outer_diameter, center = false);

        // 取手のリングの内側とカップ本体の内側を繋ぐ
        // 簡略化のため、取手のリングの外側とカップ本体の外側を直接繋いでいます。
        // より滑らかにするには、hull() や minkowski() を多用する必要があります。

        // 取手のリングの接続部分の作成
        handle_width = 20; // 取手のリングの幅 (カップの円周方向)
        handle_height = 30; // 取手のリングの高さ (カップの軸方向)

        // 取手のリングの端点
        handle_end_radius = outer_radius + handle_radial_offset;
        handle_end_height_offset = handle_height / 2;

        // 取手のリングの形状 (円筒と球の組み合わせ)
        rotate([0, 90, 0]) {
            translate([handle_end_radius, 0, handle_height_center]) {
                cylinder(h = handle_height, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
            }
            translate([-handle_end_radius, 0, handle_height_center]) {
                cylinder(h = handle_height, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
            }
        }

        // 取手のリングとカップ本体を滑らかに繋ぐ
        hull() {
            // 取手のリングの端点(左側)
            translate([-(outer_radius + handle_radial_offset), 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
            // カップ本体の円周上の点(左側)
            translate([-outer_radius, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
        }
        hull() {
            // 取手のリングの端点(右側)
            translate([outer_radius + handle_radial_offset, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
            // カップ本体の円周上の点(右側)
            translate([outer_radius, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
        }
        // 取手のリング全体
        rotate([90, 0, 0]) {
            translate([0, 0, handle_height_center]) {
                difference() {
                    minkowski() {
                        cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                        sphere(r = handle_ring_thickness / 2, $fn = 32);
                    }
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
                }
            }
        }
    }
}

// 最終的なマグカップの形状
difference() {
    // マグカップ本体
    mug_body();

    // 取手のリング部分をくり抜く
    // 取手のリングがカップ本体と重なる部分をくり抜く
    handle_ring_height = 30;
    handle_ring_radius = outer_radius + handle_radial_offset; // 取手のリングの中心の半径
    handle_ring_thickness_actual = 4; // 取手のリングの太さ

    // 取手のリングをカップ本体に接続するために、取手のリングの形状をくり抜く
    union() {
        // 取手のリングの外側
        rotate([90, 0, 0]) {
            translate([0, 0, handle_height_center - handle_ring_height/2]) {
                cylinder(h = handle_ring_height, d = handle_ring_diameter + 2 * handle_ring_thickness_actual, center = false);
            }
        }
        // 取手のリングの内側(くり抜く部分)
        rotate([90, 0, 0]) {
            translate([0, 0, handle_height_center - handle_ring_height/2]) {
                cylinder(h = handle_ring_height, d = handle_ring_diameter, center = false);
            }
        }
    }
}


// 最終的なマグカップの形状
union() {
    // マグカップ本体
    difference() {
        cylinder(h = height, d = outer_diameter, center = false);
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }

    // 取手のリング部分
    handle_diameter = 30; // 指が入るサイズ
    handle_thickness = 4; // 取手のリングの太さ
    handle_height_center = height / 2;

    // 取手のリングをカップの外側から飛び出すように配置
    // 取手のリングの中心をカップの中心から offset_from_cup_center だけ離す
    offset_from_cup_center = outer_radius + handle_thickness; // 取手のリングの円周方向の中心位置

    // 取手のリングの形状 (Torus approximation)
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_thickness, d = handle_diameter + 2 * handle_thickness, center = true);
                    sphere(r = handle_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_thickness, d = handle_diameter, center = true);
            }
        }
    }

    // 取手の接続部分 (カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(offset_from_cup_center), 0, handle_height_center]) {
            sphere(r = handle_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([offset_from_cup_center, 0, handle_height_center]) {
            sphere(r = handle_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_thickness, $fn = 32);
        }
    }

    // 取手のリングをカップ本体に接続するための形状を追加
    handle_connection_width = 20; // 取手の接続部分の幅 (カップの円周方向)
    handle_connection_height = 20; // 取手の接続部分の高さ (カップの軸方向)

    // 取手のリングとカップ本体を滑らかに繋ぐための追加形状
    // 左側の接続
    translate([-(outer_radius + handle_connection_width / 2), 0, handle_height_center - handle_connection_height / 2]) {
        rotate([0, 90, 0]) {
            cylinder(h = handle_connection_width, d = handle_connection_height, center = true);
        }
    }
    // 右側の接続
    translate([outer_radius + handle_connection_width / 2, 0, handle_height_center - handle_connection_height / 2]) {
        rotate([0, 90, 0]) {
            cylinder(h = handle_connection_width, d = handle_connection_height, center = true);
        }
    }

    // 取手のリング自体をカップ本体と結合
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                minkowski() {
                    cylinder(h = handle_thickness, d = handle_diameter + 2 * handle_thickness, center = true);
                    sphere(r = handle_thickness / 2, $fn = 32);
                }
                cylinder(h = handle_thickness, d = handle_diameter, center = true);
            }
        }
    }
}

// 最終的なコード
difference() {
    // マグカップ本体
    union() {
        // 外側の円筒
        cylinder(h = height, d = outer_diameter, center = false);

        // 取手の接続部分(カップ外周と取手リングを滑らかに繋ぐ)
        handle_radius_outer = outer_radius + 10; // 取手のリングの外側がカップ外壁からどれだけ離れるか
        handle_height_center = height / 2;
        handle_ring_thickness = 4; // 取手のリングの太さ
        handle_ring_diameter = 30; // 指が入るサイズ

        // 取手のリングの端点
        handle_attach_radius_outer = outer_radius + 5; // カップ外壁から取手リングの接続点までの距離

        // 取手のリングの左側接続
        hull() {
            translate([-handle_attach_radius_outer, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
            translate([-outer_radius, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
        }
        // 取手のリングの右側接続
        hull() {
            translate([handle_attach_radius_outer, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
            translate([outer_radius, 0, handle_height_center]) {
                sphere(r = handle_ring_thickness, $fn = 32);
            }
        }

        // 取手のリング部分 (プレースホルダー)
        // 最終的な形状はunion()で本体と結合される
        rotate([90, 0, 0]) {
            translate([0, 0, handle_height_center]) {
                difference() {
                    minkowski() {
                        cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                        sphere(r = handle_ring_thickness / 2, $fn = 32);
                    }
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
                }
            }
        }
    }

    // 内側のくり抜き
    translate([0, 0, base_thickness]) {
        cylinder(h = height - base_thickness, d = inner_diameter, center = false);
    }

    // 取手のリング部分 (くり抜く対象)
    handle_ring_thickness = 4; // 取手のリングの太さ
    handle_ring_diameter = 30; // 指が入るサイズ
    handle_height_center = height / 2;
    handle_radial_offset = 10; // カップ外壁からの取手のリングの開始点のオフセット

    // 取手のリングの形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
            }
        }
    }
}

// 最終的なマグカップの形状
union() {
    // マグカップ本体
    difference() {
        cylinder(h = height, d = outer_diameter, center = false);
        // 底面のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }

    // 取手のリング部分
    handle_ring_radius_outer = outer_diameter / 2 + 12; // 取手のリングの外側がカップ外壁からどれだけ飛び出すか
    handle_height_center = height / 2;
    handle_ring_thickness = 4; // 取手のリングの太さ
    handle_ring_diameter_inner = 30; // 指が入るサイズ

    // 取手のリングの形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter_inner + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter_inner, center = true);
            }
        }
    }

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(outer_radius + 10), 0, handle_height_center]) { // カップ外壁から少し離した位置
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([outer_radius + 10, 0, handle_height_center]) { // カップ外壁から少し離した位置
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
}


// 最終的なマグカップの形状
union() {
    // マグカップ本体
    difference() {
        cylinder(h = height, d = outer_diameter, center = false);
        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }

    // 取手のリング部分
    handle_ring_thickness = 4;       // 取手のリングの太さ
    handle_ring_diameter = 30;       // 指が入るサイズ
    handle_height_center = height / 2;
    handle_outer_radius = outer_diameter / 2 + 12; // 取手のリングの外側がカップ外壁からどれだけ飛び出すか

    // 取手のリングの形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
            }
        }
    }

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(outer_radius + 10), 0, handle_height_center]) { // カップ外壁から少し離した位置
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([outer_radius + 10, 0, handle_height_center]) { // カップ外壁から少し離した位置
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
}

// 最終的なマグカップの形状
union() {
    // マグカップ本体
    difference() {
        cylinder(h = height, d = outer_diameter, center = false);
        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }

    // 取手のリング部分
    handle_ring_thickness = 4;       // 取手のリングの太さ
    handle_ring_diameter = 30;       // 指が入るサイズ
    handle_height_center = height / 2;
    handle_connection_offset = 10;   // カップ外壁からの取手接続部のオフセット

    // 取手のリングの円周方向の中心位置
    handle_ring_center_radius = outer_radius + handle_connection_offset + handle_ring_thickness;

    // 取手のリングの形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
            }
        }
    }

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(handle_ring_center_radius), 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([handle_ring_center_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
}

// 最終的なマグカップの形状
union() {
    // マグカップ本体
    difference() {
        cylinder(h = height, d = outer_diameter, center = false);
        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }

    // 取手のリング部分
    handle_ring_thickness = 4;       // 取手のリングの太さ
    handle_ring_diameter = 30;       // 指が入るサイズ
    handle_height_center = height / 2;
    handle_outer_offset = 12;        // カップ外壁からの取手のリング外側の飛び出し量

    // 取手のリングの円周方向の中心半径
    handle_ring_center_radius = outer_radius + handle_outer_offset;

    // 取手のリングの形状
    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
            }
        }
    }

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(handle_ring_center_radius), 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([handle_ring_center_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
}

iteration: iter-png

i1 success
iter 1
5.7s · 7795/917t · $0.0011
diff vs bare: +20/-582
  // マグカップの基本パラメータ
  outer_diameter = 80; // 外径 (mm)
  height = 100;       // 高さ (mm)
  wall_thickness = 4; // 側面肉厚 (mm)
  base_thickness = 6; // 底面厚み (mm)
  
  // 内径の計算
  inner_diameter = outer_diameter - 2 * wall_thickness;
  inner_radius = inner_diameter / 2;
  outer_radius = outer_diameter / 2;
  
  // マグカップ本体の作成
- difference() {
-     // 外側の円筒
-     cylinder(h = height, d = outer_diameter, center = false);
- 
-     // 内側のくり抜き
-     translate([0, 0, base_thickness]) {
-         cylinder(h = height - base_thickness, d = inner_diameter, center = false);
-     }
- 
-     // 底面のくり抜き (底面厚み分)
-     // cylinder(h = base_thickness, d = outer_diameter, center = false); // これは不要。difference()で自動的にくり抜かれる。
- }
- 
- // 取手のパラメータ
- handle_radius = 12;          // 取手のリングの太さ (mm)
- handle_offset_from_wall = 5; // カップ外壁からの取手の開始点のオフセット (mm)
- handle_height_center = height / 2; // 取手を付ける中心高さ (mm)
- handle_ring_diameter = 30;  // 取手のリングの内径 (mm) (指が入るサイズ)
- 
- // 取手の作成 (リング状)
- translate([0, 0, handle_height_center - (handle_ring_diameter / 2 + handle_radius)]) {
-     rotate([90, 0, 0]) {
-         // 取手のリング部分
-         difference() {
-             // 外側のリング
-             cylinder(h = handle_radius * 2, d = handle_ring_diameter + 2 * handle_radius, center = true);
-             // 内側のくり抜き
-             cylinder(h = handle_radius * 2, d = handle_ring_diameter, center = true);
-         }
-     }
- }
- 
- // 取手のカップへの接続部分 (簡略化のため、リング状取手はカップ本体とは別に配置)
- // より洗練された接続が必要な場合は、union()やhull()などを検討してください。
- // ここでは、リング状取手がカップの外側にあるだけで、直接結合されていません。
- // 接続部分を表現するには、さらに複雑な形状やboolean演算が必要です。
- // 今回は、リング状取手がカップの横に「ぶら下がっている」ようなイメージで作成します。
- 
- // 実際には、取手はカップ本体に接続する必要があります。
- // 以下のコードは、取手がカップ本体に「付いている」ように見せるための簡略化された方法です。
- 
- // 取手の接続部分1 (カップ外壁に接するように配置)
- translate([outer_radius - handle_offset_from_wall, 0, handle_height_center]) {
-     rotate([0, 90, 0]) {
-         cylinder(h = handle_radius * 2, d = handle_radius * 2, center = true);
-     }
- }
- 
- // 取手の接続部分2 (取手のリングの内側に接続するように配置)
- translate([-(inner_radius + handle_offset_from_wall), 0, handle_height_center]) {
-     rotate([0, 90, 0]) {
-         cylinder(h = handle_radius * 2, d = handle_radius * 2, center = true);
-     }
- }
- 
- // 取手のリング部分をカップ本体に接続するための形状(例:TorusとHull)
- // より自然な取手にするために、取手のリングとカップ本体を繋ぐ形状を追加します。
- 
- // 取手のリング(先ほど作成したもの)を再定義し、カップ本体と結合します。
- 
- // マグカップ本体の作成(再定義、取手と結合するため)
  module mug_body() {
      difference() {
          // 外側の円筒
          cylinder(h = height, d = outer_diameter, center = false);
  
          // 内側のくり抜き
          translate([0, 0, base_thickness]) {
              cylinder(h = height - base_thickness, d = inner_diameter, center = false);
          }
      }
  }
  
- // 取手のリング部分(よりカップに一体化させる)
+ // 取手のパラメータ
+ handle_radius_from_wall = 12; // カップ外壁からの取手のリング外側の飛び出し量
+ handle_ring_thickness = 4;    // 取手のリングの太さ
+ handle_ring_diameter_inner = 30; // 指が入るサイズ (内径)
+ handle_height_center = height / 2; // 取手を付ける中心高さ
+ 
+ // 取手のリングの形状
  module handle_ring() {
-     handle_ring_inner_diameter = 30; // 指が入るサイズ
-     handle_ring_thickness = 4;      // 取手のリングの太さ
+     // 取手のリングの外側の半径
+     handle_ring_outer_radius = outer_radius + handle_radius_from_wall;
  
-     // 取手がカップのどの部分に付くかの開始点と終了点
-     handle_start_angle = 30; // 開始角度 (度)
-     handle_end_angle = 150;  // 終了角度 (度)
-     handle_arc_length = handle_end_angle - handle_start_angle;
- 
-     // 取手のリングの円周方向のオフセット(カップ外壁からの距離)
-     handle_radial_offset = 8; // リングの外側がカップ外壁からどれだけ離れるか
- 
-     // 取手のリングの回転軸(カップの中心軸)
-     rotate_axis = [0, 0, 1];
- 
-     // 取手のリングをカップの側面に沿わせるように配置
-     // ここでは、取手のリングをカップの円周に沿って配置します。
-     // より自然な取手にするために、takeoff angleなども考慮する必要があります。
- 
-     // 取手のリングをカップの円周に沿って配置する
-     // torus() を利用した方法
-     translate([0, 0, handle_height_center]) {
-         rotate([90, 0, 0]) {
-             difference() {
-                 // 外側のリング
-                 minkowski() {
-                     cylinder(h = handle_ring_thickness, d = handle_ring_inner_diameter + 2 * handle_ring_thickness, center = true);
-                     sphere(r = handle_ring_thickness / 2, $fn = 32);
-                 }
-                 // 内側のくり抜き
-                 cylinder(h = handle_ring_thickness, d = handle_ring_inner_diameter, center = true);
-             }
-         }
-     }
- }
- 
- // マグカップ全体を結合
- union() {
-     mug_body();
- 
-     // 取手のリング部分をカップ本体に接続する
-     // ここでは、hull() を使って取手のリングとカップ本体を滑らかに接続します。
-     // 取手のリングの端点とカップ本体の円周上の点を結ぶようにします。
- 
-     // 取手のリングの端点(例)
-     handle_ring_attach_point_1 = [outer_radius + handle_radial_offset, 0, handle_height_center];
-     handle_ring_attach_point_2 = [-(outer_radius + handle_radial_offset), 0, handle_height_center];
- 
-     // カップ本体の円周上の点
-     mug_attach_point_1 = [outer_radius, 0, handle_height_center];
-     mug_attach_point_2 = [-outer_radius, 0, handle_height_center];
- 
-     // 簡略化のため、単純な円筒で取手の接続部分を作成し、リングとカップ本体を結合します。
-     // より高度な形状を作成するには、customizer や complex boolean operations が必要になります。
- 
-     // 取手のリング(再定義、カップ本体に統合)
-     handle_ring_thickness = 4;
-     handle_ring_diameter = 30; // 指が入るサイズ
-     handle_part_radius = 15; // 取手のリングの円周方向の半径 (カップ中心から)
- 
-     // 取手のリング部分の形状
      rotate([90, 0, 0]) {
          translate([0, 0, handle_height_center]) {
              difference() {
                  // 外側のリング
                  minkowski() {
-                     cylinder(h = handle_part_radius * 2, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
-                     sphere(r = handle_ring_thickness / 2, $fn = 32);
-                 }
-                 // 内側のくり抜き
-                 cylinder(h = handle_part_radius * 2, d = handle_ring_diameter, center = true);
-             }
-         }
-     }
- 
-     // 取手の接続部分(カップ本体に滑らかに繋げる)
-     // 取手のリングの外側とカップ本体の外側を繋ぐ
-     union() {
-         // 取手のリングの外側
-         rotate([90, 0, 0]) {
-             translate([0, 0, handle_height_center]) {
-                 cylinder(h = handle_part_radius * 2, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
-             }
-         }
-         // カップ本体の外側
-         cylinder(h = height, d = outer_diameter, center = false);
- 
-         // 取手のリングの内側とカップ本体の内側を繋ぐ
-         // 簡略化のため、取手のリングの外側とカップ本体の外側を直接繋いでいます。
-         // より滑らかにするには、hull() や minkowski() を多用する必要があります。
- 
-         // 取手のリングの接続部分の作成
-         handle_width = 20; // 取手のリングの幅 (カップの円周方向)
-         handle_height = 30; // 取手のリングの高さ (カップの軸方向)
- 
-         // 取手のリングの端点
-         handle_end_radius = outer_radius + handle_radial_offset;
-         handle_end_height_offset = handle_height / 2;
- 
-         // 取手のリングの形状 (円筒と球の組み合わせ)
-         rotate([0, 90, 0]) {
-             translate([handle_end_radius, 0, handle_height_center]) {
-                 cylinder(h = handle_height, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
-             }
-             translate([-handle_end_radius, 0, handle_height_center]) {
-                 cylinder(h = handle_height, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
-             }
-         }
- 
-         // 取手のリングとカップ本体を滑らかに繋ぐ
-         hull() {
-             // 取手のリングの端点(左側)
-             translate([-(outer_radius + handle_radial_offset), 0, handle_height_center]) {
-                 sphere(r = handle_ring_thickness, $fn = 32);
-             }
-             // カップ本体の円周上の点(左側)
-             translate([-outer_radius, 0, handle_height_center]) {
-                 sphere(r = handle_ring_thickness, $fn = 32);
-             }
-         }
-         hull() {
-             // 取手のリングの端点(右側)
-             translate([outer_radius + handle_radial_offset, 0, handle_height_center]) {
-                 sphere(r = handle_ring_thickness, $fn = 32);
-             }
-             // カップ本体の円周上の点(右側)
-             translate([outer_radius, 0, handle_height_center]) {
-                 sphere(r = handle_ring_thickness, $fn = 32);
-             }
-         }
-         // 取手のリング全体
-         rotate([90, 0, 0]) {
-             translate([0, 0, handle_height_center]) {
-                 difference() {
-                     minkowski() {
-                         cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
-                         sphere(r = handle_ring_thickness / 2, $fn = 32);
-                     }
-                     cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
-                 }
-             }
-         }
-     }
- }
- 
- // 最終的なマグカップの形状
- difference() {
-     // マグカップ本体
-     mug_body();
- 
-     // 取手のリング部分をくり抜く
-     // 取手のリングがカップ本体と重なる部分をくり抜く
-     handle_ring_height = 30;
-     handle_ring_radius = outer_radius + handle_radial_offset; // 取手のリングの中心の半径
-     handle_ring_thickness_actual = 4; // 取手のリングの太さ
- 
-     // 取手のリングをカップ本体に接続するために、取手のリングの形状をくり抜く
-     union() {
-         // 取手のリングの外側
-         rotate([90, 0, 0]) {
-             translate([0, 0, handle_height_center - handle_ring_height/2]) {
-                 cylinder(h = handle_ring_height, d = handle_ring_diameter + 2 * handle_ring_thickness_actual, center = false);
-             }
-         }
-         // 取手のリングの内側(くり抜く部分)
-         rotate([90, 0, 0]) {
-             translate([0, 0, handle_height_center - handle_ring_height/2]) {
-                 cylinder(h = handle_ring_height, d = handle_ring_diameter, center = false);
-             }
-         }
-     }
- }
- 
- 
- // 最終的なマグカップの形状
- union() {
-     // マグカップ本体
-     difference() {
-         cylinder(h = height, d = outer_diameter, center = false);
-         translate([0, 0, base_thickness]) {
-             cylinder(h = height - base_thickness, d = inner_diameter, center = false);
-         }
-     }
- 
-     // 取手のリング部分
-     handle_diameter = 30; // 指が入るサイズ
-     handle_thickness = 4; // 取手のリングの太さ
-     handle_height_center = height / 2;
- 
-     // 取手のリングをカップの外側から飛び出すように配置
-     // 取手のリングの中心をカップの中心から offset_from_cup_center だけ離す
-     offset_from_cup_center = outer_radius + handle_thickness; // 取手のリングの円周方向の中心位置
- 
-     // 取手のリングの形状 (Torus approximation)
-     rotate([90, 0, 0]) {
-         translate([0, 0, handle_height_center]) {
-             difference() {
-                 // 外側のリング
-                 minkowski() {
-                     cylinder(h = handle_thickness, d = handle_diameter + 2 * handle_thickness, center = true);
-                     sphere(r = handle_thickness / 2, $fn = 32);
-                 }
-                 // 内側のくり抜き
-                 cylinder(h = handle_thickness, d = handle_diameter, center = true);
-             }
-         }
-     }
- 
-     // 取手の接続部分 (カップ本体と取手のリングを繋ぐ)
-     hull() {
-         // 取手のリングの左端
-         translate([-(offset_from_cup_center), 0, handle_height_center]) {
-             sphere(r = handle_thickness, $fn = 32);
-         }
-         // カップ本体の左側円周上の点
-         translate([-outer_radius, 0, handle_height_center]) {
-             sphere(r = handle_thickness, $fn = 32);
-         }
-     }
-     hull() {
-         // 取手のリングの右端
-         translate([offset_from_cup_center, 0, handle_height_center]) {
-             sphere(r = handle_thickness, $fn = 32);
-         }
-         // カップ本体の右側円周上の点
-         translate([outer_radius, 0, handle_height_center]) {
-             sphere(r = handle_thickness, $fn = 32);
-         }
-     }
- 
-     // 取手のリングをカップ本体に接続するための形状を追加
-     handle_connection_width = 20; // 取手の接続部分の幅 (カップの円周方向)
-     handle_connection_height = 20; // 取手の接続部分の高さ (カップの軸方向)
- 
-     // 取手のリングとカップ本体を滑らかに繋ぐための追加形状
-     // 左側の接続
-     translate([-(outer_radius + handle_connection_width / 2), 0, handle_height_center - handle_connection_height / 2]) {
-         rotate([0, 90, 0]) {
-             cylinder(h = handle_connection_width, d = handle_connection_height, center = true);
-         }
-     }
-     // 右側の接続
-     translate([outer_radius + handle_connection_width / 2, 0, handle_height_center - handle_connection_height / 2]) {
-         rotate([0, 90, 0]) {
-             cylinder(h = handle_connection_width, d = handle_connection_height, center = true);
-         }
-     }
- 
-     // 取手のリング自体をカップ本体と結合
-     rotate([90, 0, 0]) {
-         translate([0, 0, handle_height_center]) {
-             difference() {
-                 minkowski() {
-                     cylinder(h = handle_thickness, d = handle_diameter + 2 * handle_thickness, center = true);
-                     sphere(r = handle_thickness / 2, $fn = 32);
-                 }
-                 cylinder(h = handle_thickness, d = handle_diameter, center = true);
-             }
-         }
-     }
- }
- 
- // 最終的なコード
- difference() {
-     // マグカップ本体
-     union() {
-         // 外側の円筒
-         cylinder(h = height, d = outer_diameter, center = false);
- 
-         // 取手の接続部分(カップ外周と取手リングを滑らかに繋ぐ)
-         handle_radius_outer = outer_radius + 10; // 取手のリングの外側がカップ外壁からどれだけ離れるか
-         handle_height_center = height / 2;
-         handle_ring_thickness = 4; // 取手のリングの太さ
-         handle_ring_diameter = 30; // 指が入るサイズ
- 
-         // 取手のリングの端点
-         handle_attach_radius_outer = outer_radius + 5; // カップ外壁から取手リングの接続点までの距離
- 
-         // 取手のリングの左側接続
-         hull() {
-             translate([-handle_attach_radius_outer, 0, handle_height_center]) {
-                 sphere(r = handle_ring_thickness, $fn = 32);
-             }
-             translate([-outer_radius, 0, handle_height_center]) {
-                 sphere(r = handle_ring_thickness, $fn = 32);
-             }
-         }
-         // 取手のリングの右側接続
-         hull() {
-             translate([handle_attach_radius_outer, 0, handle_height_center]) {
-                 sphere(r = handle_ring_thickness, $fn = 32);
-             }
-             translate([outer_radius, 0, handle_height_center]) {
-                 sphere(r = handle_ring_thickness, $fn = 32);
-             }
-         }
- 
-         // 取手のリング部分 (プレースホルダー)
-         // 最終的な形状はunion()で本体と結合される
-         rotate([90, 0, 0]) {
-             translate([0, 0, handle_height_center]) {
-                 difference() {
-                     minkowski() {
-                         cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
-                         sphere(r = handle_ring_thickness / 2, $fn = 32);
-                     }
-                     cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
-                 }
-             }
-         }
-     }
- 
-     // 内側のくり抜き
-     translate([0, 0, base_thickness]) {
-         cylinder(h = height - base_thickness, d = inner_diameter, center = false);
-     }
- 
-     // 取手のリング部分 (くり抜く対象)
-     handle_ring_thickness = 4; // 取手のリングの太さ
-     handle_ring_diameter = 30; // 指が入るサイズ
-     handle_height_center = height / 2;
-     handle_radial_offset = 10; // カップ外壁からの取手のリングの開始点のオフセット
- 
-     // 取手のリングの形状
-     rotate([90, 0, 0]) {
-         translate([0, 0, handle_height_center]) {
-             difference() {
-                 // 外側のリング
-                 minkowski() {
-                     cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
-                     sphere(r = handle_ring_thickness / 2, $fn = 32);
-                 }
-                 // 内側のくり抜き
-                 cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
-             }
-         }
-     }
- }
- 
- // 最終的なマグカップの形状
- union() {
-     // マグカップ本体
-     difference() {
-         cylinder(h = height, d = outer_diameter, center = false);
-         // 底面のくり抜き
-         translate([0, 0, base_thickness]) {
-             cylinder(h = height - base_thickness, d = inner_diameter, center = false);
-         }
-     }
- 
-     // 取手のリング部分
-     handle_ring_radius_outer = outer_diameter / 2 + 12; // 取手のリングの外側がカップ外壁からどれだけ飛び出すか
-     handle_height_center = height / 2;
-     handle_ring_thickness = 4; // 取手のリングの太さ
-     handle_ring_diameter_inner = 30; // 指が入るサイズ
- 
-     // 取手のリングの形状
-     rotate([90, 0, 0]) {
-         translate([0, 0, handle_height_center]) {
-             difference() {
-                 // 外側のリング
-                 minkowski() {
                      cylinder(h = handle_ring_thickness, d = handle_ring_diameter_inner + 2 * handle_ring_thickness, center = true);
                      sphere(r = handle_ring_thickness / 2, $fn = 32);
                  }
                  // 内側のくり抜き
                  cylinder(h = handle_ring_thickness, d = handle_ring_diameter_inner, center = true);
              }
          }
      }
- 
-     // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
-     hull() {
-         // 取手のリングの左端
-         translate([-(outer_radius + 10), 0, handle_height_center]) { // カップ外壁から少し離した位置
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-         // カップ本体の左側円周上の点
-         translate([-outer_radius, 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-     }
-     hull() {
-         // 取手のリングの右端
-         translate([outer_radius + 10, 0, handle_height_center]) { // カップ外壁から少し離した位置
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-         // カップ本体の右側円周上の点
-         translate([outer_radius, 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-     }
  }
  
- 
- // 最終的なマグカップの形状
- union() {
-     // マグカップ本体
-     difference() {
-         cylinder(h = height, d = outer_diameter, center = false);
-         // 内側のくり抜き
-         translate([0, 0, base_thickness]) {
-             cylinder(h = height - base_thickness, d = inner_diameter, center = false);
-         }
-     }
- 
-     // 取手のリング部分
-     handle_ring_thickness = 4;       // 取手のリングの太さ
-     handle_ring_diameter = 30;       // 指が入るサイズ
+ // 取手の接続部分 (カップ本体と取手のリングを繋ぐ)
+ module handle_connectors() {
+     handle_ring_thickness = 4;
      handle_height_center = height / 2;
-     handle_outer_radius = outer_diameter / 2 + 12; // 取手のリングの外側がカップ外壁からどれだけ飛び出すか
+     handle_outer_offset = 12; // カップ外壁からの取手のリング外側の飛び出し量
  
-     // 取手のリングの形状
-     rotate([90, 0, 0]) {
-         translate([0, 0, handle_height_center]) {
-             difference() {
-                 // 外側のリング
-                 minkowski() {
-                     cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
-                     sphere(r = handle_ring_thickness / 2, $fn = 32);
-                 }
-                 // 内側のくり抜き
-                 cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
-             }
-         }
-     }
+     // 取手のリングの円周方向の中心半径
+     // 取手のリングの外側がカップ外壁から handle_outer_offset だけ飛び出すように計算
+     handle_ring_center_radius = outer_radius + handle_outer_offset + handle_ring_thickness;
  
      // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
      hull() {
          // 取手のリングの左端
-         translate([-(outer_radius + 10), 0, handle_height_center]) { // カップ外壁から少し離した位置
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-         // カップ本体の左側円周上の点
-         translate([-outer_radius, 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-     }
-     hull() {
-         // 取手のリングの右端
-         translate([outer_radius + 10, 0, handle_height_center]) { // カップ外壁から少し離した位置
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-         // カップ本体の右側円周上の点
-         translate([outer_radius, 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-     }
- }
- 
- // 最終的なマグカップの形状
- union() {
-     // マグカップ本体
-     difference() {
-         cylinder(h = height, d = outer_diameter, center = false);
-         // 内側のくり抜き
-         translate([0, 0, base_thickness]) {
-             cylinder(h = height - base_thickness, d = inner_diameter, center = false);
-         }
-     }
- 
-     // 取手のリング部分
-     handle_ring_thickness = 4;       // 取手のリングの太さ
-     handle_ring_diameter = 30;       // 指が入るサイズ
-     handle_height_center = height / 2;
-     handle_connection_offset = 10;   // カップ外壁からの取手接続部のオフセット
- 
-     // 取手のリングの円周方向の中心位置
-     handle_ring_center_radius = outer_radius + handle_connection_offset + handle_ring_thickness;
- 
-     // 取手のリングの形状
-     rotate([90, 0, 0]) {
-         translate([0, 0, handle_height_center]) {
-             difference() {
-                 // 外側のリング
-                 minkowski() {
-                     cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
-                     sphere(r = handle_ring_thickness / 2, $fn = 32);
-                 }
-                 // 内側のくり抜き
-                 cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
-             }
-         }
-     }
- 
-     // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
-     hull() {
-         // 取手のリングの左端
          translate([-(handle_ring_center_radius), 0, handle_height_center]) {
              sphere(r = handle_ring_thickness, $fn = 32);
          }
          // カップ本体の左側円周上の点
          translate([-outer_radius, 0, handle_height_center]) {
              sphere(r = handle_ring_thickness, $fn = 32);
          }
      }
      hull() {
          // 取手のリングの右端
          translate([handle_ring_center_radius, 0, handle_height_center]) {
              sphere(r = handle_ring_thickness, $fn = 32);
          }
          // カップ本体の右側円周上の点
          translate([outer_radius, 0, handle_height_center]) {
              sphere(r = handle_ring_thickness, $fn = 32);
          }
      }
  }
  
- // 最終的なマグカップの形状
+ // マグカップ全体を結合
  union() {
-     // マグカップ本体
-     difference() {
-         cylinder(h = height, d = outer_diameter, center = false);
-         // 内側のくり抜き
-         translate([0, 0, base_thickness]) {
-             cylinder(h = height - base_thickness, d = inner_diameter, center = false);
-         }
-     }
- 
-     // 取手のリング部分
-     handle_ring_thickness = 4;       // 取手のリングの太さ
-     handle_ring_diameter = 30;       // 指が入るサイズ
-     handle_height_center = height / 2;
-     handle_outer_offset = 12;        // カップ外壁からの取手のリング外側の飛び出し量
- 
-     // 取手のリングの円周方向の中心半径
-     handle_ring_center_radius = outer_radius + handle_outer_offset;
- 
-     // 取手のリングの形状
-     rotate([90, 0, 0]) {
-         translate([0, 0, handle_height_center]) {
-             difference() {
-                 // 外側のリング
-                 minkowski() {
-                     cylinder(h = handle_ring_thickness, d = handle_ring_diameter + 2 * handle_ring_thickness, center = true);
-                     sphere(r = handle_ring_thickness / 2, $fn = 32);
-                 }
-                 // 内側のくり抜き
-                 cylinder(h = handle_ring_thickness, d = handle_ring_diameter, center = true);
-             }
-         }
-     }
- 
-     // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
-     hull() {
-         // 取手のリングの左端
-         translate([-(handle_ring_center_radius), 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-         // カップ本体の左側円周上の点
-         translate([-outer_radius, 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-     }
-     hull() {
-         // 取手のリングの右端
-         translate([handle_ring_center_radius, 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-         // カップ本体の右側円周上の点
-         translate([outer_radius, 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
-         }
-     }
+     mug_body();
+     handle_ring();
+     handle_connectors();
  }
SCAD (89 lines)
// マグカップの基本パラメータ
outer_diameter = 80; // 外径 (mm)
height = 100;       // 高さ (mm)
wall_thickness = 4; // 側面肉厚 (mm)
base_thickness = 6; // 底面厚み (mm)

// 内径の計算
inner_diameter = outer_diameter - 2 * wall_thickness;
inner_radius = inner_diameter / 2;
outer_radius = outer_diameter / 2;

// マグカップ本体の作成
module mug_body() {
    difference() {
        // 外側の円筒
        cylinder(h = height, d = outer_diameter, center = false);

        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }
}

// 取手のパラメータ
handle_radius_from_wall = 12; // カップ外壁からの取手のリング外側の飛び出し量
handle_ring_thickness = 4;    // 取手のリングの太さ
handle_ring_diameter_inner = 30; // 指が入るサイズ (内径)
handle_height_center = height / 2; // 取手を付ける中心高さ

// 取手のリングの形状
module handle_ring() {
    // 取手のリングの外側の半径
    handle_ring_outer_radius = outer_radius + handle_radius_from_wall;

    rotate([90, 0, 0]) {
        translate([0, 0, handle_height_center]) {
            difference() {
                // 外側のリング
                minkowski() {
                    cylinder(h = handle_ring_thickness, d = handle_ring_diameter_inner + 2 * handle_ring_thickness, center = true);
                    sphere(r = handle_ring_thickness / 2, $fn = 32);
                }
                // 内側のくり抜き
                cylinder(h = handle_ring_thickness, d = handle_ring_diameter_inner, center = true);
            }
        }
    }
}

// 取手の接続部分 (カップ本体と取手のリングを繋ぐ)
module handle_connectors() {
    handle_ring_thickness = 4;
    handle_height_center = height / 2;
    handle_outer_offset = 12; // カップ外壁からの取手のリング外側の飛び出し量

    // 取手のリングの円周方向の中心半径
    // 取手のリングの外側がカップ外壁から handle_outer_offset だけ飛び出すように計算
    handle_ring_center_radius = outer_radius + handle_outer_offset + handle_ring_thickness;

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    hull() {
        // 取手のリングの左端
        translate([-(handle_ring_center_radius), 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
    hull() {
        // 取手のリングの右端
        translate([handle_ring_center_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
}

// マグカップ全体を結合
union() {
    mug_body();
    handle_ring();
    handle_connectors();
}
i2 success
iter 2
6.3s · 1379/935t · $0.0005
diff vs i1: +18/-17
  // マグカップの基本パラメータ
  outer_diameter = 80; // 外径 (mm)
  height = 100;       // 高さ (mm)
  wall_thickness = 4; // 側面肉厚 (mm)
  base_thickness = 6; // 底面厚み (mm)
  
  // 内径の計算
  inner_diameter = outer_diameter - 2 * wall_thickness;
  inner_radius = inner_diameter / 2;
  outer_radius = outer_diameter / 2;
  
  // マグカップ本体の作成
  module mug_body() {
      difference() {
          // 外側の円筒
          cylinder(h = height, d = outer_diameter, center = false);
  
          // 内側のくり抜き
          translate([0, 0, base_thickness]) {
              cylinder(h = height - base_thickness, d = inner_diameter, center = false);
          }
      }
  }
  
  // 取手のパラメータ
- handle_radius_from_wall = 12; // カップ外壁からの取手のリング外側の飛び出し量
+ handle_ring_outer_projection = 12; // カップ外壁からの取手のリング外側の飛び出し量
  handle_ring_thickness = 4;    // 取手のリングの太さ
- handle_ring_diameter_inner = 30; // 指が入るサイズ (内径)
+ handle_finger_hole_diameter = 30; // 指が入るサイズ (内径)
  handle_height_center = height / 2; // 取手を付ける中心高さ
  
  // 取手のリングの形状
  module handle_ring() {
      // 取手のリングの外側の半径
-     handle_ring_outer_radius = outer_radius + handle_radius_from_wall;
+     handle_ring_outer_radius = outer_radius + handle_ring_outer_projection;
  
-     rotate([90, 0, 0]) {
-         translate([0, 0, handle_height_center]) {
-             difference() {
-                 // 外側のリング
-                 minkowski() {
-                     cylinder(h = handle_ring_thickness, d = handle_ring_diameter_inner + 2 * handle_ring_thickness, center = true);
-                     sphere(r = handle_ring_thickness / 2, $fn = 32);
+     // 取手のリングの円周方向の中心半径
+     handle_ring_center_radius = handle_ring_outer_radius - handle_ring_thickness / 2;
+ 
+     rotate([90, 0, 0]) { // Z軸周りに90度回転して横向きにする
+         translate([handle_ring_center_radius, 0, handle_height_center]) {
+             // toroidal shape
+             rotate_extrude(convexity = 10) {
+                 translate([handle_ring_thickness / 2, 0, 0]) {
+                     circle(r = handle_ring_thickness / 2, $fn = 64);
                  }
-                 // 内側のくり抜き
-                 cylinder(h = handle_ring_thickness, d = handle_ring_diameter_inner, center = true);
              }
          }
      }
  }
  
  // 取手の接続部分 (カップ本体と取手のリングを繋ぐ)
  module handle_connectors() {
      handle_ring_thickness = 4;
      handle_height_center = height / 2;
-     handle_outer_offset = 12; // カップ外壁からの取手のリング外側の飛び出し量
+     handle_outer_projection = 12; // カップ外壁からの取手のリング外側の飛び出し量
  
      // 取手のリングの円周方向の中心半径
-     // 取手のリングの外側がカップ外壁から handle_outer_offset だけ飛び出すように計算
-     handle_ring_center_radius = outer_radius + handle_outer_offset + handle_ring_thickness;
+     handle_ring_center_radius = outer_radius + handle_outer_projection + handle_ring_thickness / 2;
  
      // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
+     // 左側の接続
      hull() {
-         // 取手のリングの左端
+         // 取手のリングの左端(回転後の位置を考慮)
          translate([-(handle_ring_center_radius), 0, handle_height_center]) {
              sphere(r = handle_ring_thickness, $fn = 32);
          }
          // カップ本体の左側円周上の点
          translate([-outer_radius, 0, handle_height_center]) {
              sphere(r = handle_ring_thickness, $fn = 32);
          }
      }
+     // 右側の接続
      hull() {
-         // 取手のリングの右端
+         // 取手のリングの右端(回転後の位置を考慮)
          translate([handle_ring_center_radius, 0, handle_height_center]) {
              sphere(r = handle_ring_thickness, $fn = 32);
          }
          // カップ本体の右側円周上の点
          translate([outer_radius, 0, handle_height_center]) {
              sphere(r = handle_ring_thickness, $fn = 32);
          }
      }
  }
  
  // マグカップ全体を結合
  union() {
      mug_body();
      handle_ring();
      handle_connectors();
  }
SCAD (90 lines)
// マグカップの基本パラメータ
outer_diameter = 80; // 外径 (mm)
height = 100;       // 高さ (mm)
wall_thickness = 4; // 側面肉厚 (mm)
base_thickness = 6; // 底面厚み (mm)

// 内径の計算
inner_diameter = outer_diameter - 2 * wall_thickness;
inner_radius = inner_diameter / 2;
outer_radius = outer_diameter / 2;

// マグカップ本体の作成
module mug_body() {
    difference() {
        // 外側の円筒
        cylinder(h = height, d = outer_diameter, center = false);

        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness, d = inner_diameter, center = false);
        }
    }
}

// 取手のパラメータ
handle_ring_outer_projection = 12; // カップ外壁からの取手のリング外側の飛び出し量
handle_ring_thickness = 4;    // 取手のリングの太さ
handle_finger_hole_diameter = 30; // 指が入るサイズ (内径)
handle_height_center = height / 2; // 取手を付ける中心高さ

// 取手のリングの形状
module handle_ring() {
    // 取手のリングの外側の半径
    handle_ring_outer_radius = outer_radius + handle_ring_outer_projection;

    // 取手のリングの円周方向の中心半径
    handle_ring_center_radius = handle_ring_outer_radius - handle_ring_thickness / 2;

    rotate([90, 0, 0]) { // Z軸周りに90度回転して横向きにする
        translate([handle_ring_center_radius, 0, handle_height_center]) {
            // toroidal shape
            rotate_extrude(convexity = 10) {
                translate([handle_ring_thickness / 2, 0, 0]) {
                    circle(r = handle_ring_thickness / 2, $fn = 64);
                }
            }
        }
    }
}

// 取手の接続部分 (カップ本体と取手のリングを繋ぐ)
module handle_connectors() {
    handle_ring_thickness = 4;
    handle_height_center = height / 2;
    handle_outer_projection = 12; // カップ外壁からの取手のリング外側の飛び出し量

    // 取手のリングの円周方向の中心半径
    handle_ring_center_radius = outer_radius + handle_outer_projection + handle_ring_thickness / 2;

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    // 左側の接続
    hull() {
        // 取手のリングの左端(回転後の位置を考慮)
        translate([-(handle_ring_center_radius), 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
    // 右側の接続
    hull() {
        // 取手のリングの右端(回転後の位置を考慮)
        translate([handle_ring_center_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_ring_thickness, $fn = 32);
        }
    }
}

// マグカップ全体を結合
union() {
    mug_body();
    handle_ring();
    handle_connectors();
}
i3 success
iter 3
3.8s · 1397/1112t · $0.0006
diff vs i2: +15/-19
  // マグカップの基本パラメータ
  outer_diameter = 80; // 外径 (mm)
  height = 100;       // 高さ (mm)
  wall_thickness = 4; // 側面肉厚 (mm)
  base_thickness = 6; // 底面厚み (mm)
  
  // 内径の計算
  inner_diameter = outer_diameter - 2 * wall_thickness;
  inner_radius = inner_diameter / 2;
  outer_radius = outer_diameter / 2;
  
  // マグカップ本体の作成
  module mug_body() {
      difference() {
          // 外側の円筒
-         cylinder(h = height, d = outer_diameter, center = false);
+         cylinder(h = height, d = outer_diameter, center = false, $fn = 100);
  
          // 内側のくり抜き
          translate([0, 0, base_thickness]) {
-             cylinder(h = height - base_thickness, d = inner_diameter, center = false);
+             cylinder(h = height - base_thickness + 0.1, d = inner_diameter, center = false, $fn = 100); // 少し高めに設定して確実にくり抜く
          }
      }
  }
  
  // 取手のパラメータ
- handle_ring_outer_projection = 12; // カップ外壁からの取手のリング外側の飛び出し量
+ handle_outer_projection = 12; // カップ外壁からの取手のリング外側の飛び出し量
  handle_ring_thickness = 4;    // 取手のリングの太さ
- handle_finger_hole_diameter = 30; // 指が入るサイズ (内径)
+ handle_finger_hole_radius = 15; // 指が入るサイズ (半径)
  handle_height_center = height / 2; // 取手を付ける中心高さ
+ handle_connector_radius = handle_ring_thickness; // 取手とカップ本体を繋ぐ部分の半径
  
  // 取手のリングの形状
  module handle_ring() {
      // 取手のリングの外側の半径
-     handle_ring_outer_radius = outer_radius + handle_ring_outer_projection;
- 
-     // 取手のリングの円周方向の中心半径
+     handle_ring_outer_radius = outer_radius + handle_outer_projection;
+     // 取手のリングの中心の半径
      handle_ring_center_radius = handle_ring_outer_radius - handle_ring_thickness / 2;
  
      rotate([90, 0, 0]) { // Z軸周りに90度回転して横向きにする
          translate([handle_ring_center_radius, 0, handle_height_center]) {
              // toroidal shape
              rotate_extrude(convexity = 10) {
                  translate([handle_ring_thickness / 2, 0, 0]) {
                      circle(r = handle_ring_thickness / 2, $fn = 64);
                  }
              }
          }
      }
  }
  
  // 取手の接続部分 (カップ本体と取手のリングを繋ぐ)
  module handle_connectors() {
-     handle_ring_thickness = 4;
-     handle_height_center = height / 2;
-     handle_outer_projection = 12; // カップ外壁からの取手のリング外側の飛び出し量
- 
      // 取手のリングの円周方向の中心半径
      handle_ring_center_radius = outer_radius + handle_outer_projection + handle_ring_thickness / 2;
  
      // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
      // 左側の接続
      hull() {
-         // 取手のリングの左端(回転後の位置を考慮)
-         translate([-(handle_ring_center_radius), 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
+         // 取手のリングの左端 (回転後の位置を考慮)
+         translate([-(handle_ring_center_radius - handle_ring_thickness/2), 0, handle_height_center]) {
+             sphere(r = handle_connector_radius, $fn = 32);
          }
          // カップ本体の左側円周上の点
          translate([-outer_radius, 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
+             sphere(r = handle_connector_radius, $fn = 32);
          }
      }
      // 右側の接続
      hull() {
-         // 取手のリングの右端(回転後の位置を考慮)
-         translate([handle_ring_center_radius, 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
+         // 取手のリングの右端 (回転後の位置を考慮)
+         translate([handle_ring_center_radius + handle_ring_thickness/2, 0, handle_height_center]) {
+             sphere(r = handle_connector_radius, $fn = 32);
          }
          // カップ本体の右側円周上の点
          translate([outer_radius, 0, handle_height_center]) {
-             sphere(r = handle_ring_thickness, $fn = 32);
+             sphere(r = handle_connector_radius, $fn = 32);
          }
      }
  }
  
  // マグカップ全体を結合
  union() {
      mug_body();
      handle_ring();
      handle_connectors();
  }
SCAD (86 lines)
// マグカップの基本パラメータ
outer_diameter = 80; // 外径 (mm)
height = 100;       // 高さ (mm)
wall_thickness = 4; // 側面肉厚 (mm)
base_thickness = 6; // 底面厚み (mm)

// 内径の計算
inner_diameter = outer_diameter - 2 * wall_thickness;
inner_radius = inner_diameter / 2;
outer_radius = outer_diameter / 2;

// マグカップ本体の作成
module mug_body() {
    difference() {
        // 外側の円筒
        cylinder(h = height, d = outer_diameter, center = false, $fn = 100);

        // 内側のくり抜き
        translate([0, 0, base_thickness]) {
            cylinder(h = height - base_thickness + 0.1, d = inner_diameter, center = false, $fn = 100); // 少し高めに設定して確実にくり抜く
        }
    }
}

// 取手のパラメータ
handle_outer_projection = 12; // カップ外壁からの取手のリング外側の飛び出し量
handle_ring_thickness = 4;    // 取手のリングの太さ
handle_finger_hole_radius = 15; // 指が入るサイズ (半径)
handle_height_center = height / 2; // 取手を付ける中心高さ
handle_connector_radius = handle_ring_thickness; // 取手とカップ本体を繋ぐ部分の半径

// 取手のリングの形状
module handle_ring() {
    // 取手のリングの外側の半径
    handle_ring_outer_radius = outer_radius + handle_outer_projection;
    // 取手のリングの中心の半径
    handle_ring_center_radius = handle_ring_outer_radius - handle_ring_thickness / 2;

    rotate([90, 0, 0]) { // Z軸周りに90度回転して横向きにする
        translate([handle_ring_center_radius, 0, handle_height_center]) {
            // toroidal shape
            rotate_extrude(convexity = 10) {
                translate([handle_ring_thickness / 2, 0, 0]) {
                    circle(r = handle_ring_thickness / 2, $fn = 64);
                }
            }
        }
    }
}

// 取手の接続部分 (カップ本体と取手のリングを繋ぐ)
module handle_connectors() {
    // 取手のリングの円周方向の中心半径
    handle_ring_center_radius = outer_radius + handle_outer_projection + handle_ring_thickness / 2;

    // 取手の接続部分(カップ本体と取手のリングを繋ぐ)
    // 左側の接続
    hull() {
        // 取手のリングの左端 (回転後の位置を考慮)
        translate([-(handle_ring_center_radius - handle_ring_thickness/2), 0, handle_height_center]) {
            sphere(r = handle_connector_radius, $fn = 32);
        }
        // カップ本体の左側円周上の点
        translate([-outer_radius, 0, handle_height_center]) {
            sphere(r = handle_connector_radius, $fn = 32);
        }
    }
    // 右側の接続
    hull() {
        // 取手のリングの右端 (回転後の位置を考慮)
        translate([handle_ring_center_radius + handle_ring_thickness/2, 0, handle_height_center]) {
            sphere(r = handle_connector_radius, $fn = 32);
        }
        // カップ本体の右側円周上の点
        translate([outer_radius, 0, handle_height_center]) {
            sphere(r = handle_connector_radius, $fn = 32);
        }
    }
}

// マグカップ全体を結合
union() {
    mug_body();
    handle_ring();
    handle_connectors();
}