-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathroundcylinders.scad
More file actions
66 lines (57 loc) · 1.79 KB
/
roundcylinders.scad
File metadata and controls
66 lines (57 loc) · 1.79 KB
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
$fn=100;
module rcylinder(h = 1, r1 = 1, r2 = 1, center = false, radius = 1, debug = false, radius1, radius2) {
// define all values
radius1 = radius1 == undef ? radius : radius1;
radius2 = radius2 == undef ? radius : radius2;
function angle(h, r) = atan2(h, r);
function differenceSquareX(radius, angle) = (radius / (tan(angle / 2)));
function differenceSquareY(differenceSquareX, angle) = differenceSquareX * cos(90 - angle);
module rCylinderFactory(h, r1, r2, center, radius1, radius2) {
union() {
difference() {
cylinder(h = h, r1 = r1, r2 = r2, center = center);
if (radius1 > 0) {
roundEdge(h, r1, r2, radius1);
}
if (radius2 > 0) {
translate([0,0,h]) {
rotate([0,180,0]) {
roundEdge(h, r2, r1, radius2);
}
}
}
}
}
}
module roundEdge(h, rThis, rOther, radius, convexity = 10) {
a = angle (h, rThis - rOther);
dSX = differenceSquareX(radius, a);
dSY = differenceSquareY(dSX, a);
// if round edge is smaller than cylinder radius
if (rThis - dSX >= 0) {
// make a round edge
_stdRoundEdge(rThis, radius, convexity, dSX, dSY);
} else {
// put a sphere on top of the cylinder instead of a round edge
// _sphereRoundEdge();
}
}
module _stdRoundEdge(rThis, radius, convexity = 10, dSX, dSY) {
rotate_extrude(convexity = convexity) {
translate([rThis - dSX, radius, 0]) {
difference() {
translate([(dSX + 1)/2, ((dSY - 1)/2) - radius, 0]) {
square([dSX + 1, dSY + 1], center = true);
}
circle(r = radius);
}
}
}
}
if(debug) {
cylinder(h = h, r1 = r1, r2 = r2, center = center);
} else {
rCylinderFactory(h = h, r1 = r1, r2 = r2, center = center, radius1 = radius1, radius2 = radius2);
}
}
rcylinder(h=25, r1=3, r2=8, radius1 = 2, radius2 = 4, center=false, debug=false);