chiark / gitweb /
fairphone-case: strengthen (from v1)
[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 phone_edge_thick = 9.0;
9 phone_total_thick = 12.0;
10 phone_backside_slope = 1.0; // larger means shallower
11
12 camera_pos_tl = [  7.0, 13.0 ]; // measured from tl corner
13 camera_pos_br = [ 24.0, 39.5 ]; // tl/br as seen from back
14
15 case_th_bottom = 2.5;
16 case_th_lid = 2.5;
17 case_th_side = 2;
18 case_th_lip = 1.2;
19
20 keeper_th_z = 0.75;
21 keeper_th_x = 0.75;
22 keeper_inner_width = 1.75;
23 keeper_inner_height = 1.75;
24
25 keeper_gap_z_top = 0.25;
26 keeper_gap_z_bot = 0.75;
27 keeper_gap_x     = 0.25;
28 keeper_gap_x_holes = 0.75;
29
30 case_lip = 1.25;
31
32 lid_gap_x = 0.25;
33 lid_gap_z = 0.25;
34 lid_lip = 1.75;
35
36 $fa = 5;
37 $fs = 0.1;
38
39 // calculated
40
41 phone_backside_slope_thick = phone_total_thick - phone_edge_thick;
42
43 //lid_lip_overlap_width xxx bad name = ;
44 //lid_lip_inner_slope = [ 5, 5 ]; // xxx
45
46 epp0 = [0,0];
47 epp1 = [0, -phone_edge_thick];
48 epp2 = epp1 + phone_backside_slope_thick * [ phone_backside_slope, -1 ];
49 epp3 = epp2 + [10, 0];
50 epp5 = epp0 + [0,1] * (keeper_th_z + keeper_gap_z_top + case_lip);
51 epp4 = epp5 + [-1,0] * case_th_side;
52
53 kppe = [0,0];
54 kppd = kppe + [1,0] * keeper_inner_width;
55 kppc = kppd + [0,1] * keeper_th_z;
56 kppb = [ kppe[0] - keeper_th_x, kppc[1] ];
57 kppf = kppe - [0,1] * keeper_inner_height;
58 kppa = [ kppb[0], kppf[1] ];
59
60 lpp10 = [ epp5[0] + lid_gap_x, kppc[1] + lid_gap_z ];
61 lpp11 = [ lpp10[0],            epp5[1] + lid_gap_z ];
62 lpp12 = [ epp4[0] + lid_lip,   lpp11[1] ];
63 lpp13 = [ lpp12[0],            lpp12[1] + lid_lip ];
64
65 module rectfromto(a,b) {
66   ab = b - a;
67   translate([min(a[0], b[0]), min(a[1], b[1])])
68     square([abs(ab[0]), abs(ab[1])]);
69 }
70 module circleat(c,r) { translate(c) circle(r); }
71
72 module KeeperProfile(){
73   polygon([kppe, kppd, kppc, kppb, kppa, kppf]);
74 }
75
76 module EdgeProfile(){
77   difference(){
78     hull(){
79       translate(epp3) square(case_th_bottom*2, center=true);
80       circleat(epp2, r=case_th_bottom);
81       circleat(epp1, r=case_th_side);
82       rectfromto(epp0, epp4);
83     }
84     polygon([ epp5 + [0,10],
85               epp1,
86               epp2,
87               epp3 + [10,0] ]);
88   }
89 }
90
91 module LidEdgeProfile(){
92   polygon([ lpp10,
93             lpp11,
94             lpp12,
95             lpp13,
96             lpp13 + [10, 0],
97             lpp10 + [10, 0]
98             ]);
99   intersection(){
100     circleat(lpp12, r=lid_lip);
101     rectfromto( lpp12 + [-10,   0],
102                 lpp12 + [+10, +10] );
103   }
104 }
105
106 module CaseBase_rhsflip(yn=[0,1]) {
107   for (rhs=yn) {
108     translate([phone_width/2, 0, 0])
109       mirror([rhs,0,0])
110       translate([-phone_width/2, 0, 0])
111       children();
112   }
113 }
114
115 module CaseBase_botflip() {
116   for (bot=[0,1]) {
117     translate([0, -phone_height/2, 0])
118       mirror([0, bot, 0])
119       translate([0, phone_height/2, 0])
120       children();
121   }
122 }  
123
124 module AroundEdges(fill_zstart, fill_th, fill_downwards=0){
125   // sides
126   CaseBase_rhsflip(){
127     translate([0, -phone_cnr_rad, 0])
128       rotate([90,0,0])
129       linear_extrude(height = phone_height - phone_cnr_rad*2)
130       children(0);
131   }
132   // corners
133   CaseBase_rhsflip() CaseBase_botflip() {
134     translate([+1,-1] * phone_cnr_rad)
135       intersection(){
136         rotate_extrude()
137           intersection(){
138             mirror([1,0,0])
139               translate([-1,0] * phone_cnr_rad)
140               children(0);
141             rectfromto([0,-20],[10,20]);
142           }
143         translate([-10, 0, -20] + 0.01 * [+1,-1, 0] )
144           cube([10,10,40]);
145       }
146   }
147   // top and bottom
148   CaseBase_botflip(){
149     translate([ phone_width - phone_cnr_rad, 0,0 ])
150       rotate([90,0,-90])
151       linear_extrude(height = phone_width - phone_cnr_rad*2)
152       children(0);
153   }
154   // fill
155   translate([0,0, fill_zstart])
156     mirror([0,0, fill_downwards])
157     linear_extrude(height = fill_th)
158     rectfromto([+1,-1] * phone_cnr_rad,
159                [phone_width, -phone_height] + [-1,+1] * phone_cnr_rad);
160 }
161
162 module CaseBase(){
163   AroundEdges(epp3[1], case_th_bottom, 1)
164     EdgeProfile();
165 }
166
167 module Case(){ ////toplevel
168   difference(){
169     union(){
170       CaseBase();
171
172       // ledge (fixed keeper)
173       intersection(){
174         rotate([90, 0, 0])
175           linear_extrude(height = phone_height + phone_cnr_rad * 2)
176           KeeperProfile();
177
178         // outline of the whole case, to stop it protruding
179         translate([0,0, -25])
180           linear_extrude(height = 50)
181           hull()
182           // CaseBase_rhsflip() // actually, we only care about the LH
183           CaseBase_botflip()
184           circleat([+1,-1] * phone_cnr_rad, phone_cnr_rad + case_th_side/2);
185       }
186     }
187
188     // slot for keeper
189     CaseBase_rhsflip(1)
190       translate([0, -phone_cnr_rad, 0])
191       rotate([90, 0, 0])
192       linear_extrude(height = phone_height + phone_cnr_rad * 2)
193       minkowski(){
194         KeeperProfile();
195         rectfromto([ -keeper_gap_x,    -keeper_gap_z_bot ],
196                    [ keeper_gap_x_holes,    +keeper_gap_z_top ]);
197       }
198
199     // front camera
200     CaseBase_rhsflip([1])
201       mirror([0, 0, 1])
202       linear_extrude(height = 20)
203       mirror([0, 1, 0])
204       rectfromto(camera_pos_tl, camera_pos_br);
205   }
206 }
207
208 module Lid(){ ////toplevel
209   AroundEdges(lpp10[1], lpp13[1] - lpp10[1], 0)
210     LidEdgeProfile();
211 }
212
213 module TestLength(){ ////toplevel
214   intersection(){
215     Case();
216     translate([-30, -200, -20])
217     cube([30 + 15, 250, 40]);
218   }
219 }
220
221 module TestWidth(){ ////toplevel
222   intersection(){
223     Case();
224     translate([-30, -(phone_height - 25), -20])
225       mirror([0, 1, 0])
226       cube([200, 50, 40]);
227   }
228 }
229
230 module TestCamera(){ ////toplevel
231   intersection(){
232     Case();
233     CaseBase_rhsflip(1)
234       translate([0,0,-25])
235       linear_extrude(height = 50)
236       mirror([0, 1, 0])
237       rectfromto([-20, -20],
238                  camera_pos_br + [ 5, 5 ]);
239   }
240 }
241
242 module OneKeeper(){ ////toplevel
243   translate([0, -phone_cnr_rad, 0])
244     rotate([90, 0, 0])
245     linear_extrude(height = phone_height - phone_cnr_rad * 2)
246     KeeperProfile();
247 }
248
249 module OneKeeperPrint(){ ////toplevel
250   rotate([0,180,0])
251     OneKeeper();
252 }
253
254 module Keeper(){ ////toplevel
255   CaseBase_rhsflip()
256     OneKeeper();
257 }
258
259 module DemoProfiles(){ ////toplevel
260   LidEdgeProfile();
261   %EdgeProfile();
262   KeeperProfile();
263 }
264
265 //EdgeProfile();
266 //KeeperProfile();
267 //CaseBase();
268 //%Case();
269 //Keeper();
270 //LidEdgeProfile();
271 //KeeperProfile();
272 //DemoProfiles();