chiark / gitweb /
sewing-table: move first_front (nfc)
[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 machine_rear_to_front = 85;
34
35 machine_rear_profile = [
36                         [ -  0,  -0.00 ],
37                         [ -  2,  -0.10 ],
38                         [ -  4,  -0.20 ],
39                         [ -  5,  -0.30 ],
40                         [ -  6,  -0.40 ],
41                         [ -  7,  -0.50 ],
42                         [ -  8,  -0.75 ],
43                         [ - 10,  -1.50 ],
44                         [ - 12,  -2.25 ],
45                         [ - 14,  -3.25 ],
46                         [ - 16,  -4.25 ],
47                         [ - 18,  -5.75 ],
48                         [ - 20,  -8.00 ]
49                         ];
50
51 machine_front_profile =  [
52                           [  128,  -3.70,  ],
53                           [  124,  -2.90,  ],
54                           [  120,  -2.45,  ],
55                           [  116,  -2.10,  ],
56                           [  112,  -1.80,  ],
57                           [  108,  -1.55,  ],
58                           [  104,  -1.25,  ],
59                           [  100,  -1.00,  ],
60                           [   96,  -0.80,  ],
61                           [   92,  -0.65,  ],
62                           [   88,  -0.55,  ],
63                           [   84,  -0.50,  ]
64                           ];
65
66 cutout_l_end_y_front_slop = 0.5;
67 cutout_l_end_y_rear_slop = 0.5;
68 cutout_l_end_x_slop = 0.25;
69
70 cutout_l_end_x = 22;
71 cutout_l_end_y = machine_rear_to_front;
72 cutout_l_end_curve = 1;
73 cutout_l_end_y_total = cutout_l_end_y
74   + cutout_l_end_y_front_slop + cutout_l_end_y_rear_slop;
75
76 tile02_tr = [-250, 0];
77 tile01_tr = [  0, 0];
78
79 cutout_tile01_y = 170 - 147 + cutout_l_end_y_front_slop;
80 cutout_tile11_x = cutout_l_end_x + cutout_l_end_curve;
81 cutout_tile11_y = cutout_l_end_y_total - cutout_tile01_y;
82
83 // front and rear curves
84
85 rearedge_len = 170;
86
87 rearcurve_strt_len = 52;
88
89 rearcurve_z_slop = 0.75;
90
91 rearcurve_avoid_y = 35;
92
93 rearcurve_double_inrad = 26.10 + 8.04;
94
95 reartablet_z = 2.54;
96 reartablet_x = 5 + 1;
97 reartablet_y = 5;
98
99 // calculated
100
101 TEST = false;
102
103 ply_edge_hole_dist = ply_edge_min + ply_hole_dia/2;
104
105 echo(str("HOLES IN PLY ctr dist from PLY edge = ", ply_edge_hole_dist));
106
107 hole_slop = (ply_hole_dia - post_dia)/2;
108 tile_hard_edge_hole_dist = ply_edge_hole_dist + hole_slop;
109
110 echo(str("HOLES IN PLY ctr dist from TILE HARD edge = ",
111          tile_hard_edge_hole_dist));
112
113 echo(str("HOLES IN PLY ctr dist from TILE ROUND edge = ",
114          tile_hard_edge_hole_dist + round_edge_rad));
115
116 thehd = [ tile_hard_edge_hole_dist, tile_hard_edge_hole_dist ];
117 thehd_tr = thehd;
118 thehd_tl = [ -thehd_tr[0], thehd_tr[1] ];
119 thehd_bl = -thehd_tr;
120 thehd_br = -thehd_tl;
121
122 interlock_rad = interlock_dia/2;
123 interlock_negative_rad = interlock_rad + 0.125;
124
125 interlock_sq_adj = 0.2; // arbitrary
126
127 first_front = machine_front_profile[len(machine_front_profile)-1];
128
129 module Post(){
130   mirror([0,0,1]) {
131     difference(){
132       cylinder(r= post_dia/2, h= tile_th + ply_th - post_shorter);
133       translate([0,0, tile_th]) {
134         cylinder(r= screw_big_dia/2, h= screw_big_len);
135         cylinder(r= screw_dia/2, h= ply_th, $fn=20);
136       }
137     }
138     if (TEST) {
139       tsz = tile_hard_edge_hole_dist - test_edge + 1;
140       translate([0,0, tile_th/2]) {
141         cube([post_dia, tsz*2, tile_th], center=true);
142         cube([tsz*2, post_dia, tile_th], center=true);
143       }
144     }
145   }
146 }
147
148 module Posts(posts) {
149   for (p= posts) {
150     translate(concat(p, [0]))
151       Post();
152   }
153 }
154
155 module TileBase(botleft, topright){
156   size = topright - botleft;
157   botleft_post = botleft + thehd_tr;
158   topright_post = topright + thehd_bl;
159   difference(){
160     mirror([0,0,1])
161       translate(concat(botleft, [0]))
162       cube(concat(size, [tile_th]));
163     if (!TEST) {
164       translate( concat(botleft_post, [ -tile_th ])
165                  + 0.5 * [ post_dia, post_dia, 0 ] )
166         Commitid_BestCount_M( topright_post-botleft_post
167                               + [-post_dia,-post_dia]
168                               + [0, thehd[1]]);
169     }
170     if (TEST) {
171       translate( concat(botleft + [thehd[0], 0], [0]) )
172         Commitid_BestCount([ size[0] - thehd[0]*2, thehd[1] ]);
173       difference(){
174         mirror([0,0,1]) {
175           translate(concat(botleft + [test_edge,test_edge], [test_tile_th]))
176             cube(concat(size - [test_edge,test_edge]*2, [tile_th]));
177           translate(concat(botleft_post, [-1]))
178             cube(concat(topright_post-botleft_post, [tile_th+2]));
179         }
180         minkowski(){
181           Machine();
182           cube(max(test_edge, tile_hard_edge_hole_dist)*2, center=true);
183         }
184       }
185     }
186   }
187 }
188
189 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars) { body; }
190 m4_define(`INREFFRAME',`
191   length_vec = ($2) - ($1);
192   length = dist2d([0,0], length_vec);
193   length_uvec = length_vec / length;
194   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
195   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
196         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
197         [ 0,              0,              1,            0, ],
198         [ 0,              0,              0,            1, ] ];
199   $3
200   multmatrix(m)
201 ')
202
203 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars)
204 m4_dnl    INREFFRAME_EDGE { body; }
205 m4_define(`INREFFRAME_EDGE',`
206   translate([0,0, -round_edge_rad])
207 ')
208
209 module RoundEdge(left_cnr, right_cnr) {
210   INREFFRAME(left_cnr, right_cnr)
211     INREFFRAME_EDGE {
212     difference(){
213       rotate([0,90,0])
214         cylinder(r= round_edge_rad, h= length, $fn=50);
215       translate([-1, 0, -20])
216         cube([length+2, 20, 20]);
217     }
218   }
219 }
220
221 module RoundCornerCut(ci) {
222   // ci should be [this_cnr, right_cnr]
223   // where right_cnr is to the right (ie, anticlockwise)
224   this_cnr = ci[0];
225   right_cnr = ci[1];
226   offr= round_cnr_rad - round_edge_rad;
227   INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
228     difference(){
229       cube(offr*2 - 0.1, center=true);
230       translate([offr, offr, 0])
231         cylinder(center=true, h=20, r= offr);
232     }
233   }
234 }
235
236 module RoundCornerAdd(ci) {
237   this_cnr = ci[0];
238   right_cnr = ci[1];
239   bigr = round_cnr_rad - round_edge_rad;
240   INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
241     intersection(){
242       cube(bigr*2 + 0.1, center=true);
243       translate([bigr, bigr, 0])
244         rotate_extrude(convexity=10, $fn=50)
245         translate([bigr, 0])
246         difference(){
247           circle(r= round_edge_rad, $fn=50);
248           mirror([1,1])
249             square([20,20]);
250         }
251     }
252   }
253 }
254
255 module InterlockLobePlan(negative) {
256   r = negative ? interlock_negative_rad : interlock_rad;
257   ymir = negative ? 0 : 1;
258
259   dx = sqrt(3) * r;
260   $fn= 80;
261   translate([thehd[0], 0]){
262     mirror([0,ymir]){
263       circle(r=r);
264       difference(){
265         translate([-dx, -0.1])
266           square([ dx*2, r/2 + 0.1 ]);
267         for (xi = [-1, 1]) {
268           translate([ xi*dx, r ])
269             circle(r=r);
270         }
271       }
272     }
273   }
274 }
275
276 module InterlockEdgePlan(negative, nlobes, length, dosquare=true) {
277   for (lobei = [ 0 : nlobes-1 ]) {
278     lobex = (length - thehd[0]*2) * (lobei ? lobei / (nlobes-1) : 0);
279     translate([lobex, 0, 0]) {
280       InterlockLobePlan(negative);
281     }
282   }
283
284   if (dosquare) {
285     iadj = 0;
286     slotshorter = negative ? -0.1 : interlock_fine_lenslop;
287     mirror([0, negative])
288       translate([slotshorter, iadj])
289       square([length - slotshorter*2, interlock_fine + iadj*2]);
290   }
291 }
292
293 module InterlockEdge(left_cnr, right_cnr, negative=0, nlobes=2) {
294   plusth = negative * 1.0;
295   protr = interlock_fine + interlock_sq_adj;
296
297   z2 = -tile_th/2;
298   z1 = -tile_th/2 - protr / interlock_fine_slope;
299   z3 = -tile_th/2 + protr / interlock_fine_slope;
300
301   negsign = negative ? -1 : +1;
302   yprotr = negsign * protr;
303
304   INREFFRAME(left_cnr, right_cnr) {
305     for (vsect = [ // zs0            zs1      ys0,            ys1
306                   [ -tile_th-plusth, plusth,  0,              0],
307                   [ z1,              z2,      0, yprotr],
308                   [ z2,              z3,      yprotr, 0],
309                   ]) {
310       zs0 = vsect[0];
311       zs1 = vsect[1];
312       zsd = zs1-zs0;
313       ys0 = vsect[2];
314       ys1 = vsect[3];
315       ysd = ys1-ys0;
316       sl = ysd/zsd;
317       m = [ [ 1,0,   0,    0 ],
318             [ 0,1, -sl, -ys0 + negsign*interlock_sq_adj ],
319             [ 0,0,   1,  zs0 ],
320             [ 0,0,   0,    1 ] ];
321       multmatrix(m)
322         linear_extrude(height=zsd, convexity=10)
323         InterlockEdgePlan(negative, nlobes, length, !!ysd);
324     }
325   }
326 }
327
328 function TestPiece_holes2corners(holes) =
329   [ holes[0] + thehd_bl,
330     holes[1] + thehd_br,
331     holes[1] + thehd_tr,
332     holes[0] + thehd_tl ];
333
334 module TestPiece1(){ ////toplevel
335   holes = [ [-100, 0],
336             [   0, 0]
337             ];
338   corners = TestPiece_holes2corners(holes);
339   rcs = [corners[0], corners[1]];
340   difference(){
341     union(){
342       TileBase(corners[0], corners[2]);
343       Posts(holes);
344       RoundEdge(corners[0], corners[1]);
345       RoundEdge(corners[3], corners[0]);
346     }
347     InterlockEdge(corners[1], corners[2], 1, nlobes=1);
348     RoundCornerCut(rcs);
349   }
350   RoundCornerAdd(rcs);
351 }
352
353 module TestPiece2(){ ////toplevel
354   holes = [ [   0, 0],
355             [  50, 0]
356             ];
357   corners = TestPiece_holes2corners(holes);
358   TileBase(corners[0], corners[2]);
359   Posts(holes);
360   RoundEdge(corners[0], corners[1]);
361   InterlockEdge(corners[3], corners[0], 0, nlobes=1);
362 }
363
364 module TestDemo(){ ////toplevel
365   translate([ -thehd[0], 0 ])
366     color("blue")
367     TestPiece1();
368   translate([ +thehd[0] + demo_slop, 0 ])
369     TestPiece2();
370 }
371
372 module Machine_Arm(){
373   ysz = cutout_l_end_y_total;
374   // assume the round end is arc of a circle
375   chordlen = dist2d([0,0], [ cutout_l_end_y, cutout_l_end_curve ]);
376   endrad = cutout_l_end_y / cutout_l_end_curve * chordlen;
377   
378   translate([0,0,-30]) linear_extrude(height=60) {
379     translate(tile01_tr + [0, (-cutout_tile01_y + cutout_tile11_y)/2]) {
380       intersection(){
381         translate([-100, -ysz/2])
382           square([400, ysz]);
383         translate([ endrad - cutout_tile11_x - cutout_l_end_x_slop, 0 ])
384           circle(r=endrad, $fa=0.01,$fd=5);
385       }
386     }
387   }
388 }
389
390 module Machine_Profile(){
391   first_rear = machine_rear_profile[0];
392   below_point = 0.5 * ( first_rear + first_front ) + [ 0, -10 ];
393   pol = concat( machine_rear_profile,
394                 [ below_point ],
395                 machine_front_profile);
396   skew_angle = atan2( first_front[1] - first_rear[1],
397                       first_front[0] - first_rear[0] );
398   echo(below_point, pol, skew_angle);
399   hull(){
400     for (z=[0,-40]) {
401       translate([0,z]) {
402         //scale([1,5])
403         rotate([0,0, -skew_angle ]){
404           //translate( - first_front )
405           polygon(pol);
406         }
407       }
408     }
409   }
410 }
411
412 module Machine_RearProfile(){
413   intersection(){
414     Machine_Profile();
415     translate([ -200 + machine_rear_to_front/2, -100 ]) {
416       square([200,200]);
417     }
418   }
419 }
420
421 module Machine_Curves(){ ////toplevel
422   translate([ tile01_tr[0] - cutout_l_end_x + rearedge_len,
423               cutout_tile11_y,
424               0 ]){
425     //%cube([20,20,20]);
426     translate([ -reartablet_x,
427                 -1,
428                 -reartablet_z])
429       mirror([0,0,1])
430       cube([ reartablet_x+1,
431              reartablet_y+1,
432              20 ]);
433   }
434   translate([ tile01_tr[0] - cutout_l_end_x + rearedge_len,
435               cutout_tile11_y,
436               0 ]){
437     translate([ rearcurve_strt_len,
438                 0,
439                 rearcurve_z_slop ]){
440       translate([ 1,
441                   0,
442                   0
443                   ]){
444         rotate([0,-90,0])rotate([0,0,-90]){
445           linear_extrude(height= rearcurve_strt_len + 1)
446           Machine_RearProfile();
447         }
448       }
449       translate([ 0,
450                   0,
451                   rearcurve_double_inrad ]) {
452         intersection(){
453           rotate([90,0,0]){
454             rotate_extrude(convexity=10, $fn=32) {
455               rotate([0,0,90]) translate([ 0,
456                           -rearcurve_double_inrad ]) {
457                 Machine_RearProfile();
458               }
459             }
460           }
461           mirror([0,0,1])
462             translate([0,-75,0]) cube([150,150,150]);
463         }
464       }
465     }
466   }
467 }
468
469 module Machine(){ ////toplevel
470   Machine_Arm();
471   Machine_Curves();
472 }
473   
474 function Rectangle_corners(c0, sz) =
475   // returns the corners of a rectangle from c0 to c0+sz
476   // if sz is positive, the corners are anticlockwise starting with c0
477   [ c0 + [ 0,     0     ],
478     c0 + [ sz[0], 0     ],
479     c0 + [ sz[0], sz[1] ],
480     c0 + [ 0,     sz[1] ] ];
481
482 function Rectangle_corners2posts(c) =
483   [ c[0] + thehd_tr,
484     c[1] + thehd_tl,
485     c[2] + thehd_bl,
486     c[3] + thehd_br ];
487
488 module Rectangle_TileBase(c) { TileBase(c[0], c[2]); }
489
490 function Posts_interpolate_one(c0,c1) = [c0, (c0+c1)/2, c1];
491
492 m4_dnl   R_EDGE(c,ix)
493 m4_dnl        c is from Rectangle_corners and
494 m4_dnl        ix is a corner number
495 m4_dnl    expands to two comma-separated corners:
496 m4_dnl    that denoted by ix, and the next one anticlockwise
497 m4_define(`R_EDGE',`$1[$2],$1[(($2)+1)%4]')
498
499 module Tile02(){ ////toplevel
500   sz = [100,170];
501   c0 = tile02_tr + -sz;
502   c = Rectangle_corners(c0, sz);
503   posts = Rectangle_corners2posts(c);
504   rcs = [R_EDGE(c,0)];
505   difference(){
506     union(){
507       Rectangle_TileBase(c);
508       Posts(posts);
509       RoundEdge(R_EDGE(c,0));
510       RoundEdge(R_EDGE(c,3));
511       InterlockEdge(R_EDGE(c,2), 0);
512     }
513     InterlockEdge(R_EDGE(c,1), 1);
514     RoundCornerCut(rcs);
515   }
516   RoundCornerAdd(rcs);
517 }
518
519 module Tile12(){ ////toplevel
520   sz = [100,250];
521   c0 = tile02_tr + [-sz[0], 0];
522   c = Rectangle_corners(c0, sz);
523   posts = Rectangle_corners2posts(c);
524   rcs = [R_EDGE(c,3)];
525   difference(){
526     union(){
527       Rectangle_TileBase(c);
528       Posts(posts);
529       RoundEdge(R_EDGE(c,2));
530       RoundEdge(R_EDGE(c,3));
531     }
532     InterlockEdge(R_EDGE(c,0), 1);
533     InterlockEdge(R_EDGE(c,1), 1);
534     RoundCornerCut(rcs);
535   }
536   RoundCornerAdd(rcs);
537 }
538
539 tile_01_11_cnr = tile01_tr + [-cutout_tile11_x, 0];
540 tile_11_10_cnr = tile01_tr + [0, cutout_tile11_y];
541
542 module Tile11(){ ////toplevel
543   sz = [250,250];
544   c0 = tile02_tr + [0,0];
545   c = Rectangle_corners(c0, sz);
546   cnr_posts = Rectangle_corners2posts(c);
547   posts = concat(
548                  Posts_interpolate_one(cnr_posts[0],
549                                        cnr_posts[1] - [cutout_tile11_x, 0]),
550                  [ cnr_posts[1] + [0, cutout_tile11_y],
551                    cnr_posts[2],
552                    cnr_posts[3]
553                    ]);
554   difference(){
555     union(){
556       Rectangle_TileBase(c);
557       Posts(posts);
558       RoundEdge(R_EDGE(c,2));
559       InterlockEdge(R_EDGE(c,3));
560     }
561     InterlockEdge(c[0], tile_01_11_cnr, 1);
562     InterlockEdge(tile_11_10_cnr, c[2], 1);
563     Machine();
564   }
565 }    
566
567 tile_01_00_cnr = tile01_tr + [0, -cutout_tile01_y];
568
569 module Tile01(){ ////toplevel
570   sz = [250,170];
571   c0 = tile02_tr + [0,-sz[1]];
572   c = Rectangle_corners(c0, sz);
573   cnr_posts = Rectangle_corners2posts(c);
574   posts = concat(
575                  Posts_interpolate_one(R_EDGE(cnr_posts,0)),
576                  [ cnr_posts[2] + [0, -cutout_tile01_y] ],
577                  Posts_interpolate_one(cnr_posts[2] - [cutout_tile11_x, 0],
578                                        cnr_posts[3])
579                  );
580   difference(){
581     union(){
582       Rectangle_TileBase(c);
583       Posts(posts);
584       RoundEdge(R_EDGE(c,0));
585       InterlockEdge(tile_01_11_cnr, c[3]);
586       InterlockEdge(R_EDGE(c,3));
587     }
588     InterlockEdge(c[1], tile_01_00_cnr, 1);
589     Machine();
590   }
591 }    
592
593 module Tile10(){ ////toplevel
594   sz = [250,250];
595   c0 = tile02_tr + [sz[0],0];
596   c = Rectangle_corners(c0, sz);
597   cnr_posts = Rectangle_corners2posts(c);
598   cty = cutout_tile11_y;
599   rcy = cty + rearcurve_avoid_y;
600   posts = [ cnr_posts[0] + [ 0,                             cty ],
601             cnr_posts[1] + [ -sz[1] + rearedge_len - cutout_l_end_x, cty ],
602             cnr_posts[1] + [ 0,                             rcy ],
603             cnr_posts[2],
604             cnr_posts[3] ];
605   rcs = [R_EDGE(c,2)];
606   difference(){
607     union(){
608       Rectangle_TileBase(c);
609       Posts(posts);
610       RoundEdge(R_EDGE(c,1));
611       RoundEdge(R_EDGE(c,2));
612       InterlockEdge(c[3], tile_11_10_cnr);
613     }
614     RoundCornerCut(rcs);
615     Machine();
616   }
617   RoundCornerAdd(rcs);
618 }
619
620 module Demo(){ ////toplevel
621   translate(demo_slop*[-2,1]) color("blue") Tile12();
622   translate(demo_slop*[-2,0]) color("red")  Tile02();
623   translate(demo_slop*[-2,1]) color("orange") Tile11();
624   translate(demo_slop*[-2,0]) color("purple") Tile01();
625   translate(demo_slop*[-3,1]) color("blue")   Tile10();
626   %Machine();
627 }
628   
629 //TestPiece1();
630 //TestPiece2();
631 //Demo();
632
633 //Machine_Profile();
634 //Machine_RearProfile();