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