Werner's Miscellanea
Sign in or create your account | Project List | Help
Werner's Miscellanea Git Source Tree
Root/
Source at commit ca5905ae5164aee98575fbf81032e7f4f7e98b6a created 12 years 8 months ago. By root, Merge branch 'master' of git@projects.qi-hardware.com:wernermisc | |
---|---|
1 | #!/usr/bin/perl |
2 | |
3 | use POSIX; |
4 | |
5 | |
6 | $PI = atan2(1, 1)*4; |
7 | $epsilon = 0.02; |
8 | |
9 | $d = 25.4/8; # 1/8" |
10 | $r = $d/2; |
11 | |
12 | |
13 | sub orig |
14 | { |
15 | $x0 = $_[0]; |
16 | $y0 = $_[1]; |
17 | } |
18 | |
19 | |
20 | sub mil |
21 | { |
22 | return $_[0]/1000*25.4; |
23 | } |
24 | |
25 | |
26 | sub cut |
27 | { |
28 | if (defined $x) { |
29 | if ($x == $_[0]+$x0 && $y == $_[1]+$y0) { |
30 | shift @_; |
31 | shift @_; |
32 | } else { |
33 | print "\n"; |
34 | } |
35 | } |
36 | while (@_) { |
37 | $x = shift @_; |
38 | $y = shift @_; |
39 | $x += $x0; |
40 | $y += $y0; |
41 | print "$x $y $z\n"; |
42 | } |
43 | } |
44 | |
45 | |
46 | sub mm |
47 | { |
48 | local ($x, $y, @m) = @_; |
49 | |
50 | return ($x*$m[0]+$y*$m[1], $x*$m[2]+$y*$m[3]); |
51 | } |
52 | |
53 | |
54 | sub a2m |
55 | { |
56 | local ($a) = $_[0]/180*$PI; |
57 | |
58 | return (cos($a), sin($a), -sin($a), cos($a)); |
59 | } |
60 | |
61 | |
62 | sub yarc |
63 | { |
64 | local ($x, $y, $dx, $dy0, $dy1, $r, @m) = @_; |
65 | local ($dy); |
66 | |
67 | $dx = ($dx > 0 ? 1 : -1)*sqrt($r*$r-$dy0*$dy0+$epsilon); |
68 | $dy = $dy0; |
69 | |
70 | while (1) { |
71 | if ($dy0 < $dy1) { |
72 | last if $dy >= $dy1-$epsilon; |
73 | } else { |
74 | last if $dy <= $dy1+$epsilon; |
75 | } |
76 | print $x+$dx, " ", $y+$dy, " ", $z, "\n"; |
77 | ($dx, $dy) = &mm($dx, $dy, @m); |
78 | } |
79 | } |
80 | |
81 | |
82 | sub circ |
83 | { |
84 | local ($x, $y, $r, $n) = @_; |
85 | local ($a, $dx, $dy); |
86 | |
87 | for ($a = 0; $a <= 2*$PI+$epsilon; $a += 2*$PI/$n) { |
88 | $dx = $r*sin($a); |
89 | $dy = $r*cos($a); |
90 | print $x+$dx, " ", $y+$dy, " ", $z, "\n"; |
91 | } |
92 | } |
93 | |
94 | |
95 | # |
96 | # general shape: |
97 | # |
98 | # <------ 150 ------> |
99 | # +-------------------+ |
100 | # | | ^ |
101 | # | () () () () () () | | |
102 | # | () () () () () () | | 93 |
103 | # | () () () () () () | | |
104 | # | () () () () () () | | |
105 | # | | v |
106 | # +-------------------+ |
107 | # |
108 | |
109 | |
110 | # start depth |
111 | $z0 = -0.5; |
112 | |
113 | # floor depth |
114 | $zf = -18; |
115 | |
116 | # maximum depth step |
117 | $zs = 2.5; |
118 | |
119 | # distance between columns |
120 | $xs = 24; |
121 | |
122 | # distance between vial centers within columns |
123 | $ys = 20; |
124 | |
125 | # vial diameter |
126 | $vd = 18.7; |
127 | |
128 | # minimum wall thickness |
129 | $mw = 2.5; |
130 | |
131 | $nc = 6; |
132 | $nr = 4; |
133 | |
134 | |
135 | @m_cw = &a2m(1); |
136 | @m_ccw = &a2m(-1); |
137 | |
138 | # vial hole radius |
139 | $vr = $vd/2; |
140 | |
141 | # circle radii: first, last, increment |
142 | $r0 = $r/2; |
143 | $r1 = $vr-$r*1.5; |
144 | $rs = $r*0.75; |
145 | |
146 | # |
147 | # x offset at which the vial bay stops |
148 | # |
149 | |
150 | $t = $ys/2-$mw/2; |
151 | $xo = sqrt($vr*$vr-$t*$t); |
152 | |
153 | # |
154 | # radius of the arcs connecting vial bays |
155 | # |
156 | $br = $vr*($mw/2)/$t; |
157 | |
158 | # x offset of the center of the arcs connecting vial bays |
159 | # |
160 | #$bx = $xo+sqrt($br*$br-($mw/2)*($mw/2)); |
161 | $bx = $xo+$xo*($mw/2)/$vr; |
162 | |
163 | print STDERR "t = $t\n"; |
164 | print STDERR "xo = $xo\n"; |
165 | print STDERR "br = $br\n"; |
166 | print STDERR "bx = $bx\n"; |
167 | |
168 | # adjust the z step |
169 | |
170 | $nz = POSIX::ceil(($z0-$zf)/$zs); |
171 | $zs = ($z0-$zf)/$nz; |
172 | |
173 | print STDERR "nz = $nz\n"; |
174 | print STDERR "zs = $zs\n"; |
175 | |
176 | print STDERR "r0 = $r0\n"; |
177 | print STDERR "r1 = $r1\n"; |
178 | print STDERR "rs = $rs\n"; |
179 | |
180 | |
181 | sub do_col |
182 | { |
183 | local ($x0) = @_; |
184 | local ($rw, $end); |
185 | |
186 | for ($rw = 0; $rw != $nr; $rw++) { |
187 | if ($rw) { |
188 | $end = $rw == $nr-1 ? $vr : ($ys-$mw)/2; |
189 | &yarc($x0-$bx, $y0-$ys/2, |
190 | 1, -$mw/2-$r, $mw/2+$r, $br+$r, @m_ccw); |
191 | &yarc($x0, $y0, |
192 | -1, -($ys-$mw)/2+$r, $end-$r, $vr-$r, @m_cw); |
193 | } else { |
194 | &yarc($x0, $y0, |
195 | 1, -$vr+$r, ($ys-$mw)/2-$r, $vr-$r, @m_cw); |
196 | } |
197 | $y0 += $ys; |
198 | } |
199 | for ($rw = 0; $rw != $nr; $rw++) { |
200 | $y0 -= $ys; |
201 | if ($rw) { |
202 | $end = $rw == $nr-1 ? $vr : ($ys-$mw)/2; |
203 | &yarc($x0+$bx, $y0+$ys/2, |
204 | -1, $mw/2+$r, -$mw/2-$r, $br+$r, @m_ccw); |
205 | &yarc($x0, $y0, |
206 | 1, ($ys-$mw)/2-$r, -$end+$r, $vr-$r, @m_cw); |
207 | } else { |
208 | &yarc($x0, $y0, |
209 | 1, $vr-$r, -($ys-$mw)/2+$r, $vr-$r, @m_cw); |
210 | } |
211 | } |
212 | } |
213 | |
214 | |
215 | sub do_cols |
216 | { |
217 | local ($c, $x); |
218 | |
219 | $x = $x0; |
220 | for ($c = 0; $c != $nc; $c++) { |
221 | &do_col($x); |
222 | $x += $xs; |
223 | print "\n"; |
224 | } |
225 | } |
226 | |
227 | |
228 | sub do_circles |
229 | { |
230 | local ($c, $rw, $x, $y); |
231 | local ($rr); |
232 | |
233 | $x = $x0; |
234 | for ($c = 0; $c != $nc; $c++) { |
235 | $y = $y0; |
236 | for ($rw = 0; $rw != $nr; $rw++) { |
237 | for ($rr = $r0; $rr <= $r1; $rr += $rs) { |
238 | &circ($x, $y, $rr, 180); |
239 | } |
240 | print "\n"; |
241 | $y += $ys; |
242 | } |
243 | $x += $xs; |
244 | } |
245 | } |
246 | |
247 | |
248 | ($x0, $y0) = (5+$ys/2, 6.5+$ys/2); |
249 | |
250 | $z = $z0; |
251 | for ($i = 0; $i != $nz; $i++) { |
252 | # print "#%%r_tool=0\n"; |
253 | &do_circles; |
254 | |
255 | # print "#%%r_tool=", $r, "\n"; |
256 | &do_cols; |
257 | |
258 | $z -= $zs; |
259 | } |
260 |
Branches:
master