chiark / gitweb /
fairphone-case: LidEdge
[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       circleat(epp3, r=case_th_bottom);
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 CaseBase(){
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       EdgeProfile();
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               EdgeProfile();
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       EdgeProfile();
153   }
154   // fill
155   translate([0,0, epp3[1]])
156     mirror([0,0, 1])
157     linear_extrude(height = case_th_bottom)
158     rectfromto([+1,-1] * phone_cnr_rad,
159                [phone_width, -phone_height] + [-1,+1] * phone_cnr_rad);
160 }
161
162 module Case(){ ////toplevel
163   difference(){
164     CaseBase();
165
166     // slots for keeper
167     CaseBase_rhsflip()
168       translate([0, -phone_cnr_rad, 0])
169       rotate([90, 0, 0])
170       linear_extrude(height = phone_height + phone_cnr_rad * 2)
171       minkowski(){
172         KeeperProfile();
173         rectfromto([ -keeper_gap_x,    -keeper_gap_z_bot ],
174                    [ keeper_gap_x_holes,    +keeper_gap_z_top ]);
175       }
176
177     // front camera
178     CaseBase_rhsflip([1])
179       mirror([0, 0, 1])
180       linear_extrude(height = 20)
181       mirror([0, 1, 0])
182       rectfromto(camera_pos_tl, camera_pos_br);
183   }
184 }
185
186 module TestLength(){ ////toplevel
187   intersection(){
188     Case();
189     translate([-30, -200, -20])
190     cube([30 + 15, 250, 40]);
191   }
192 }
193
194 module TestWidth(){ ////toplevel
195   intersection(){
196     Case();
197     translate([-30, -(phone_height - 25), -20])
198       mirror([0, 1, 0])
199       cube([200, 50, 40]);
200   }
201 }
202
203 module TestCamera(){ ////toplevel
204   intersection(){
205     Case();
206     CaseBase_rhsflip(1)
207       translate([0,0,-25])
208       linear_extrude(height = 50)
209       mirror([0, 1, 0])
210       rectfromto([-20, -20],
211                  camera_pos_br + [ 5, 5 ]);
212   }
213 }
214
215 module OneKeeper(){ ////toplevel
216   translate([0, -phone_cnr_rad, 0])
217     rotate([90, 0, 0])
218     linear_extrude(height = phone_height - phone_cnr_rad * 2)
219     KeeperProfile();
220 }
221
222 module OneKeeperPrint(){ ////toplevel
223   rotate([0,180,0])
224     OneKeeper();
225 }
226
227 module Keeper(){ ////toplevel
228   CaseBase_rhsflip()
229     OneKeeper();
230 }
231
232 module DemoProfiles(){ ////toplevel
233   LidEdgeProfile();
234   %EdgeProfile();
235   KeeperProfile();
236 }
237
238 //EdgeProfile();
239 //KeeperProfile();
240 //CaseBase();
241 //%Case();
242 //Keeper();
243 //LidEdgeProfile();
244 //KeeperProfile();
245 //DemoProfiles();