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