forked from JustinSDK/dotSCAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stick_tower.scad
83 lines (67 loc) · 2.06 KB
/
stick_tower.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
use <line3d.scad>;
/* [Basic] */
stick_leng = 80;
stick_thickness = 5;
inner_square_leng = 60;
leng_diff = 1.75;
min_leng = 13;
stick_fn = 24;
/* [Advanced] */
cap_style = "CAP_CIRCLE"; // [CAP_BUTT, CAP_CIRCLE, CAP_SPHERE]
angle_offset = 5;
layer_offset = 1.2;
module stick_square(inner_square_leng, stick_leng, stick_thickness, cap_style) {
diff_leng = stick_leng - inner_square_leng;
half_inner_square_leng = inner_square_leng / 2;
half_stick_leng = stick_leng / 2;
module stick() {
line3d(
[0, -half_stick_leng, 0],
[0, half_stick_leng, 0],
stick_thickness,
cap_style,
cap_style
);
}
module sticks() {
translate([-half_inner_square_leng, 0, 0])
stick();
translate([half_inner_square_leng, 0, 0])
stick();
}
sticks();
translate([0, 0, stick_thickness])
rotate(90)
sticks();
}
module spiral_stack(orig_leng, orig_height, current_leng, leng_diff, min_leng, angle_offset, pre_height = 0, i = 0) {
if(current_leng > min_leng) {
angle = atan2(leng_diff, current_leng - leng_diff);
factor = current_leng / orig_leng;
translate([0, 0, pre_height])
scale(factor)
children();
next_square_leng = sqrt(pow(leng_diff, 2) + pow(current_leng - leng_diff, 2));
height = factor * orig_height + pre_height;
rotate(angle + angle_offset)
spiral_stack(
orig_leng,
orig_height,
next_square_leng,
leng_diff,
min_leng,
angle_offset,
height,
i + 1
) children();
}
}
height = stick_thickness * layer_offset;
$fn = stick_fn;
spiral_stack(inner_square_leng, stick_thickness * 2, inner_square_leng, leng_diff, min_leng, angle_offset)
stick_square(
inner_square_leng,
stick_leng,
height,
cap_style
);