chiark / gitweb /
fairphone-case: Lid
[reprap-play.git] / fairphone-case.scad
1 // -*- C -*-
2
3 phone_height = 146.5;
4 phone_width = 76.75;
5
6 phone_cnr_rad = 4.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.5, 13.5 ]; // measured from tl corner
13 camera_pos_br = [ 24.0, 39.5 ]; // tl/br as seen from back
14
15 case_th_bottom = 2;
16 case_th_lid = 2;
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.25;
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     CaseBase();
170
171     // slots for keeper
172     CaseBase_rhsflip()
173       translate([0, -phone_cnr_rad, 0])
174       rotate([90, 0, 0])
175       linear_extrude(height = phone_height + phone_cnr_rad * 2)
176       minkowski(){
177         KeeperProfile();
178         rectfromto([ -keeper_gap_x,    -keeper_gap_z_bot ],
179                    [ keeper_gap_x_holes,    +keeper_gap_z_top ]);
180       }
181
182     // front camera
183     CaseBase_rhsflip([1])
184       mirror([0, 0, 1])
185       linear_extrude(height = 20)
186       mirror([0, 1, 0])
187       rectfromto(camera_pos_tl, camera_pos_br);
188   }
189 }
190
191 module Lid(){ ////toplevel
192   AroundEdges(lpp10[1], lpp13[1] - lpp10[1], 0)
193     LidEdgeProfile();
194 }
195
196 module TestLength(){ ////toplevel
197   intersection(){
198     Case();
199     translate([-30, -200, -20])
200     cube([30 + 15, 250, 40]);
201   }
202 }
203
204 module TestWidth(){ ////toplevel
205   intersection(){
206     Case();
207     translate([-30, -(phone_height - 25), -20])
208       mirror([0, 1, 0])
209       cube([200, 50, 40]);
210   }
211 }
212
213 module TestCamera(){ ////toplevel
214   intersection(){
215     Case();
216     CaseBase_rhsflip(1)
217       translate([0,0,-25])
218       linear_extrude(height = 50)
219       mirror([0, 1, 0])
220       rectfromto([-20, -20],
221                  camera_pos_br + [ 5, 5 ]);
222   }
223 }
224
225 module OneKeeper(){ ////toplevel
226   translate([0, -phone_cnr_rad, 0])
227     rotate([90, 0, 0])
228     linear_extrude(height = phone_height - phone_cnr_rad * 2)
229     KeeperProfile();
230 }
231
232 module OneKeeperPrint(){ ////toplevel
233   rotate([0,180,0])
234     OneKeeper();
235 }
236
237 module Keeper(){ ////toplevel
238   CaseBase_rhsflip()
239     OneKeeper();
240 }
241
242 module DemoProfiles(){ ////toplevel
243   LidEdgeProfile();
244   %EdgeProfile();
245   KeeperProfile();
246 }
247
248 //EdgeProfile();
249 //KeeperProfile();
250 //CaseBase();
251 //%Case();
252 //Keeper();
253 //LidEdgeProfile();
254 //KeeperProfile();
255 //DemoProfiles();