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