chiark / gitweb /
nook-case: trim a bit more for test
[reprap-play.git] / nook-case.scad
1 // -*- C -*-
2
3 include <funcs.scad>
4 include <utils.scad>
5
6 nook_th = 12.41 + 0.50 - 1.50 + 1.35 - .25;
7 nook_w = 127.12 + 0.75 - .95 - .50;
8 nook_h = 123.44 + 21.88 + 21.05 + 0.75 - 1.90 - 0.50 - 0.50;
9
10 edge_ledge_w = 9.60;
11 edge_ledge_h = 2.44 - .25;
12 edge_ledge_inc_ang = 10; // degrees
13
14 usb_w = 14.5;
15 usb_below = 1.5;
16
17 open_recess_w = 12.5;
18 open_recess_h = 2.5;
19
20 open_recess_2_len = 15;
21 open_recess_2_d_tooth = 30;
22
23 nook_cnr_rad = 10;
24
25 case_th = 2.5;
26 ledge_w = 4;
27 tape_th = 1.75;
28 tape_inside = 2.0;
29
30 gap = 0.5 * [1,1];
31
32 tape_w = 15;
33
34 test_pillar = 4;
35
36 engage_l0 = 10;
37 engage_l1 = 10;
38 engage_l2 = 3;
39
40 tooth_inward = gap[0] * 1.0 + 0.25 + 0.25;
41 tooth_w = 15;
42
43 diag_near_hinge_slope = 0.5;
44
45 $test = false;
46
47 $fa = $test ? 10 : 3;
48 $fs = $test ? 0.1 : 1;
49
50 // calculated
51
52 tooth_height = nook_th;
53 ledge_h = case_th;
54 lid_th = case_th;
55 tooth_th = case_th;
56
57 spp0 = [0,0];
58 spp1 = spp0 + case_th * [-1,0];
59 spp9 = spp0 + ledge_h * [0,-1];
60 spp8 = spp9 + nook_th * [0,-1];
61 spp7 = spp8 + case_th * [-1,-1];
62
63 spp11y = spp1[1] - tape_th;
64 spp4y  = 0.5 * (spp0[1] + spp7[1]);
65 spp3y = spp4y + tape_inside/2;  spp5y = spp4y - tape_inside/2;
66 spp2y = spp3y + tape_th;        spp6y = spp5y - tape_th;
67
68 spp20 = spp8 + nook_cnr_rad * [1,0];
69 spp20x = spp20[0];
70
71 tppA = spp0 + gap;
72 tppB = spp1 + [0, gap[1]];
73 tppC = tppB + lid_th * [0,1];
74 tppD = [ spp20x, tppC[1] ];
75 tppE = [ spp20x, tppB[1] ];
76 tppF = tppA + ledge_w * [1,0];
77 tppG = tppF + ledge_h * [0,-1];
78 tppH = [ tppA[0], tppG[1] ];
79
80 tppJx = tppA[0] + tape_th;
81
82 tppK = [ tppC[0], tppG[1] ];
83 spp31 = tppK - [0, gap[1]];
84 spp30 = [ spp8[0], spp31[1] ];
85
86 nom_cnr = 0.5 * [nook_w, nook_h, 0] - nook_cnr_rad * [1,1,0];
87
88 tooth_y = nom_cnr[1] - tooth_w/2;
89
90 etxa = nom_cnr[0] - engage_l2;
91 etxb = etxa - engage_l1;
92 etxc = -(nom_cnr[0] - engage_l2);
93
94 tapa = nom_cnr[1] - engage_l2;
95 tapb = tapa - tape_w;
96
97 opra = nom_cnr[1] - engage_l2;
98 oprb = opra - open_recess_w;
99
100 opqa = tooth_y - open_recess_2_d_tooth + open_recess_2_len/2;
101 opqb = opqa - open_recess_2_len;
102
103 tppS = tppB + [-gap[0], 0];
104 tppP = [ tppS[0] - tooth_th, tppC[1] ];
105 tppQ = tppP + tooth_height * [0,-1] + tooth_inward * [1,0];
106 tppR = [ tppS[0] + tooth_inward, tppQ[1] ];
107 tppM = (tppQ + tppR) * 0.5 + tooth_th * 0.5 * [0,1];
108
109 edge_ledge_rad = edge_ledge_h;
110
111 module RightSideMainProfile() {
112   rectfromto(spp7, spp0);
113   rectfromto(spp7, spp20);
114   EdgeLedgeProfile();
115 }
116
117 module LeftSideMainProfile() {
118   rectfromto(spp7, spp30);
119   rectfromto(spp7, spp20);
120   EdgeLedgeProfile();
121 }
122
123 module EdgeLedgeProfile() {
124   intersection(){
125     hull(){
126       for (t=[[0,0], [$test ? -1 : -20,0], [0,-10]]) {
127         translate(spp8
128                   + [edge_ledge_w, edge_ledge_h]
129                   + edge_ledge_rad * [ -sin(edge_ledge_inc_ang),
130                                        -cos(edge_ledge_inc_ang) ]
131                   + t)
132           circle(edge_ledge_rad);
133       }
134     }
135     translate(spp7)
136       square(30);
137   }
138 }
139
140 module TopTapeCutout() {
141   polygon([ tppA,
142             tppA + [-40, 0],
143             tppG + [-40,-1],
144             [ tppJx, tppH[1]-1 ],
145             [ tppJx, tppC[1]+1 ],
146             [ tppA[0], tppC[1]+1 ]]);
147 }
148
149 module RightTopMainProfile() {
150   l = [ tppA, tppB, tppC, tppD, tppE, tppF, tppG, tppH ];
151   polygon(l);
152 }
153
154 module LeftTopMainProfile() {
155   l = [ tppC, tppD, tppE, tppF, tppG, tppK ];
156   polygon(l);
157 }
158
159 module SideTapeCutout1(y0,y1) {
160   rectfromto([ spp7[0]-1, y0 ],
161              [ spp8[0]+1, y1 ]);
162 }
163
164 module SideTapeCutout() {
165   SideTapeCutout1(spp6y, spp5y);
166   SideTapeCutout1(spp3y, spp2y);
167   SideTapeCutout1(spp3y, spp2y);
168   SideTapeCutout1(spp11y, spp1[1] + 1); // obsolete I think
169 }
170
171 module ToothProfile(){
172   polygon([tppA,
173            tppB,
174            tppS + [-0.1,0],
175            tppP,
176            tppC]);
177   hull(){
178     polygon([tppP,
179              tppM,
180              tppS]);
181     translate(tppM)
182       circle(r= tooth_th/2);
183   }
184 }
185
186 module Demo(){ ////toplevel
187   translate([-1,0,0]) {
188     translate([0,0,-2]) LeftSideMainProfile(); 
189     translate([0,0,-2]) color("yellow") LeftTopMainProfile();
190     color("red") difference(){
191       LeftSideMainProfile();
192       SideTapeCutout();
193     }
194     translate([0,0,-4]) color("brown") EdgeLedgeProfile();
195     translate(concat(spp8 + [edge_ledge_w, edge_ledge_h], [2]))
196       rotate(-edge_ledge_inc_ang) {
197       color("blue") square(3);
198       color("lightblue") mirror([1,0]) square(3);
199     }
200   }
201   translate([0,0,0]) color("purple") difference(){
202     LeftTopMainProfile();
203     TopTapeCutout();
204   }
205   translate([nook_cnr_rad*2 + 5, 0,0]) mirror([1,0,0]) {
206     color("red") RightSideMainProfile();
207     color("purple") RightTopMainProfile();
208     color("grey") translate([0,0,-2]) ToothProfile();
209   }
210   //%SideTapeCutout();
211 }
212
213 module FaceCore(z0,z1, extra_left, extra_right){
214   difference(){
215     for (mx=[0,1]) mirror([mx,0,0]) {
216         for (my=[0,1]) mirror([0,my,0]) {
217             translate(-nom_cnr) {
218               rotate_extrude(angle=90, convexity=10) {
219                 intersection(){
220                   translate(-[1,0,0] * nook_cnr_rad)
221                     children(mx);
222                   rectfromto([-100,-100], [0,100]);
223                 }
224               }
225             }
226           }
227         translate([nook_w/2, 0,0])
228           linextr_y_xz(-nom_cnr[1]-0.1, nom_cnr[1]+0.1)
229           children(1-mx);
230       }
231     for (my=[0,1]) mirror([0,my,0]) {
232         translate([-nook_w/2, 0,0])
233           mirror([1,0,0])
234           linextr_y_xz(tapb, tapa)
235           children(2);
236       }
237   }
238   for (my=[0,1]) mirror([0,my,0]) {
239       translate([0, -nook_h/2, 0]) {
240         linextr_x_yz(-nom_cnr[0]-0.1,    etxc + extra_left)  children(0);
241         linextr_x_yz(etxc - extra_right, etxb + extra_right) children(1);
242         linextr_x_yz(etxb - extra_left,  etxa + extra_left)  children(0);
243         linextr_x_yz(etxa - extra_right, nom_cnr[0]+0.1)     children(1);
244       }
245     }
246   if (!$test) {
247     linextr(z0,z1)
248       rectfromto(-nom_cnr, nom_cnr);
249   }
250 }
251
252 module DiagonaliseNearHinge(wider){
253   sz = spp0[1] - spp30[1] + gap[1];
254
255   for (my=[0,1]) mirror([0,my,0]) {
256       translate([-etxa, -nook_h/2, 0])
257         mirror([1,0,0])
258         linextr_y_xz(spp31[0] - wider, spp30[0] + gap[0] + 0.1)
259         translate([ 0, spp30[1] ])
260         polygon([[  -1, 0 ],
261                  [   0, 0 ],
262                  [  sz/diag_near_hinge_slope, sz ],
263                  [  sz/diag_near_hinge_slope, sz + 0.1 ],
264                  [  -1, sz + 0.1 ]]);
265     }
266 }    
267
268 module Base(){ ////toplevel
269   difference(){
270     FaceCore(spp7[1],spp8[1], 0.3, 0) {
271       LeftSideMainProfile();
272       RightSideMainProfile();
273       SideTapeCutout();
274     }
275     translate([0, -nook_h/2, 0])
276       mirror([0,1,0])
277       linextr_x_yz(-usb_w/2, usb_w/2)
278       rectfromto(spp8 + [-40, usb_below], [40, 40]);
279     translate([ gap[0], 0,0 ])
280       DiagonaliseNearHinge(10);
281 /*
282     translate([nook_w/2, 0, 0])
283       linextr_y_xz(oprb, opra)
284       translate(spp0)
285       rectfromto([-40, -open_recess_h], [40, 1]);
286 */
287   }
288   if ($test) {
289     linextr(spp7[1], spp8[1]) {
290       hull(){
291         for (r=[0,180])
292           rotate([0,0,r])
293             translate(nom_cnr + -1 * nook_cnr_rad*[1,1])
294             square(12);
295       }
296     }
297   }
298 }
299
300 module Top(){ ////toplevel
301   difference(){
302     FaceCore(tppE[1],tppD[1], -gap[0], gap[0] + 0.3) {
303       LeftTopMainProfile();
304       RightTopMainProfile();
305       TopTapeCutout();
306     }
307     translate([nook_w/2, 0,0])
308       linextr_y_xz(opqb, opqa)
309       rectfromto(spp8, tppC + [-1,1]);
310   }
311   translate([0,0, gap[1]])
312     DiagonaliseNearHinge(0);
313   translate([nook_w/2, tooth_y, 0])
314     linextr_y_xz(-tooth_w/2, +tooth_w/2)
315     ToothProfile();
316 }
317 module TopPrint(){ ////toplevel
318   rotate([0,0,90]) rotate([180,0,0]) Top();
319 }
320 module BasePrint(){ ////toplevel
321   rotate([0,0,90]) Base();
322 }
323
324 module TestExtrude(){
325   difference(){
326     linextr_y_xz(-test_pillar, tape_w+test_pillar) children(0);
327     linextr_y_xz(           0, tape_w            ) children(1);
328   }
329 }
330
331 module BaseTestRest(){ ////toplevel
332   cube([30,15, spp8[1]-spp7[1]]);
333 }
334
335 module Demo3(){ ////toplevel
336   color("purple") Top();
337   color("red") Base();
338 }
339
340 module TestSide(){ ////toplevel
341   TestExtrude() { LeftSideMainProfile(); SideTapeCutout(); }
342 }
343
344 module TestTop(){ ////toplevel
345   TestExtrude() { LeftTopMainProfile(); TopTapeCutout(); }
346 }
347 module TestTopPrint(){ ////toplevel
348   rotate([180,0,0]) TestTop();
349 }