-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgeometry.scad
74 lines (66 loc) · 1.94 KB
/
geometry.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
module arc(a=90, r1=1, r2=1, h=1, center=false) {
translate(-[0, 0, center ? h/2 : 0])
difference() {
cylinder(r=r1, h=h, center=center);
translate([0, 0, -.1]) {
cylinder(r=r2, h=h+0.2);
translate([-r1-0.1, -r1-0.1, 0]) cube([r1*2+.1, r1+.1, h+0.2]);
rotate([0, 0, -180+a]) translate([-r1-0.1, -r1-0.1, 0]) cube([r1*2+.1, r1+.1, h+0.2]);
}
}
}
module truncated_sphere(r=undef, d=undef, rr=0.8) {
radius = is_undef(r) ? (is_undef(d) ? 2 : d / 2) : r;
difference() {
rotate([0, 90, 0]) sphere(radius);
translate([-radius, 0, 0]) cube([(1 - rr) * radius, radius, radius] * 2, center=true);
translate([+radius, 0, 0]) cube([(1 - rr) * radius, radius, radius] * 2, center=true);
}
}
module lobed_cylinder(radius, h=2) {
lobes = 6;
translate([0, 0, h/2])
difference() {
$fn=24;
hull()
for (i=[1:lobes]) {
rotate([0, 0, i*360/lobes])
translate([radius, 0, 0]) {
cylinder(r=radius/5, h=h-1, center=true);
cylinder(r=0.8*radius/5, h=h, center=true);
}
}
for (i=[1:lobes]) {
rotate([0, 0, (i-0.5)*360/lobes])
translate([9/5*radius, 0, 0]) {
cylinder(r=0.825*radius, h=h+0.1, center=true, $fn=76);
translate([0, 0, h/2]) cylinder(r1=0.825*radius, r2=1.2*0.825*radius, h=1, center=true, $fn=76);
translate([0, 0, -h/2]) cylinder(r2=0.825*radius, r1=1.2*0.825*radius, h=1, center=true, $fn=76);
}
}
}
}
function l (t, s) = (
let(cos4t=pow(cos(t), s))
let(sin4t=pow(sin(t), s))
let(rho=1/pow(cos4t + sin4t, 1/s))
[
rho * cos(t),
rho * sin(t)
]
);
function make_squircle(r=1, s=5, steps=40) = (
let(quadrant = concat([
for (t=[0:steps/4])
l(t/(steps/4)*90, s) * r
], [[0, r]]))
concat(
quadrant,
[ for (p=quadrant) [-p.x, p.y] ],
[ for (p=quadrant) [-p.x, -p.y] ],
[ for (p=quadrant) [ p.x, -p.y] ]
)
);
module squircle(r=1, s=5, steps=40) {
polygon(make_squircle(r, s, steps));
}