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