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