chiark / gitweb /
poster-tube-lid-parametric: bugfixes
[reprap-play.git] / earring-stand.scad
1 // -*- C -*-
2
3 include <commitid.scad>
4
5 front_height = 80;
6 front_width = 120;
7 front_setback = 30;
8 front_thick = 2.4;
9
10 front_hex_stride = 12.5;
11 front_hex_dia = 9.5;
12
13 front_hex_y_fudge = -0.65;
14
15 front_surround_lr =3;
16
17 back_thick = 3;
18 back_pillarw = 6;
19
20 base_thick = 2.4;
21
22 eclip_inner_rad = 2.5;
23 eclip_gap_rad = 0.1;
24 eclip_prong_th = 2.25;
25 eclip_outer_strt = 0.5;
26 eclip_inner_xstrt = 0.5;
27
28 eclip_ult_angle = 44;
29 eclip_base_epsilon = 0.5;
30
31 eclip_each_len = 6;
32 eclip_each_every = 29;
33
34 test_alpha = 10;
35 test_main_th = 1.5;
36 test_eclips = 5;
37 test_base_th = 2.5;
38 test_len = eclip_each_len + eclip_each_every*(test_eclips-1);
39
40 num_eclips = 5;
41
42 // calculated
43
44 include <utils.scad>
45
46 eclip_inner_strt = eclip_outer_strt + eclip_inner_xstrt;
47
48 r0 = eclip_inner_rad;
49 r1 = r0 + eclip_gap_rad;
50 r2 = r1 + eclip_prong_th;
51 r2e = r1 + eclip_base_epsilon;
52
53 ppxl = -(r0 / sqrt(2)) + (eclip_inner_strt / sqrt(2));
54
55 rgap = eclip_gap_rad;
56
57 eclip_base_offset = r1;
58 eclip_wall_offset = -ppxl;
59
60 eclip_ra_offset = r2 - 0.1;
61
62 eclip_recept_height = r2;
63
64 eclip_rhs_offset = ppxl + rgap + eclip_prong_th;
65 // does not include main_th
66
67 $fn=70;
68
69 module EclipLPlanCore(alpha){
70   FArcSegment(0,0, r1,r2,
71               180-eclip_ult_angle, eclip_ult_angle-alpha +1);
72
73   difference(){
74     hull(){
75       intersection(){
76         circle(r2);
77         rotate(-alpha) mirror([1,1]) square([r2e, 50]);
78      }
79       rotate(-alpha) mirror([1,1]) square([r2e, r2]);
80     }
81     circle(r1);
82   }
83 }
84
85 module EclipRPlan(alpha, main_th){
86   intersection(){
87     rotate(alpha)
88       translate([ppxl + main_th + rgap, -r2*2])
89       square([eclip_prong_th, r2*(2 + 1/sqrt(2))]);
90     translate([-r2, -r2e])
91       square([r2*3, eclip_base_epsilon + r2*4]);
92   }
93 }
94
95 module EclipLPlan(alpha){
96   rotate(alpha) EclipLPlanCore(alpha);
97 }
98
99 module EclipPPlan(main_th){
100   intersection(){
101     hull(){
102       circle(r0);
103       rotate(90-eclip_ult_angle) square([r0,r0]);
104     }
105     translate([-(r0+.1), -(r0+.1)])
106       square([(r0+.1) + main_th + ppxl, r2*2]);
107   }
108   translate([ppxl, 0]) square([main_th, r2]);
109 }
110
111 module TestBase(){ ////toplevel
112   translate([0,0, eclip_base_offset]){
113     for (i=[1 : 2: test_eclips-2]) {
114       translate([0, i*eclip_each_every])
115         rotate([90,0,0])
116         linear_extrude(height=eclip_each_len)
117         EclipLPlan(test_alpha);
118     }
119     for (j=[0 : 2: test_eclips-1]) {
120       translate([0, j*eclip_each_every])
121         rotate([90,0,0])
122         linear_extrude(height=eclip_each_len)
123         EclipRPlan(test_alpha, test_main_th);
124     }
125   }
126   translate([-r2, -eclip_each_len, -test_base_th]){
127     difference(){
128       cube([r2*2,
129             test_len,
130             test_base_th]);
131       mirror([0,0,1]) Commitid_BestCount_M([r2*2, test_len]);
132     }
133   }
134 }
135
136 module TestProtr(){ ////toplevel
137   difference(){
138     translate([0,0, test_main_th - eclip_wall_offset])
139       rotate([0,90,0])
140       linear_extrude(height=test_len)
141       EclipPPlan(test_main_th);
142     mirror([0,0,1]) Commitid_BestCount_M([test_len, r2]);
143   }
144 }
145
146 module TestRAProtr(){ ////toplevel
147   rotate([-90,0,0]) TestProtr();
148   mirror([1,0,0])
149     translate([-test_len,
150                -r2,
151                -(eclip_ra_offset + test_base_th)])
152     cube([test_len,
153           r2*2,
154           test_base_th]);
155 }
156
157 module TestPlanDemo(){
158   color("red") EclipLPlan(test_alpha);
159   color("blue") rotate(test_alpha) EclipPPlan(test_main_th);
160   color("green") EclipRPlan(test_alpha, test_main_th);
161 }
162
163 beta = asin(front_setback / front_height);
164
165 uf = [-sin(beta), cos(beta)];
166 ur = [ -uf[1], uf[0]];
167
168 pp = [0, 0];
169 pq = pp + uf*front_height + ur*eclip_ra_offset;
170 pr = [ pq[0] - eclip_base_offset - eclip_wall_offset,
171        0 ];
172
173 echo("uf ur P Q R", uf, ur, pp, pq, pr);
174
175 module Sketch(){
176   polygon([pq, pp, pr]);
177 }
178
179 thicks = [ base_thick, front_thick, back_thick ];
180
181 module Joins(alpha, objnum, objnum_f, objnum_m) {
182   pitch = (front_width - eclip_each_len) / (num_eclips-1);
183   
184   thm = thicks[objnum_m];
185   stride = (front_width - eclip_each_len) / (num_eclips-1);
186
187   if (objnum==objnum_f) {
188     for (i=[ 1 : 2 : num_eclips-1 ]) {
189       translate([0, i*stride + eclip_each_len, 0]) {
190         rotate([90,0,0])
191         linear_extrude(height=eclip_each_len)
192           EclipLPlan(alpha);
193       }
194     }
195     for (i=[ 0 : 2 : num_eclips-1 ]) {
196       translate([0, i*stride + eclip_each_len, 0]) {
197         rotate([90,0,0])
198         linear_extrude(height=eclip_each_len)
199           EclipRPlan(alpha, thm);
200       }
201     }
202   }
203   if (objnum==objnum_m)
204     mirror([0,1,0])
205       rotate([90,0,0])
206       linear_extrude(height=front_width)
207       rotate(alpha)
208       EclipPPlan(thm);
209 }
210
211 function r3(pc) = [ pc[0], 0, pc[1] ];
212
213 module ObjectJoins(objnum){
214   translate(r3(pp))                   Joins(beta, objnum, 0,1);
215   translate(r3(pr)) mirror([1,0,0])   Joins(0,    objnum, 0,2);
216   translate(r3(pq)) rotate([0,90,0]) mirror([1,0,0]) Joins(-beta, objnum, 2,1);
217 }
218
219 module Base(){
220   xmin = pr[0] - eclip_rhs_offset - thicks[2];
221   xmax = pp[0] + eclip_rhs_offset + thicks[1]
222     + eclip_prong_th * (1/cos(beta) - 1)
223     + eclip_base_offset * tan(beta);
224   intersection(){
225     ObjectJoins(0);
226     translate([xmin,
227                -1,
228                -50])
229       cube([xmax - xmin,
230             front_width + 2,
231             300]);
232   }
233   translate([xmin,
234              0,
235              -eclip_base_offset - thicks[0]]){
236     difference(){
237       cube([xmax - xmin,
238             front_width,
239           thicks[0]]);
240       translate([xmax-xmin, front_width]/2)
241         rotate([0,0,270])
242         Commitid_Full16_M();
243     }
244   }
245 }
246
247 module FrontPattern(){
248   totalh = front_height - eclip_wall_offset + thicks[1];
249
250   ystride = front_hex_stride;
251   xstride = front_hex_stride * cos(30) * 2;
252
253   difference(){
254     square([front_width, totalh]);
255     translate([ front_surround_lr,
256                 eclip_recept_height ])
257       square([ front_width - front_surround_lr*2,
258                totalh - eclip_recept_height*2
259                ]);
260   }
261     
262   difference(){
263     square([front_width, totalh]);
264     for (xi=[ -5 : 5 ]) {
265       translate([front_width/2 +
266                  xi * xstride,
267                  0]) {
268         for (yi=[ 0 : 10 ]) {
269           //echo(yi);
270           translate([0, yi * ystride +
271                      front_hex_dia*front_hex_y_fudge]) {
272             for (dv=[ [0,0],
273                       [-xstride/2, -ystride/2]
274                       ])
275               translate(dv)
276                 circle(r= front_hex_dia/2, $fn=6);
277           }
278         }
279       }
280     }
281   }
282 }
283
284 module Front(){
285   ObjectJoins(1);
286   rotate([0, 90-beta, 0])
287     translate([0, 0, ppxl])
288     rotate([0,0,90]) {
289     linear_extrude(height=thicks[1])
290       FrontPattern();
291   }
292 }
293
294 module Back(){
295   ObjectJoins(2);
296
297   zmin = pr[1];
298   zmax = pq[1] + eclip_prong_th;
299   height = zmax - zmin;
300
301   translate([pr[0] + eclip_wall_offset - thicks[2],
302              0, 0])
303     rotate([0,90,0])
304     rotate([0,0,90]) {
305     difference(){
306       cube([front_width,
307             height,
308             thicks[2]]);
309       translate([back_pillarw,
310                  eclip_recept_height,
311                  -10])
312         cube([front_width - back_pillarw*2,
313               height - eclip_recept_height*2 - eclip_prong_th,
314               20]);
315     }
316   }
317 }
318
319 module BackPrint(){ ////toplevel
320   rotate([0,-90,0]) Back();
321 }
322
323 module FrontPrint(){ ////toplevel
324   rotate([0, 90+beta, 0]) Front();
325 }
326
327 module BasePrint(){ ////toplevel
328   Base();
329 }
330
331 module Demo(){ ////toplevel
332   color("red") Base();
333   color("blue") Front();
334   color("black") Back();
335 }
336
337 //PlanDemo();
338 //TestBase();
339 //TestProtr();
340 //TestRAProtr();
341 //Sketch();
342 //Demo();
343 //BackPrint();
344 //FrontPrint();
345 //BasePrint();