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