-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathr_gauge.scad
79 lines (59 loc) · 2.26 KB
/
r_gauge.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
/*
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>
*/
// range for the gauge to follow
radii = [ for (i = [2 : 16]) i ];
// rendering
r_gauge(radii);
// modules
module r_gauge(radii) {
/*
create a gauge for a specific set of radii
*/
// gauge dimensions
// TODO: scale this based on the radii?
disk_r = 75;
hgt = 3;
// figure some stuff out
count = len(radii);
sum = add(radii);
// bring disk to the top of the xy plane
translate([0,0,hgt/2])
// create the gauge
difference() {
// main disk
cylinder(h=hgt, r=disk_r, center=true);
// remove center hole
cylinder(h=hgt*2, r=disk_r/4, center=true);
// remove all the radii and imprint text labels
for (i=[0:count-1]) {
rotate([0,0,(345*sum_to_index(radii, i+1)/sum)]) {
translate([disk_r,0,0])
rotate([0,0,180])
cywtangents(h=hgt*2, r=radii[i], center=true,a=40);
translate([disk_r*.75,-2,hgt/2])
rotate([0,0,90])
linear_extrude(hgt)
text(str(radii[i]), size=5, font="Courier:style=Bold", halign="Right");
}
}
}
}
module cywtangents(h, r, center, a) {
union() {
cylinder(h=h, r=r, center=center);
rotate([0,0,a])
translate([r/2,r,0])
cube([r,2*r,h], center=center);
rotate([0,0,-1*a])
translate([r/2,-r,0])
cube([r,2*r,h], center=center);
}
}
module test(radii) {
echo(a=sum_to_index(radii, len(radii)));
}
function add(array, i=0, r=0) = sum_to_index(array, len(array), i, r);
function sum_to_index(array, m, i=0, r=0) = (i < len(array) && i < m) ? sum_to_index(array, m, i+1, r+array[i]) : r;