chiark / gitweb /
sewing-table: Tile11 wip machine cutout
[reprap-play.git] / sewing-table.scad.m4
1 // -*- C -*-
2
3 include <funcs.scad>
4 include <commitid.scad>
5
6 ply_th = 18;
7 ply_hole_dia = 15;
8 ply_edge_min = 10;
9
10 tile_th = 3;
11 post_dia = 8;
12
13 post_shorter = 1;
14
15 screw_dia = 2.2;
16 screw_big_dia = 3.6;
17 screw_big_len = 4.0;
18
19 round_edge_rad = 2.0;
20
21 round_cnr_rad = 10;
22
23 interlock_dia = 10;
24 interlock_fine = 0.66;
25
26 interlock_fine_slope = 1.0;
27 interlock_fine_lenslop = 1.0;
28
29 demo_slop = 0.1;
30
31 // cutout
32
33 cutout_l_end_y_front_slop = 0.5;
34 cutout_l_end_y_rear_slop = 0.5;
35
36 cutout_l_end_y = 85;
37 cutout_l_end_curve = 1;
38 cutout_l_end_y_total = cutout_l_end_y
39   + cutout_l_end_y_front_slop + cutout_l_end_y_rear_slop;
40
41 tile01_tr = [250, 0];
42
43 cutout_tile01_y = 170 - 147 + cutout_l_end_y_front_slop;
44 cutout_tile11_x = 22 + cutout_l_end_curve;
45 cutout_tile11_y = cutout_l_end_y_total - cutout_tile01_y;
46
47 // calculated
48
49 TEST = false;
50
51 ply_edge_hole_dist = ply_edge_min + ply_hole_dia/2;
52
53 echo(str("HOLES IN PLY ctr dist from PLY edge = ", ply_edge_hole_dist));
54
55 hole_slop = (ply_hole_dia - post_dia)/2;
56 tile_hard_edge_hole_dist = ply_edge_hole_dist + hole_slop;
57
58 echo(str("HOLES IN PLY ctr dist from TILE HARD edge = ",
59          tile_hard_edge_hole_dist));
60
61 echo(str("HOLES IN PLY ctr dist from TILE ROUND edge = ",
62          tile_hard_edge_hole_dist + round_edge_rad));
63
64 thehd = [ tile_hard_edge_hole_dist, tile_hard_edge_hole_dist ];
65 thehd_tr = thehd;
66 thehd_tl = [ -thehd_tr[0], thehd_tr[1] ];
67 thehd_bl = -thehd_tr;
68 thehd_br = -thehd_tl;
69
70 interlock_rad = interlock_dia/2;
71 interlock_negative_rad = interlock_rad + 0.125;
72
73 interlock_sq_adj = 0.2; // arbitrary
74
75 module Post(){
76   mirror([0,0,1]) {
77     difference(){
78       cylinder(r= post_dia/2, h= tile_th + ply_th - post_shorter);
79       translate([0,0, tile_th]) {
80         cylinder(r= screw_big_dia/2, h= screw_big_len);
81         cylinder(r= screw_dia/2, h= ply_th, $fn=20);
82       }
83     }
84     if (TEST) {
85       tsz = tile_hard_edge_hole_dist - test_edge + 1;
86       translate([0,0, tile_th/2]) {
87         cube([post_dia, tsz*2, tile_th], center=true);
88         cube([tsz*2, post_dia, tile_th], center=true);
89       }
90     }
91   }
92 }
93
94 module Posts(posts) {
95   for (p= posts) {
96     translate(concat(p, [0]))
97       Post();
98   }
99 }
100
101 module TileBase(botleft, topright){
102   size = topright - botleft;
103   botleft_post = botleft + thehd_tr;
104   topright_post = topright + thehd_bl;
105   difference(){
106     mirror([0,0,1])
107       translate(concat(botleft, [0]))
108       cube(concat(size, [tile_th]));
109     if (!TEST) {
110       translate( concat(botleft_post, [ -tile_th ])
111                  + 0.5 * [ post_dia, post_dia, 0 ] )
112         Commitid_BestCount_M( topright_post-botleft_post
113                               + [-post_dia,-post_dia]
114                               + [0, thehd[1]]);
115     }
116     if (TEST) {
117       translate( concat(botleft + [thehd[0], 0], [0]) )
118         Commitid_BestCount([ size[0] - thehd[0]*2, thehd[1] ]);
119       difference(){
120         mirror([0,0,1]) {
121           translate(concat(botleft + [test_edge,test_edge], [test_tile_th]))
122             cube(concat(size - [test_edge,test_edge]*2, [tile_th]));
123           translate(concat(botleft_post, [-1]))
124             cube(concat(topright_post-botleft_post, [tile_th+2]));
125         }
126 //      minkowski(){
127 //        /
128       }
129     }
130   }
131 }
132
133 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars) { body; }
134 m4_define(`INREFFRAME',`
135   length_vec = ($2) - ($1);
136   length = dist2d([0,0], length_vec);
137   length_uvec = length_vec / length;
138   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
139   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
140         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
141         [ 0,              0,              1,            0, ],
142         [ 0,              0,              0,            1, ] ];
143   $3
144   multmatrix(m)
145 ')
146
147 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars)
148 m4_dnl    INREFFRAME_EDGE { body; }
149 m4_define(`INREFFRAME_EDGE',`
150   translate([0,0, -round_edge_rad])
151 ')
152
153 module RoundEdge(left_cnr, right_cnr) {
154   INREFFRAME(left_cnr, right_cnr)
155     INREFFRAME_EDGE {
156     difference(){
157       rotate([0,90,0])
158         cylinder(r= round_edge_rad, h= length, $fn=50);
159       translate([-1, 0, -20])
160         cube([length+2, 20, 20]);
161     }
162   }
163 }
164
165 module RoundCornerCut(ci) {
166   // ci should be [this_cnr, right_cnr]
167   // where right_cnr is to the right (ie, anticlockwise)
168   this_cnr = ci[0];
169   right_cnr = ci[1];
170   offr= round_cnr_rad - round_edge_rad;
171   INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
172     difference(){
173       cube(offr*2 - 0.1, center=true);
174       translate([offr, offr, 0])
175         cylinder(center=true, h=20, r= offr);
176     }
177   }
178 }
179
180 module RoundCornerAdd(ci) {
181   this_cnr = ci[0];
182   right_cnr = ci[1];
183   bigr = round_cnr_rad - round_edge_rad;
184   INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
185     intersection(){
186       cube(bigr*2 + 0.1, center=true);
187       translate([bigr, bigr, 0])
188         rotate_extrude(convexity=10, $fn=50)
189         translate([bigr, 0])
190         difference(){
191           circle(r= round_edge_rad, $fn=50);
192           mirror([1,1])
193             square([20,20]);
194         }
195     }
196   }
197 }
198
199 module InterlockLobePlan(negative) {
200   r = negative ? interlock_negative_rad : interlock_rad;
201   ymir = negative ? 0 : 1;
202
203   dx = sqrt(3) * r;
204   $fn= 80;
205   translate([thehd[0], 0]){
206     mirror([0,ymir]){
207       circle(r=r);
208       difference(){
209         translate([-dx, -0.1])
210           square([ dx*2, r/2 + 0.1 ]);
211         for (xi = [-1, 1]) {
212           translate([ xi*dx, r ])
213             circle(r=r);
214         }
215       }
216     }
217   }
218 }
219
220 module InterlockEdgePlan(negative, nlobes, length, dosquare=true) {
221   for (lobei = [ 0 : nlobes-1 ]) {
222     lobex = (length - thehd[0]*2) * (lobei ? lobei / (nlobes-1) : 0);
223     translate([lobex, 0, 0]) {
224       InterlockLobePlan(negative);
225     }
226   }
227
228   if (dosquare) {
229     iadj = 0;
230     slotshorter = negative ? -0.1 : interlock_fine_lenslop;
231     mirror([0, negative])
232       translate([slotshorter, iadj])
233       square([length - slotshorter*2, interlock_fine + iadj*2]);
234   }
235 }
236
237 module InterlockEdge(left_cnr, right_cnr, negative=0, nlobes=2) {
238   plusth = negative * 1.0;
239   protr = interlock_fine + interlock_sq_adj;
240
241   z2 = -tile_th/2;
242   z1 = -tile_th/2 - protr / interlock_fine_slope;
243   z3 = -tile_th/2 + protr / interlock_fine_slope;
244
245   negsign = negative ? -1 : +1;
246   yprotr = negsign * protr;
247
248   INREFFRAME(left_cnr, right_cnr) {
249     for (vsect = [ // zs0            zs1      ys0,            ys1
250                   [ -tile_th-plusth, plusth,  0,              0],
251                   [ z1,              z2,      0, yprotr],
252                   [ z2,              z3,      yprotr, 0],
253                   ]) {
254       zs0 = vsect[0];
255       zs1 = vsect[1];
256       zsd = zs1-zs0;
257       ys0 = vsect[2];
258       ys1 = vsect[3];
259       ysd = ys1-ys0;
260       sl = ysd/zsd;
261       m = [ [ 1,0,   0,    0 ],
262             [ 0,1, -sl, -ys0 + negsign*interlock_sq_adj ],
263             [ 0,0,   1,  zs0 ],
264             [ 0,0,   0,    1 ] ];
265       multmatrix(m)
266         linear_extrude(height=zsd, convexity=10)
267         InterlockEdgePlan(negative, nlobes, length, !!ysd);
268     }
269   }
270 }
271
272 function TestPiece_holes2corners(holes) =
273   [ holes[0] + thehd_bl,
274     holes[1] + thehd_br,
275     holes[1] + thehd_tr,
276     holes[0] + thehd_tl ];
277
278 module TestPiece1(){ ////toplevel
279   holes = [ [-100, 0],
280             [   0, 0]
281             ];
282   corners = TestPiece_holes2corners(holes);
283   rcs = [corners[0], corners[1]];
284   difference(){
285     union(){
286       TileBase(corners[0], corners[2]);
287       Posts(holes);
288       RoundEdge(corners[0], corners[1]);
289       RoundEdge(corners[3], corners[0]);
290     }
291     InterlockEdge(corners[1], corners[2], 1, nlobes=1);
292     RoundCornerCut(rcs);
293   }
294   RoundCornerAdd(rcs);
295 }
296
297 module TestPiece2(){ ////toplevel
298   holes = [ [   0, 0],
299             [  50, 0]
300             ];
301   corners = TestPiece_holes2corners(holes);
302   TileBase(corners[0], corners[2]);
303   Posts(holes);
304   RoundEdge(corners[0], corners[1]);
305   InterlockEdge(corners[3], corners[0], 0, nlobes=1);
306 }
307
308 module TestDemo(){ ////toplevel
309   translate([ -thehd[0], 0 ])
310     color("blue")
311     TestPiece1();
312   translate([ +thehd[0] + demo_slop, 0 ])
313     TestPiece2();
314 }
315
316 module Machine_Arm(){
317   ysz = cutout_l_end_y_total;
318   // assume the round end is arc of a circle
319   //rad = 
320   
321   translate([0,0,-30]) linear_extrude(height=60) {
322     translate(tile01_tr + [0, (-cutout_tile01_y + cutout_tile11_y)/2]) {
323       intersection(){
324         translate([-100, -ysz/2])
325           square([400, ysz]);
326         
327       }
328     }
329   }
330 }
331
332 module Machine(){
333   Machine_Arm();
334 }
335   
336 function Rectangle_corners(c0, sz) =
337   // returns the corners of a rectangle from c0 to c0+sz
338   // if sz is positive, the corners are anticlockwise starting with c0
339   [ c0 + [ 0,     0     ],
340     c0 + [ sz[0], 0     ],
341     c0 + [ sz[0], sz[1] ],
342     c0 + [ 0,     sz[1] ] ];
343
344 function Rectangle_corners2posts(c) =
345   [ c[0] + thehd_tr,
346     c[1] + thehd_tl,
347     c[2] + thehd_bl,
348     c[3] + thehd_br ];
349
350 module Rectangle_TileBase(c) { TileBase(c[0], c[2]); }
351
352 function Posts_interpolate_one(c0,c1) = [c0, (c0+c1)/2, c1];
353
354 m4_dnl   R_EDGE(c,ix)
355 m4_dnl        c is from Rectangle_corners and
356 m4_dnl        ix is a corner number
357 m4_dnl    expands to two comma-separated corners:
358 m4_dnl    that denoted by ix, and the next one anticlockwise
359 m4_define(`R_EDGE',`$1[$2],$1[(($2)+1)%4]')
360
361 module Tile02(){ ////toplevel
362   sz = [100,170];
363   c0 = -sz;
364   c = Rectangle_corners(c0, sz);
365   posts = Rectangle_corners2posts(c);
366   rcs = [R_EDGE(c,0)];
367   difference(){
368     union(){
369       Rectangle_TileBase(c);
370       Posts(posts);
371       RoundEdge(R_EDGE(c,0));
372       RoundEdge(R_EDGE(c,3));
373       InterlockEdge(R_EDGE(c,2), 0);
374     }
375     InterlockEdge(R_EDGE(c,1), 1);
376     RoundCornerCut(rcs);
377   }
378   RoundCornerAdd(rcs);
379 }
380
381 module Tile12(){ ////toplevel
382   sz = [100,250];
383   c0 = [-sz[0], 0];
384   c = Rectangle_corners(c0, sz);
385   posts = Rectangle_corners2posts(c);
386   rcs = [R_EDGE(c,3)];
387   difference(){
388     union(){
389       Rectangle_TileBase(c);
390       Posts(posts);
391       RoundEdge(R_EDGE(c,2));
392       RoundEdge(R_EDGE(c,3));
393     }
394     InterlockEdge(R_EDGE(c,0), 1);
395     InterlockEdge(R_EDGE(c,1), 1);
396     RoundCornerCut(rcs);
397   }
398   RoundCornerAdd(rcs);
399 }
400
401 module Tile11(){ ////toplevel
402   sz = [250,250];
403   c0 = [0,0];
404   c = Rectangle_corners(c0, sz);
405   cnr_posts = Rectangle_corners2posts(c);
406   posts = concat(
407                  Posts_interpolate_one(cnr_posts[0],
408                                        cnr_posts[1] - [cutout_tile11_x, 0]),
409                  [ cnr_posts[1] + [0, cutout_tile11_y],
410                    cnr_posts[2],
411                    cnr_posts[3]
412                    ]);
413   difference(){
414     union(){
415       Rectangle_TileBase(c);
416       Posts(posts);
417       RoundEdge(R_EDGE(c,2));
418       InterlockEdge(R_EDGE(c,3));
419     }
420     Machine();
421     InterlockEdge(R_EDGE(c,0), 1);
422   }
423 }    
424
425 module Demo(){ ////toplevel
426   translate(demo_slop*[-2,1]) color("blue") Tile12();
427   translate(demo_slop*[-2,0]) color("red")  Tile02();
428   translate(demo_slop*[-2,1]) color("orange") Tile11();
429   %Machine();
430 }
431   
432 //TestPiece1();
433 //TestPiece2();
434 //Demo();