chiark / gitweb /
c6b813bf0bb67711db4307fe451c631aee13e5b8
[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 $fn=70;
51
52 module EclipLPlanCore(alpha){
53   FArcSegment(0,0, r1,r2,
54               180-eclip_ult_angle, eclip_ult_angle-alpha +1);
55
56   difference(){
57     hull(){
58       intersection(){
59         circle(r2);
60         rotate(-alpha) mirror([1,1]) square([r2e, 50]);
61      }
62       rotate(-alpha) mirror([1,1]) square([r2e, r2]);
63     }
64     circle(r1);
65   }
66 }
67
68 module EclipRPlan(alpha, main_th){
69   intersection(){
70     rotate(alpha)
71       translate([ppxl + main_th + rgap, -r2*2])
72       square([eclip_prong_th, r2*(2 + 1/sqrt(2))]);
73     translate([-r2, -r2e])
74       square([r2*3, eclip_base_epsilon + r2*4]);
75   }
76 }
77
78 module EclipLPlan(alpha){
79   rotate(alpha) EclipLPlanCore(alpha);
80 }
81
82 module EclipPPlan(main_th){
83   intersection(){
84     hull(){
85       circle(r0);
86       rotate(90-eclip_ult_angle) square([r0,r0]);
87     }
88     translate([-(r0+.1), -(r0+.1)])
89       square([(r0+.1) + main_th + ppxl, r2*2]);
90   }
91   translate([ppxl, 0]) square([main_th, r2]);
92 }
93
94 module TestBase(){ ////toplevel
95   translate([0,0, eclip_base_offset]){
96     for (i=[1 : 2: test_eclips-2]) {
97       translate([0, i*eclip_each_every])
98         rotate([90,0,0])
99         linear_extrude(height=eclip_each_len)
100         EclipLPlan(test_alpha);
101     }
102     for (j=[0 : 2: test_eclips-1]) {
103       translate([0, j*eclip_each_every])
104         rotate([90,0,0])
105         linear_extrude(height=eclip_each_len)
106         EclipRPlan(test_alpha, test_main_th);
107     }
108   }
109   translate([-r2, -eclip_each_len, -test_base_th]){
110     difference(){
111       cube([r2*2,
112             test_len,
113             test_base_th]);
114       mirror([0,0,1]) Commitid_BestCount_M([r2*2, test_len]);
115     }
116   }
117 }
118
119 module TestProtr(){ ////toplevel
120   difference(){
121     translate([0,0, test_main_th - eclip_wall_offset])
122       rotate([0,90,0])
123       linear_extrude(height=test_len)
124       EclipPPlan(test_main_th);
125     mirror([0,0,1]) Commitid_BestCount_M([test_len, r2]);
126   }
127 }
128
129 module TestRAProtr(){ ////toplevel
130   rotate([-90,0,0]) TestProtr();
131   mirror([1,0,0])
132     translate([-test_len,
133                -r2,
134                -(eclip_ra_offset + test_base_th)])
135     cube([test_len,
136           r2*2,
137           test_base_th]);
138 }
139
140 module TestPlanDemo(){
141   color("red") EclipLPlan(test_alpha);
142   color("blue") rotate(test_alpha) EclipPPlan(test_main_th);
143   color("green") EclipRPlan(test_alpha, test_main_th);
144 }
145
146 beta = asin(front_setback / front_height);
147
148 uf = [-sin(beta), cos(beta)];
149 ur = [-uf[0], uf[1]];
150
151 pp = [0, 0];
152 pq = pp + uf*front_height + ur*eclip_ra_offset;
153 pr = [ pq[0] - eclip_base_offset + eclip_wall_offset, 0 ];
154
155 module Sketch(){
156   polygon([pq, pp, pr]);
157 }
158
159 thicks = [ 2, 2, 2 ];
160
161 module Joins(alpha, objnum, objnum_f, objnum_m) {
162   pitch = (front_width - eclip_each_len) / (num_eclips-1);
163   
164   echo("Joins",objnum, objnum_f, objnum_m);
165   thm = thicks[objnum_m];
166   stride = (front_width - eclip_each_len) / (num_eclips-1);
167
168   if (objnum==objnum_f) {
169     for (i=[ 0 : 2 : num_eclips-1 ]) {
170       translate([0, i*stride, 0]) {
171         rotate([90,0,0])
172         linear_extrude(height=eclip_each_len)
173           EclipLPlan(alpha);
174       }
175     }
176     for (i=[ 1 : 2 : num_eclips-1 ]) {
177       translate([0, i*stride, 0]) {
178         rotate([90,0,0])
179         linear_extrude(height=eclip_each_len)
180           EclipRPlan(alpha, thm);
181       }
182     }
183   }
184 //  if (objnum==objnum_m)
185 //    rotate(alpha)
186 //      EclipPPlan(thm);
187 }
188
189 function r3(pc) = [ pc[0], 0, pc[1] ];
190
191 module ObjectJoins(objnum){
192   echo("Object",objnum);
193   translate(r3(pp))                   Joins(beta, objnum, 0,1);
194   translate(r3(pr)) mirror([1,0,0])   Joins(0,    objnum, 0,2);
195   translate(r3(pq)) rotate([0,-90,0]) Joins(beta, objnum, 2,1);
196 }
197
198 module Base(){
199   ObjectJoins(0);
200 }
201
202 module Front(){
203   ObjectJoins(1);
204 }
205
206 module Back(){
207   ObjectJoins(2);
208 }
209
210 module Demo(){
211   Base();
212   Front();
213   Back();
214 }
215
216 //PlanDemo();
217 //TestBase();
218 //TestProtr();
219 //TestRAProtr();
220 //Sketch();
221 Demo();