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