1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 22:28:16 +01:00
dotSCAD/examples/klein_bottle.scad

110 lines
3.5 KiB
OpenSCAD
Raw Normal View History

2022-06-06 13:11:46 +08:00
use <arc_path.scad>
use <shape_circle.scad>
use <path_extrude.scad>
use <bezier_curve.scad>
use <polyline_join.scad>
use <bspline_curve.scad>
2019-07-12 16:38:49 +08:00
radius1 = 10;
radius2 = 20;
bottom_height = 60;
thickness = 1.5;
t_step = 0.025;
fn = 24;
cut = false; // [true,false]
module klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn) {
$fn = fn;
2019-09-26 08:53:47 +08:00
half_thickness = thickness / 2;
2019-07-12 16:38:49 +08:00
2020-01-23 10:31:37 +08:00
module bottom() {
2019-09-26 08:53:47 +08:00
rotate(180)
rotate_extrude() {
2020-01-23 10:31:37 +08:00
ph1 = arc_path(radius = radius2, angle = [180, 360]);
ph2 = bezier_curve(t_step, [
[radius1 + radius2 * 2, 0, 0],
[radius1 + radius2 * 2, bottom_height * 0.25, 0],
[radius1 + radius2 * 0.5, bottom_height * 0.5, 0],
[radius1, bottom_height * 0.75, 0],
[radius1, bottom_height, 0]
]);
path = concat([for(p = ph1) p + [radius1 + radius2, 0, 0]], ph2);
2019-07-12 16:38:49 +08:00
2021-10-08 09:36:01 +08:00
polyline_join(path)
circle(half_thickness);
2019-07-12 16:38:49 +08:00
}
}
module tube() {
mid_pts = [
2019-10-12 07:45:24 +08:00
[0, 0, bottom_height + radius1 / 2],
2019-07-12 16:38:49 +08:00
[0, 0, bottom_height + radius1],
[0, 0, bottom_height + radius1 * 2],
2019-10-11 20:44:36 +08:00
[0, radius1, bottom_height + radius1 * 3.5],
[0, radius1 * 2.5, bottom_height + radius1 * 3.75],
[0, radius1 * 3.5, bottom_height + radius1 * 3.5],
[0, radius1 * 4.5, bottom_height + radius1 * 2.5],
[0, radius1 * 4.5, bottom_height + radius1],
[0, radius1 * 4.5, bottom_height],
[0, radius1 * 3.5, bottom_height - radius1],
[0, radius1 * 1, bottom_height - radius1 * 2],
[0, radius1 * 0.15, bottom_height + half_thickness - radius1 * 3],
2019-07-12 16:38:49 +08:00
[0, 0, bottom_height - radius1 * 4],
2019-10-12 07:45:24 +08:00
[0, 0, bottom_height - radius1 * 5],
[0, 0, bottom_height - radius1 * 6]
2019-07-12 16:38:49 +08:00
];
2019-10-11 20:44:36 +08:00
degree = 2;
2019-10-12 07:45:24 +08:00
bs_curve = bspline_curve(t_step, degree, mid_pts);
tube_path = [[0, 0, bottom_height], each bs_curve, [0, 0, 0]];
tube_path2 = [[0, 0, bottom_height - thickness], each bs_curve, [0, 0, -thickness]];
2019-07-12 16:38:49 +08:00
difference() {
2019-07-12 16:38:49 +08:00
union() {
bottom();
2020-01-23 10:32:11 +08:00
rotate(-90)
path_extrude(
2020-03-17 14:29:27 +08:00
shape_circle(radius1 + half_thickness),
2019-07-12 16:38:49 +08:00
tube_path
);
}
2020-01-23 10:32:11 +08:00
rotate(-90)
path_extrude(
2020-03-17 14:29:27 +08:00
shape_circle(radius1 - half_thickness),
2019-07-12 16:38:49 +08:00
tube_path2
);
}
}
tube();
}
module cutted_klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn) {
difference() {
union() {
translate([radius2 + thickness, 0, 0])
2019-10-11 18:15:29 +08:00
rotate([0, 90, 0])
klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn);
2019-07-12 16:38:49 +08:00
translate([-radius2 - thickness, 0, 0])
2019-10-11 18:15:29 +08:00
rotate([0, -90, 0])
klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn);
2019-07-12 16:38:49 +08:00
}
h = (radius1 + radius2) * 2;
w = 2 * h;
l = bottom_height * 4;
translate([0, 0, h / 2])
2019-10-11 18:15:29 +08:00
cube([l, w, h], center = true);
2019-07-12 16:38:49 +08:00
}
}
if(cut) {
cutted_klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn);
} else {
klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn);
2019-10-11 18:15:29 +08:00
}