-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathklein_bottle.scad
110 lines (94 loc) · 3.52 KB
/
klein_bottle.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
use <arc_path.scad>
use <shape_circle.scad>
use <path_extrude.scad>
use <bezier_curve.scad>
use <polyline_join.scad>
use <bspline_curve.scad>
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;
half_thickness = thickness / 2;
module bottom() {
rotate(180)
rotate_extrude() {
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);
polyline_join(path)
circle(half_thickness);
}
}
module tube() {
mid_pts = [
[0, 0, bottom_height + radius1 / 2],
[0, 0, bottom_height + radius1],
[0, 0, bottom_height + radius1 * 2],
[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],
[0, 0, bottom_height - radius1 * 4],
[0, 0, bottom_height - radius1 * 5],
[0, 0, bottom_height - radius1 * 6]
];
degree = 2;
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]];
difference() {
union() {
bottom();
rotate(-90)
path_extrude(
shape_circle(radius1 + half_thickness),
tube_path
);
}
rotate(-90)
path_extrude(
shape_circle(radius1 - half_thickness),
tube_path2
);
}
}
tube();
}
module cutted_klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn) {
difference() {
union() {
translate([radius2 + thickness, 0, 0])
rotate([0, 90, 0])
klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn);
translate([-radius2 - thickness, 0, 0])
rotate([0, -90, 0])
klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn);
}
h = (radius1 + radius2) * 2;
w = 2 * h;
l = bottom_height * 4;
translate([0, 0, h / 2])
cube([l, w, h], center = true);
}
}
if(cut) {
cutted_klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn);
} else {
klein_bottle(radius1, radius2, bottom_height, thickness, t_step, fn);
}