-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathsierpinski_pyramid.scad
43 lines (36 loc) · 1.17 KB
/
sierpinski_pyramid.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
use <polyline_join.scad>
side_leng = 100;
min_leng = 5;
diameter = 2.5;
sierpinski_pyramid(side_leng, min_leng, diameter, $fn = 4);
module sierpinski_pyramid(side_leng, min_leng, diameter) {
pyramid_frame(side_leng, diameter);
if(side_leng > min_leng){
half_leng = side_leng / 2;
h = half_leng * 0.707107;
pt = [side_leng / 4, side_leng / 4, 0];
for(i=[0:3]) {
rotate([0, 0, i * 90])
translate(pt)
sierpinski_pyramid(half_leng, min_leng, diameter);
}
translate([0, 0, h])
sierpinski_pyramid(half_leng, min_leng, diameter);
}
}
module pyramid_frame(side_leng, diameter) {
half_leng = side_leng / 2;
h = half_leng * 1.414214;
tri_pts = [[0, 0, h], [half_leng, half_leng, 0], [half_leng, -half_leng, 0], [0, 0, h]];
line_pts = [[half_leng, half_leng, 0], [-half_leng, half_leng, 0]];
polyline_join(tri_pts)
sphere(d = diameter);
mirror([1, 0, 0])
polyline_join(tri_pts)
sphere(d = diameter);
polyline_join(line_pts)
sphere(d = diameter);
mirror([0, 1, 0])
polyline_join(line_pts)
sphere(d = diameter);
}