chiark / gitweb /
fairphone-case: ButtonPlan: wip fix height
[reprap-play.git] / fairphone-case.scad
1 // -*- C -*-
2
3 phone_height = 146.5 - .80;
4 phone_width = 76.75;
5
6 phone_cnr_rad = 6.0;
7
8 button_cutout_depth = 9;
9
10 phone_edge_thick = 9.0;
11 phone_total_thick = 12.0;
12 phone_backside_slope_inner = 1.5; // larger means shallower
13 phone_backside_slope_outer = 1.0; // larger means shallower
14
15 camera_pos_tl = [  7.0, 13.0 ]; // measured from tl corner
16 camera_pos_br = [ 24.0, 39.5 ]; // tl/br as seen from back
17
18 case_th_bottom = 2.5;
19 case_th_lid = 2.5;
20 case_th_side = 2;
21 case_th_lip = 1.2;
22
23 case_struts_count = 6;
24 case_struts_solid_below = 0.75;
25 case_struts_solid_above = 1.00;
26 case_struts_width = 0.10;
27
28 keeper_th_z = 0.75;
29 keeper_th_x = 0.75;
30 keeper_inner_width = 1.75;
31 keeper_inner_height = 1.75;
32
33 keeper_gap_z_top = 0.25;
34 keeper_gap_z_bot = 0.75;
35 keeper_gap_x     = 0.25;
36 keeper_gap_x_holes = 0.75;
37
38 case_lip = 1.25;
39
40 lid_gap_x = 0.25;
41 lid_gap_z = 0.25;
42 lid_lip = 1.75;
43
44 $fa = 5;
45 $fs = 0.1;
46
47 // ---------- calculated ----------
48
49 // ----- could be changed -----
50 lid_buttoncover_gap = lid_gap_x;
51 lid_buttoncover_overlap = case_th_lip + keeper_gap_z_top;
52
53 phone_backside_slope_thick = phone_total_thick - phone_edge_thick;
54
55 //lid_lip_overlap_width xxx bad name = ;
56 //lid_lip_inner_slope = [ 5, 5 ]; // xxx
57
58 epp0 = [0,0];
59 epp1 = [0, -phone_edge_thick];
60 epp2i = epp1 + phone_backside_slope_thick * [ phone_backside_slope_inner, -1 ];
61 epp2o = epp1 + phone_backside_slope_thick * [ phone_backside_slope_outer, -1 ];
62 epp3 = epp2i + [10, 0];
63 epp5 = epp0 + [0,1] * (keeper_th_z + keeper_gap_z_top + case_lip);
64 epp4 = epp5 + [-1,0] * case_th_side;
65
66 kppe = [0,0];
67 kppd = kppe + [1,0] * keeper_inner_width;
68 kppc = kppd + [0,1] * keeper_th_z;
69 kppb = [ kppe[0] - keeper_th_x, kppc[1] ];
70 kppf = kppe - [0,1] * keeper_inner_height;
71 kppa = [ kppb[0], kppf[1] ];
72
73 lpp10 = [ epp5[0] + lid_gap_x, kppc[1] + lid_gap_z ];
74 lpp11 = [ lpp10[0],            epp5[1] + lid_gap_z ];
75 lpp12 = [ epp4[0] + lid_lip,   lpp11[1] ];
76 lpp13 = [ lpp12[0],            lpp12[1] + lid_lip ];
77
78 // button profile
79 bppM = epp4 + [0,5];
80 bppN = [ 0.5 * (epp0[0] + epp4[0]), bppM[1] ];
81 bppR = [ bppN[0] + lid_buttoncover_gap, -button_cutout_depth ];
82 bppS = [ epp1[0], bppR[1] ];
83 bppQ = [ bppM[0], bppR[1] - lid_buttoncover_overlap ];
84 bppP = bppQ + [0,1] * lid_buttoncover_gap;
85 bppO = [ bppN[0], bppP[1] ];
86 bppL = lpp10 + [5,0];
87 bppK = [ bppL[0], bppN[1] ];
88 bppJ = [ bppN[0], bppL[1] ];
89
90 module rectfromto(a,b) {
91   ab = b - a;
92   translate([min(a[0], b[0]), min(a[1], b[1])])
93     square([abs(ab[0]), abs(ab[1])]);
94 }
95 module circleat(c,r) { translate(c) circle(r); }
96
97 module KeeperProfile(){
98   polygon([kppe, kppd, kppc, kppb, kppa, kppf]);
99 }
100
101 module EdgeProfile(){
102   difference(){
103     hull(){
104       translate(epp3) square(case_th_bottom*2, center=true);
105       circleat(epp2o, r=case_th_bottom);
106       circleat(epp1, r=case_th_side);
107       rectfromto(epp0, epp4);
108     }
109     polygon([ epp5 + [0,10],
110               epp1,
111               epp2i,
112               epp3 + [10,0] ]);
113   }
114 }
115
116 module LidEdgeProfile(){
117   polygon([ lpp10,
118             lpp11,
119             lpp12,
120             lpp13,
121             lpp13 + [10, 0],
122             lpp10 + [10, 0]
123             ]);
124   intersection(){
125     circleat(lpp12, r=lid_lip);
126     rectfromto( lpp12 + [-10,   0],
127                 lpp12 + [+10, +10] );
128   }
129 }
130
131 module ButtonCoverProfile(){
132   intersection(){
133     polygon([ bppM, bppP, bppO, bppJ, bppL, bppK ]);
134     hull(){
135       EdgeProfile();
136       LidEdgeProfile();
137     }
138   }
139 }
140
141 module ButtonPlan(l, deep, cut){
142   bigger =
143     (deep ? lid_buttoncover_overlap : 0) +
144     (cut  ? lid_buttoncover_gap     : 0);
145
146   d_D1_y =
147     (cut  ? 0 : lid_buttoncover_gap);
148
149   C = [0,0]; // by definition
150   T = [ 0, epp4[1] ];
151   G = T + [0,10];
152   B0 = C + [0,-1] * button_cutout_depth;
153   r0 = 0.5 * (T[1] - B0[1]);
154   A = [  -l/2 + r0, 0.5 * (T[1] + B0[1]) ];
155   r1 = r0 + bigger;
156   // | D1 - A | = r1 * 2
157   // D1_y = T_y - r1 + d_D1_y
158   // =>    4 * r1^2   =  (r1-r0 + d_D1_y)^2 + (D1_x - A_x)^2
159   // =>    D1_x =  A_x + v/~ [  4 * r1^2   -   (r1-r0 + d_D1_y)^2 ]
160   D1  = [ A[0] + sqrt( 4*r1*r1 - pow(bigger + d_D1_y, 2) ),
161           T[1] - r1 + d_D1_y ];
162   E1  = 0.5 * (D1 + A);
163   F1  = D1 + [0,10];
164
165   hull(){
166     for (m=[0,1]) mirror([m,0])
167       circleat(A, r1);
168   }
169   for (m=[0,1]) mirror([m,0]) {
170     difference(){
171       polygon([ E1,
172                 A,
173                 B0,
174                 G,
175                 F1,
176                 D1
177                 ]);
178       circleat(D1, r1);
179     }
180   }
181 }
182
183 module CaseBase_rhsflip(yn=[0,1]) {
184   for (rhs=yn) {
185     translate([phone_width/2, 0, 0])
186       mirror([rhs,0,0])
187       translate([-phone_width/2, 0, 0])
188       children();
189   }
190 }
191
192 module CaseBase_botflip() {
193   for (bot=[0,1]) {
194     translate([0, -phone_height/2, 0])
195       mirror([0, bot, 0])
196       translate([0, phone_height/2, 0])
197       children();
198   }
199 }  
200
201 module AroundEdges(fill_zstart, fill_th, fill_downwards=0){
202   // sides
203   CaseBase_rhsflip(){
204     translate([0, -phone_cnr_rad, 0])
205       rotate([90,0,0])
206       linear_extrude(height = phone_height - phone_cnr_rad*2)
207       children(0);
208   }
209   // corners
210   CaseBase_rhsflip() CaseBase_botflip() {
211     translate([+1,-1] * phone_cnr_rad)
212       intersection(){
213         rotate_extrude()
214           intersection(){
215             mirror([1,0,0])
216               translate([-1,0] * phone_cnr_rad)
217               children(0);
218             rectfromto([0,-20],[10,20]);
219           }
220         translate([-10, 0, -20] + 0.01 * [+1,-1, 0] )
221           cube([10,10,40]);
222       }
223   }
224   // top and bottom
225   CaseBase_botflip(){
226     translate([ phone_width - phone_cnr_rad, 0,0 ])
227       rotate([90,0,-90])
228       linear_extrude(height = phone_width - phone_cnr_rad*2)
229       children(0);
230   }
231   // fill
232   translate([0,0, fill_zstart])
233     mirror([0,0, fill_downwards])
234     linear_extrude(height = fill_th)
235     rectfromto([+1,-1] * phone_cnr_rad,
236                [phone_width, -phone_height] + [-1,+1] * phone_cnr_rad);
237 }
238
239 module CaseBase(){
240   AroundEdges(epp3[1], case_th_bottom, 1)
241     EdgeProfile();
242 }
243
244 module Case(){ ////toplevel
245   difference(){
246     union(){
247       CaseBase();
248
249       // ledge (fixed keeper)
250       intersection(){
251         rotate([90, 0, 0])
252           linear_extrude(height = phone_height + phone_cnr_rad * 2)
253           KeeperProfile();
254
255         // outline of the whole case, to stop it protruding
256         translate([0,0, -25])
257           linear_extrude(height = 50)
258           hull()
259           // CaseBase_rhsflip() // actually, we only care about the LH
260           CaseBase_botflip()
261           circleat([+1,-1] * phone_cnr_rad, phone_cnr_rad + case_th_side/2);
262       }
263     }
264
265     // slot for keeper
266     CaseBase_rhsflip(1)
267       translate([0, -phone_cnr_rad, 0])
268       rotate([90, 0, 0])
269       linear_extrude(height = phone_height + phone_cnr_rad * 2)
270       minkowski(){
271         KeeperProfile();
272         rectfromto([ -keeper_gap_x,    -keeper_gap_z_bot ],
273                    [ keeper_gap_x_holes,    +keeper_gap_z_top ]);
274       }
275
276     // front camera
277     CaseBase_rhsflip([1])
278       mirror([0, 0, 1])
279       linear_extrude(height = 20)
280       mirror([0, 1, 0])
281       rectfromto(camera_pos_tl, camera_pos_br);
282
283     // struts (invisible, because they're buried in the case)
284     for (i= [1 : 1 : case_struts_count]) {
285       translate([0,
286                  -phone_height * i / (case_struts_count+1),
287                  epp2i[1] - case_th_bottom + case_struts_solid_below])
288         linear_extrude(height= case_th_bottom
289                        -(case_struts_solid_below+case_struts_solid_above))
290         rectfromto([               epp2i[0], -0.5 * case_struts_width ],
291                    [ phone_width - epp2i[0], +0.5 * case_struts_width ]);
292     }
293   }
294 }
295
296 module Lid(){ ////toplevel
297   AroundEdges(lpp10[1], lpp13[1] - lpp10[1], 0)
298     LidEdgeProfile();
299 }
300
301 module TestLength(){ ////toplevel
302   intersection(){
303     Case();
304     translate([-30, -200, -20])
305     cube([30 + 15, 250, 40]);
306   }
307 }
308
309 module TestWidth(){ ////toplevel
310   intersection(){
311     Case();
312     translate([-30, -(phone_height - 25), -20])
313       mirror([0, 1, 0])
314       cube([200, 50, 40]);
315   }
316 }
317
318 module TestLidWidthPrint(){ ////toplevel
319   rotate([0,180.0])
320     intersection(){
321       Lid();
322       translate([-30, -(phone_height - 25), -20])
323         mirror([0, 1, 0])
324         cube([200, 50, 40]);
325     }
326 }
327
328 module TestCamera(){ ////toplevel
329   intersection(){
330     Case();
331     CaseBase_rhsflip(1)
332       translate([0,0,-25])
333       linear_extrude(height = 50)
334       mirror([0, 1, 0])
335       rectfromto([-20, -20],
336                  camera_pos_br + [ 5, 5 ]);
337   }
338 }
339
340 module OneKeeper(){ ////toplevel
341   translate([0, -phone_cnr_rad, 0])
342     rotate([90, 0, 0])
343     linear_extrude(height = phone_height - phone_cnr_rad * 2)
344     KeeperProfile();
345 }
346
347 module OneKeeperPrint(){ ////toplevel
348   rotate([0,180,0])
349     OneKeeper();
350 }
351
352 module Keeper(){ ////toplevel
353   CaseBase_rhsflip()
354     OneKeeper();
355 }
356
357 module ButtonPlanForDemo(colour, z, deep, cut){
358   color(colour)
359     translate([0,0,z])
360     ButtonPlan(8, deep, cut);
361 }
362
363 module DemoProfiles(){ ////toplevel
364   LidEdgeProfile();
365   %EdgeProfile();
366   KeeperProfile();
367
368   translate([20,0]) {
369     LidEdgeProfile();
370     %EdgeProfile();
371
372     demopoint_QR = [ bppS[0], bppQ[1] - 0.1];
373   
374     color("blue") ButtonCoverProfile();
375     color("red") {
376       rectfromto(bppQ, demopoint_QR);
377       rectfromto(bppR, demopoint_QR);
378     }
379   }
380
381   translate([-20,0]) {
382     ButtonPlanForDemo("blue",    0, 0,0);
383     ButtonPlanForDemo("red",    -1, 0,1);
384     ButtonPlanForDemo("yellow", -2, 1,0);
385     ButtonPlanForDemo("blue",   -3, 1,1);
386   }
387 }
388
389 //EdgeProfile();
390 //KeeperProfile();
391 //CaseBase();
392 //%Case();
393 //Keeper();
394 //LidEdgeProfile();
395 //KeeperProfile();
396 //DemoProfiles();