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