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