chiark / gitweb /
4d438b7486c3eef470af9398630b8c97d8036a35
[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 = 84 + 0.25 - 1.4;
34
35 cutout_l_end_y_front_slop = 0.5;
36 cutout_l_end_y_rear_slop = 0.5;
37 cutout_l_end_x_slop = 0.25;
38
39 cutout_l_end_x = 22;
40 cutout_l_end_y = machine_rear_to_front;
41 cutout_l_end_curve = 1;
42 cutout_l_end_y_total = cutout_l_end_y
43   + cutout_l_end_y_front_slop + cutout_l_end_y_rear_slop;
44
45 tile02_tr = [-250, 0];
46 tile01_tr = [  0, 0];
47
48 cutout_tile01_y = 170 - 147 + cutout_l_end_y_front_slop;
49 cutout_tile11_x = cutout_l_end_x + cutout_l_end_curve;
50 cutout_tile11_y = cutout_l_end_y_total - cutout_tile01_y;
51
52 // front and rear curves
53
54 rearedge_len = 170;
55
56 rearcurve_strt_len = 52;
57
58 rearcurve_z_slop = -0.50;
59
60 rearcurve_avoid_y = 35;
61
62 rearcurve_double_inrad = 26.10 + 8.04;
63
64 reartablet_z = 2.54;
65 reartablet_x = 5 + 1;
66 reartablet_y = 8;
67
68 frontcurve_side_skew = 3.5 / 72;
69 frontcurve_avoid_y = 70;
70 frontcurve_z_slop = 0.75;
71
72 frontcurve_strt_len = 50;
73 frontcurve_dualcurve_angle = 30;
74
75 // calculated
76
77 TEST = false;
78
79 ply_edge_hole_dist = ply_edge_min + ply_hole_dia/2;
80
81 echo(str("HOLES IN PLY ctr dist from PLY edge = ", ply_edge_hole_dist));
82
83 hole_slop = (ply_hole_dia - post_dia)/2;
84 tile_hard_edge_hole_dist = ply_edge_hole_dist + hole_slop;
85
86 echo(str("HOLES IN PLY ctr dist from TILE HARD edge = ",
87          tile_hard_edge_hole_dist));
88
89 echo(str("HOLES IN PLY ctr dist from TILE ROUND edge = ",
90          tile_hard_edge_hole_dist + round_edge_rad));
91
92 thehd = [ tile_hard_edge_hole_dist, tile_hard_edge_hole_dist ];
93 thehd_tr = thehd;
94 thehd_tl = [ -thehd_tr[0], thehd_tr[1] ];
95 thehd_bl = -thehd_tr;
96 thehd_br = -thehd_tl;
97
98 tablet_z_slop = rearcurve_z_slop;
99
100 interlock_rad = interlock_dia/2;
101 interlock_negative_rad = interlock_rad + 0.125;
102
103 interlock_sq_adj = 0.2; // arbitrary
104
105 m4_define(`POST_TCROSSSZ',
106           `2*( tile_hard_edge_hole_dist - test_edge + 1 )')
107
108 module Post(){
109   mirror([0,0,1]) {
110     difference(){
111       cylinder(r= post_dia/2, h= tile_th + ply_th - post_shorter);
112       translate([0,0, tile_th]) {
113         cylinder(r= screw_big_dia/2, h= screw_big_len);
114         cylinder(r= screw_dia/2, h= ply_th, $fn=20);
115       }
116     }
117     if (TEST) {
118       translate([0,0, tile_th/2]) {
119         cube([post_dia,      POST_TCROSSSZ, tile_th], center=true);
120         cube([POST_TCROSSSZ, post_dia,      tile_th], center=true);
121       }
122     }
123   }
124 }
125
126 module Posts(posts) {
127   for (p= posts) {
128     translate(concat(p, [0]))
129       Post();
130   }
131 }
132
133 module TileBase(botleft, topright){
134   size = topright - botleft;
135   botleft_post = botleft + thehd_tr;
136   topright_post = topright + thehd_bl;
137   difference(){
138     mirror([0,0,1])
139       translate(concat(botleft, [0]))
140       cube(concat(size, [tile_th]));
141     if (!TEST) {
142       cidsz = topright_post-botleft_post
143         + [-post_dia,-post_dia]
144         + [0, thehd[1]];
145       cidszr = [ min(cidsz[0],50), min(cidsz[1],50) ];
146       echo("CID",cidsz,cidszr);
147       translate( concat(botleft_post, [ -tile_th ])
148                  + 0.5 * [ post_dia, post_dia, 0 ]
149                  + 0.5 * concat( cidsz - cidszr, [ 0 ]) )
150         Commitid_BestCount_M(cidszr);
151     }
152     if (TEST) {
153       crossoff = tile_hard_edge_hole_dist + POST_TCROSSSZ/2;
154       cidsz = [ thehd[0], size[1] - 2*crossoff ];
155       cidszr = [ cidsz[0], min(cidsz[1], 50) ];
156       translate( concat(botleft + [0, crossoff] + (cidsz-cidszr)/2, [0]) )
157         Commitid_BestCount(cidszr);
158       difference(){
159         mirror([0,0,1]) {
160           translate(concat(botleft + [test_edge,test_edge], [test_tile_th]))
161             cube(concat(size - [test_edge,test_edge]*2, [tile_th]));
162           translate(concat(botleft_post, [-1]))
163             cube(concat(topright_post-botleft_post, [tile_th+2]));
164         }
165         shufflesz = max(test_edge, tile_hard_edge_hole_dist)*2;
166         minkowski(){
167           MachineEnvelope();
168           cube(shufflesz, center=true);
169         }
170       }
171     }
172   }
173 }
174
175 m4_dnl   R_EDGE(c,ix)
176 m4_dnl        c is from Rectangle_corners and
177 m4_dnl        ix is a corner number
178 m4_dnl    expands to two comma-separated corners:
179 m4_dnl    that denoted by ix, and the next one anticlockwise
180 m4_define(`R_EDGE',`$1[$2], $1[(($2)+1)%4]')
181
182 m4_dnl   R_CNR(c,ix)
183 m4_dnl        c is from Rectangle_corners and
184 m4_dnl        ix is a corner number
185 m4_dnl    expands to an array of corners as for RoundCorner
186 m4_define(`R_CNR',`[ $1[$2], $1[(($2)+1)%4], $1[(($2)+3)%4] ]')
187
188 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars) { body; }
189 m4_define(`INREFFRAME',`
190   length_vec = ($2) - ($1);
191   length = dist2d([0,0], length_vec);
192   length_uvec = length_vec / length;
193   ortho_uvec = [ -length_uvec[1], length_uvec[0] ];
194   m = [ [ length_uvec[0],  ortho_uvec[0], 0, ($1)[0], ],
195         [ length_uvec[1],  ortho_uvec[1], 0, ($1)[1], ],
196         [ 0,              0,              1,            0, ],
197         [ 0,              0,              0,            1, ] ];
198   $3
199   multmatrix(m)
200 ')
201
202 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars)
203 m4_dnl    INREFFRAME_EDGE { body; }
204 m4_define(`INREFFRAME_EDGE',`
205   translate([0,0, -round_edge_rad])
206 ')
207
208 module RoundEdge(left_cnr, right_cnr) {
209   INREFFRAME(left_cnr, right_cnr)
210     INREFFRAME_EDGE {
211     difference(){
212       rotate([0,90,0])
213         cylinder(r= round_edge_rad, h= length, $fn=50);
214       translate([-1, 0, -20])
215         cube([length+2, 20, 20]);
216     }
217   }
218 }
219
220 m4_define(`ROUNDCORNER_VARS',`
221   this_cnr = ci[0];
222   right_cnr = ci[1];
223   left_cnr = ci[2];
224   bigr= round_cnr_rad - round_edge_rad;
225   l_uvec = unitvector2d(left_cnr - this_cnr);
226   r_uvec = unitvector2d(right_cnr - this_cnr);
227   lp1 = left_cnr  + clockwise2d(l_uvec) * bigr;
228   lp2 = this_cnr  + clockwise2d(l_uvec) * bigr;
229   lp3 = this_cnr  - clockwise2d(r_uvec) * bigr;
230   lp4 = right_cnr - clockwise2d(r_uvec) * bigr;
231   ctr = line_intersection_2d(lp1,lp2,lp3,lp4);
232   ctr3 = concat(ctr,[0])
233 ')
234
235 module RoundCorner_selector(ci, adj) {
236   ROUNDCORNER_VARS;
237   intersection(){
238     union(){
239       INREFFRAME(ctr3,concat(lp1,[4])){
240         translate([0,0,-bigr]) linear_extrude(height=bigr*2) {
241           translate([-bigr*2 + adj, -bigr])
242             square([bigr*2, bigr*3]);
243         }
244       }
245     }
246     union(){
247       INREFFRAME(ctr3,concat(lp4,[0])){
248         translate([0,0,-bigr]) linear_extrude(height=bigr*2) {
249           translate([-bigr*2, -bigr*2])
250             square([bigr*2 + adj, bigr*3]);
251         }
252       }
253     }
254   }
255 }
256
257 module RoundCornerCut(ci) {
258   // ci should be [this_cnr, right_cnr, left_cnr]
259   // where right_cnr is to the right (ie, anticlockwise)
260   ROUNDCORNER_VARS;
261   difference(){
262     RoundCorner_selector(ci, -0.1);
263     translate(ctr3)
264       cylinder(center=true, h=20, r= bigr);
265   }
266 }
267
268 module RoundCornerAdd(ci) {
269   ROUNDCORNER_VARS;
270   intersection(){
271     RoundCorner_selector(ci, +0.1);
272     INREFFRAME_EDGE {
273       translate(ctr3){
274         rotate_extrude(convexity=10, $fn=50)
275           translate([bigr, 0])
276           difference(){
277           circle(r= round_edge_rad, $fn=50);
278           mirror([1,1])
279             square([20,20]);
280         }
281       }
282     }
283   }
284 }
285
286 module InterlockLobePlan(negative) {
287   r = negative ? interlock_negative_rad : interlock_rad;
288   ymir = negative ? 0 : 1;
289
290   dx = sqrt(3) * r;
291   $fn= 80;
292   translate([thehd[0], 0]){
293     mirror([0,ymir]){
294       circle(r=r);
295       difference(){
296         translate([-dx, -0.1])
297           square([ dx*2, r/2 + 0.1 ]);
298         for (xi = [-1, 1]) {
299           translate([ xi*dx, r ])
300             circle(r=r);
301         }
302       }
303     }
304   }
305 }
306
307 module InterlockEdgePlan(negative, nlobes, length, dosquare=true) {
308   for (lobei = [ 0 : nlobes-1 ]) {
309     lobex = (length - thehd[0]*2) * (lobei ? lobei / (nlobes-1) : 0);
310     translate([lobex, 0, 0]) {
311       InterlockLobePlan(negative);
312     }
313   }
314
315   if (dosquare) {
316     iadj = 0;
317     slotshorter = negative ? -0.1 : interlock_fine_lenslop;
318     mirror([0, negative])
319       translate([slotshorter, iadj])
320       square([length - slotshorter*2, interlock_fine + iadj*2]);
321   }
322 }
323
324 module InterlockEdge(left_cnr, right_cnr, negative=0, nlobes=2) {
325   plusth = negative * 1.0;
326   protr = interlock_fine + interlock_sq_adj;
327
328   z2 = -tile_th/2;
329   z1 = -tile_th/2 - protr / interlock_fine_slope;
330   z3 = -tile_th/2 + protr / interlock_fine_slope;
331
332   negsign = negative ? -1 : +1;
333   yprotr = negsign * protr;
334
335   INREFFRAME(left_cnr, right_cnr) {
336     for (vsect = [ // zs0            zs1      ys0,            ys1
337                   [ -tile_th-plusth, plusth,  0,              0],
338                   [ z1,              z2,      0, yprotr],
339                   [ z2,              z3,      yprotr, 0],
340                   ]) {
341       zs0 = vsect[0];
342       zs1 = vsect[1];
343       zsd = zs1-zs0;
344       ys0 = vsect[2];
345       ys1 = vsect[3];
346       ysd = ys1-ys0;
347       sl = ysd/zsd;
348       m = [ [ 1,0,   0,    0 ],
349             [ 0,1, -sl, -ys0 + negsign*interlock_sq_adj ],
350             [ 0,0,   1,  zs0 ],
351             [ 0,0,   0,    1 ] ];
352       multmatrix(m)
353         linear_extrude(height=zsd, convexity=10)
354         InterlockEdgePlan(negative, nlobes, length, !!ysd);
355     }
356   }
357 }
358
359 function TestPiece_holes2corners(holes) =
360   [ holes[0] + thehd_bl,
361     holes[1] + thehd_br,
362     holes[1] + thehd_tr,
363     holes[0] + thehd_tl ];
364
365 module TestPiece1(){ ////toplevel
366   holes = [ [-100, 0],
367             [   0, 0]
368             ];
369   corners = TestPiece_holes2corners(holes);
370   rcs = R_CNR(corners,0);
371   difference(){
372     union(){
373       TileBase(corners[0], corners[2]);
374       Posts(holes);
375       RoundEdge(corners[0], corners[1]);
376       RoundEdge(corners[3], corners[0]);
377     }
378     InterlockEdge(corners[1], corners[2], 1, nlobes=1);
379     RoundCornerCut(rcs);
380   }
381   RoundCornerAdd(rcs);
382 }
383
384 module TestPiece2(){ ////toplevel
385   holes = [ [   0, 0],
386             [  50, 0]
387             ];
388   corners = TestPiece_holes2corners(holes);
389   TileBase(corners[0], corners[2]);
390   Posts(holes);
391   RoundEdge(corners[0], corners[1]);
392   InterlockEdge(corners[3], corners[0], 0, nlobes=1);
393 }
394
395 module TestDemo(){ ////toplevel
396   translate([ -thehd[0], 0 ])
397     color("blue")
398     TestPiece1();
399   translate([ +thehd[0] + demo_slop, 0 ])
400     TestPiece2();
401 }
402
403 module Machine_Arm(){
404   ysz = cutout_l_end_y_total;
405   // assume the round end is arc of a circle
406   chordlen = dist2d([0,0], [ cutout_l_end_y, cutout_l_end_curve ]);
407   endrad = cutout_l_end_y / cutout_l_end_curve * chordlen;
408   
409   translate([0,0,-30]) linear_extrude(height=60) {
410     translate(tile01_tr + [0, (-cutout_tile01_y + cutout_tile11_y)/2]) {
411       intersection(){
412         translate([-50, -ysz/2])
413           square([400, ysz]);
414         translate([ endrad - cutout_tile11_x - cutout_l_end_x_slop, 0 ])
415           circle(r=endrad, $fa=0.01,$fd=5);
416       }
417     }
418   }
419 }
420
421 module Machine_NewRearProfile(){
422   // figures copied out of xfig edit boxes
423   // best not to edit the posbox size if poss - just move it
424   posbox = 10 * ([7.2333,-14.1267] - [-16.2289,40.0289]); // box, Green
425   sideline = -10 * ([-6.2400,13.5600] - [-2.4467,28.2556]); // line, Blue
426   scaleline = 10 * dist2d([-1.1911,-20.4800], [-11.2600,4.0578]); // Green2
427   scaleline_mm = 12+5+10+5+3;
428   sh = -[abs(posbox[0]), abs(posbox[1])];
429   rot = atan2(-sideline[0], sideline[1]);
430   sc = scaleline_mm / scaleline;
431   //echo("SH",sh,rot,sc);
432   scale(sc) rotate(rot) translate(sh){
433     import("sewing-table-rear-profile.dxf", convexity=10); // spline, Pink3
434   }
435 }
436
437 module Machine_NewFrontProfile(){
438   // figures copied out of xfig edit boxes
439   // best not to edit the posbox size if poss - just move it
440   posbox = 10 * ([11.8022,8.0600] - [4.2044,19.1867]); // box, Green
441   refline = 10 * ([7.6778,16.7222] - [27.8689,17.6578]); // line, Blue
442   refline_mm = (11-1)*10;
443   sh = -[abs(posbox[0]), abs(posbox[1])];
444   rot = atan2(-refline[0], refline[1]);
445   sc = refline_mm / vectorlen2d(refline);
446   //echo("SH",sh,rot,sc);
447   mirror([1,0]) scale(sc) rotate(rot+90) translate(sh){
448     import("sewing-table-front-profile.dxf", convexity=10); // spline, Pink3
449   }
450 }
451
452 module Machine_NewRearCurve(){
453   slant = atan2(4,210-10);
454   //echo("SL",slant);
455   translate([0,0, rearcurve_double_inrad]) rotate([slant,0,0]){
456     translate([ rearcurve_double_inrad,
457                 0,
458                 -rearcurve_double_inrad + 10 ]){
459       rotate([180,0,0]) rotate([0,0,90]) linear_extrude(height=30){
460         hull(){
461           Machine_NewRearProfile();
462           translate([0,-100]) Machine_NewRearProfile();
463         }
464       }
465     }
466     rotate([0,90,0]) rotate([90,0,0]) {
467       intersection(){
468         rotate_extrude(convexity=10, $fn=64)
469           rotate(90)
470           translate([ 0, -rearcurve_double_inrad ])
471           Machine_NewRearProfile();
472         translate([0,0,-500])
473           cube([500,500,1000]);
474       }
475     }
476     translate([1,0,-rearcurve_double_inrad])
477       rotate([0,-90,0]) rotate([0,0,-90])
478       linear_extrude(height= rearcurve_strt_len + 1)
479       Machine_NewRearProfile();
480   }
481 }
482
483 module Machine_Curves(){ ////toplevel
484   translate([ tile01_tr[0] - cutout_l_end_x + rearedge_len,
485               cutout_tile11_y,
486               0 ]){
487     //%cube([20,20,20]);
488     translate([ -reartablet_x,
489                 -1,
490                 -reartablet_z + tablet_z_slop])
491       mirror([0,0,1])
492       cube([ reartablet_x+1,
493              reartablet_y+1,
494              20 ]);
495   }
496   translate([ tile01_tr[0] - cutout_l_end_x + rearedge_len,
497               cutout_tile11_y,
498               frontcurve_z_slop ]){
499     translate([0, -machine_rear_to_front, 0])
500       multmatrix([[1, -frontcurve_side_skew, 0, 0],
501                   [0,  1,   0, 0],
502                   [0,  0,   1, 0],
503                   [0,  0,   0, 1]])
504       mirror([1,0,0]) rotate([0,-90,0])rotate([0,0,-90])
505       linear_extrude(height= 200)
506       Machine_NewFrontProfile();
507
508     translate([ rearcurve_strt_len,
509                 0,
510                 rearcurve_z_slop ]){
511       Machine_NewRearCurve();
512     }
513   }
514 }
515
516 module TestStrapSlots(){
517   at = [[ 110, 70 ],
518         [ 180, 90 ],
519         ];
520   pegwidth = 7.5;
521   strap = [ 3, 5 ];
522   for (pos = at) {
523     echo("TSS",pos);
524     translate(concat(pos,[0]))
525       for (mx = [0,1]) mirror([mx,0,0]) {
526           translate([ pegwidth/2, -strap[1]/2, -20 ])
527             #cube(concat(strap,[40]));
528         }
529   }
530 }
531
532 module Machine(){ ////toplevel
533   Machine_Arm();
534   Machine_Curves();
535   if (TEST)
536     TestStrapSlots();
537 }
538
539 module MachineEnvelope(){
540   // used for testing
541   p_arm_bl = [-cutout_tile11_x, -cutout_tile01_y];
542   y_arm_t  = cutout_tile11_y;
543   p_crv_fl = p_arm_bl + [rearedge_len, -frontcurve_avoid_y];
544   y_crv_b  = y_arm_t + rearcurve_avoid_y;
545
546   translate([0,0,-50]) linear_extrude(height= 100){
547     translate(p_arm_bl) square([400, y_arm_t] - p_arm_bl);
548     translate(p_crv_fl) square([400, y_crv_b] - p_crv_fl);
549   }
550 }
551
552 function Rectangle_corners(c0, sz) =
553   // returns the corners of a rectangle from c0 to c0+sz
554   // if sz is positive, the corners are anticlockwise starting with c0
555   [ c0 + [ 0,     0     ],
556     c0 + [ sz[0], 0     ],
557     c0 + [ sz[0], sz[1] ],
558     c0 + [ 0,     sz[1] ] ];
559
560 function Rectangle_corners2posts(c) =
561   [ c[0] + thehd_tr,
562     c[1] + thehd_tl,
563     c[2] + thehd_bl,
564     c[3] + thehd_br ];
565
566 module Rectangle_TileBase(c) { TileBase(c[0], c[2]); }
567
568 function Posts_interpolate_one(c0,c1) = [c0, (c0+c1)/2, c1];
569
570 module Tile02(){ ////toplevel
571   sz = [100,170];
572   c0 = tile02_tr + -sz;
573   c = Rectangle_corners(c0, sz);
574   posts = Rectangle_corners2posts(c);
575   rcs = R_CNR(c,0);
576   difference(){
577     union(){
578       Rectangle_TileBase(c);
579       Posts(posts);
580       RoundEdge(R_EDGE(c,0));
581       RoundEdge(R_EDGE(c,3));
582       InterlockEdge(R_EDGE(c,2), 0);
583     }
584     InterlockEdge(R_EDGE(c,1), 1);
585     RoundCornerCut(rcs);
586   }
587   RoundCornerAdd(rcs);
588 }
589
590 module Tile12(){ ////toplevel
591   sz = [100,250];
592   c0 = tile02_tr + [-sz[0], 0];
593   c = Rectangle_corners(c0, sz);
594   posts = Rectangle_corners2posts(c);
595   rcs = R_CNR(c,3);
596   difference(){
597     union(){
598       Rectangle_TileBase(c);
599       Posts(posts);
600       RoundEdge(R_EDGE(c,2));
601       RoundEdge(R_EDGE(c,3));
602     }
603     InterlockEdge(R_EDGE(c,0), 1);
604     InterlockEdge(R_EDGE(c,1), 1);
605     RoundCornerCut(rcs);
606   }
607   RoundCornerAdd(rcs);
608 }
609
610 tile_01_11_cnr = tile01_tr + [-cutout_tile11_x, 0];
611 tile_11_10_cnr = tile01_tr + [0, cutout_tile11_y];
612 tile_01_00_cnr = tile01_tr - [0, cutout_tile01_y];
613
614 module Tile11(){ ////toplevel
615   sz = [250,250];
616   c0 = tile01_tr + [-sz[0],0];
617   c = Rectangle_corners(c0, sz);
618   cnr_posts = Rectangle_corners2posts(c);
619   posts = concat(
620                  Posts_interpolate_one(cnr_posts[0],
621                                        cnr_posts[1] - [cutout_tile11_x, 0]),
622                  [ cnr_posts[1] + [0, cutout_tile11_y],
623                    cnr_posts[2],
624                    cnr_posts[3]
625                    ]);
626   difference(){
627     union(){
628       Rectangle_TileBase(c);
629       Posts(posts);
630       RoundEdge(R_EDGE(c,2));
631       InterlockEdge(R_EDGE(c,3));
632     }
633     InterlockEdge(c[0], tile_01_11_cnr, 1);
634     InterlockEdge(tile_11_10_cnr, c[2], 1);
635     Machine();
636   }
637 }    
638
639 module Tile01(){ ////toplevel
640   sz = [250,170];
641   c0 = tile01_tr + -sz;
642   c = Rectangle_corners(c0, sz);
643   cnr_posts = Rectangle_corners2posts(c);
644   posts = concat(
645                  Posts_interpolate_one(R_EDGE(cnr_posts,0)),
646                  [ cnr_posts[2] + [0, -cutout_tile01_y] ],
647                  Posts_interpolate_one(cnr_posts[2] - [cutout_tile11_x, 0],
648                                        cnr_posts[3])
649                  );
650   difference(){
651     union(){
652       Rectangle_TileBase(c);
653       Posts(posts);
654       RoundEdge(R_EDGE(c,0));
655       InterlockEdge(tile_01_11_cnr, c[3]);
656       InterlockEdge(R_EDGE(c,3));
657     }
658     InterlockEdge(c[1], tile_01_00_cnr, 1);
659     Machine();
660   }
661 }    
662
663 module Tile10(){ ////toplevel
664   sz = [250,250];
665   c0 = tile01_tr + [0,0];
666   c = Rectangle_corners(c0, sz);
667   cnr_posts = Rectangle_corners2posts(c);
668   cty = cutout_tile11_y;
669   rcy = cty + rearcurve_avoid_y;
670   posts = [ cnr_posts[0] + [ 0,                             cty ],
671             cnr_posts[1] + [ -sz[0] + rearedge_len - cutout_l_end_x, cty ],
672             cnr_posts[1] + [ 0,                             rcy ],
673             cnr_posts[2],
674             cnr_posts[3] ];
675   rcs = R_CNR(c,2);
676   difference(){
677     union(){
678       Rectangle_TileBase(c);
679       Posts(posts);
680       RoundEdge(R_EDGE(c,1));
681       RoundEdge(R_EDGE(c,2));
682       InterlockEdge(c[3], tile_11_10_cnr);
683     }
684     RoundCornerCut(rcs);
685     Machine();
686   }
687   RoundCornerAdd(rcs);
688 }
689
690 module Tile00(){ ////toplevel
691   sz = [250,170];
692   c0 = tile01_tr + [0,-sz[1]];
693   c = Rectangle_corners(c0, sz);
694
695   // the edge c[1]..c[2] needs a diagonal chunk, from c1bis to c2bis
696   c2bis = [ -cutout_l_end_x + rearedge_len + frontcurve_strt_len, c[2][1] ];
697   c1bis = [ c[1][0],
698             c[2][1] -
699             (c[2][0] - c2bis[0]) * tan(90 - frontcurve_dualcurve_angle) ];
700
701   cnr_posts = Rectangle_corners2posts(c);
702   cty = cutout_tile01_y;
703   rcy = cty + frontcurve_avoid_y;
704   posts = [ cnr_posts[0],
705             cnr_posts[1],
706             cnr_posts[2] + [ 0,                             -rcy ],
707             cnr_posts[2] + [ -sz[0] + rearedge_len - cutout_l_end_x, -cty ],
708             cnr_posts[3] + [ 0,                             -cty ]
709             ];
710   rcs = R_CNR(c,1);
711   rc2 = [c1bis,c2bis,c[1]];
712   difference(){
713     union(){
714       difference(){
715         union(){
716           Rectangle_TileBase(c);
717           Posts(posts);
718           RoundEdge(R_EDGE(c,0));
719           RoundEdge(c[1], c1bis);
720           InterlockEdge(tile_01_00_cnr, c[0]);
721         }
722         RoundCornerCut(rcs);
723         translate([0,0,-20]) linear_extrude(height=40) {
724           polygon([ c1bis, c1bis + [50,0], c2bis + [50,0], c2bis ]);
725         }
726       }
727       RoundEdge(c1bis, c2bis);
728     }
729     Machine();
730     RoundCornerCut(rc2);
731   }
732   RoundCornerAdd(rcs);
733   RoundCornerAdd(rc2);
734 }
735
736 module FitTest_general(c0,sz, dobrace=false, bracexx=0){
737   c = Rectangle_corners(c0, sz);
738   brace = [7,7,9];
739   bsz = sz + [bracexx,0,0];
740   difference(){
741     union(){
742       Rectangle_TileBase(c);
743       if (dobrace) {
744         translate(concat(c0, [-brace[2] + 0.1])){
745           difference(){
746             cube(concat(bsz, [brace[2]]) - [5,0,0]);
747             translate(brace + [0,0, -25])
748               cube(concat(bsz, [50]) - brace*2 + [10,0,0]);
749           }
750         }
751       }
752       RoundEdge(R_EDGE(c,1));
753     }
754     Machine();
755   }
756 }
757
758 module FitTest_PairLink(cut=false){ ////toplevel
759   cy0=-55; cy1=85; cx=132;
760   bar = [10,10];
761   legrad = 12;
762   footrad_min = 1; footrad_max = 4; footrad_depth = 5;
763   strap = [3,5];
764   adj_neg_slop = 1.0;
765   bar_z_slop = 1.75;
766
767   // calculated
768   straphole_x_max = legrad/sqrt(2) + footrad_max;
769   dz = cut ? adj_neg_slop : 0;
770
771   translate([cx - bar[0]/2, cy0, dz + bar_z_slop])
772     cube([bar[0], cy1-cy0, bar[1] - bar_z_slop]);
773
774   for (endy=[cy0,cy1]) {
775     $fn=32;
776     translate([cx,endy,dz]){
777       // feet
778       for (rot=[45:90:315]) rotate(rot) {
779         translate([legrad,0,0]){
780           hull(){
781             cylinder(r= footrad_max, h=1);
782             translate([0,0,-footrad_depth])
783               cylinder(r= footrad_min, h=1);
784           }
785           translate([0,0,-10])
786             cylinder(r= footrad_min +
787                      adj_neg_slop * (footrad_max-footrad_min)/footrad_depth,
788                      h=20);
789         }
790       }
791       // legs
792       for (rot=[45,135]) rotate(rot) {
793         hull(){
794           for (s=[-1,+1]){
795             translate([s*legrad,0,0])
796               cylinder(r= footrad_max, h=bar[1]);
797           }
798         }
799       }
800       // strap holes
801       if (cut) {
802         for (rot=[0,180]) rotate(rot) {
803             translate([ straphole_x_max - strap[0]/2, 0,0 ])
804               cube(concat(strap,[20]), center=true);
805           }
806       }
807     }
808   }
809 }
810
811 module FitTest_RearCurve(){ ////toplevel
812   difference(){
813     FitTest_general([100,0], [180,100]);
814     FitTest_PairLink(true);
815     TestStrapSlots();
816   }
817 }
818
819 module FitTest_FrontCurve(){ ////toplevel
820   p0 = [110,-80];
821   sz = [170,80];
822   difference(){
823     intersection() {
824       Tile00();
825       translate([0,0,-8]) linear_extrude(height=18) {
826         translate(p0) square(sz);
827       }
828     }
829     FitTest_PairLink(true);
830   }
831 }
832
833 module FitTest_Entire(){ ////toplevel
834   p0 = [-40,-80];
835   szrear = [270,180];
836   szfront = [250,szrear[1]];
837   difference(){
838     FitTest_general(p0, szrear, dobrace=true, bracexx=0);
839     FitTest_PairLink(true);
840     translate(concat(p0,[0]) + [szfront[0],-10,-40])
841       cube([100, -p0[1], 80]);
842   }
843   intersection(){
844     FitTest_RearCurve();
845     translate(concat(p0,[-20])) cube(concat(szrear,[40]));
846   }
847   FitTest_FrontCurve();
848 }
849
850 module FitTest_EntireDemo(){ ////toplevel
851   FitTest_Entire();
852   //%Tile00();
853 }
854
855 module FitTest_PairDemo(){ ////toplevel
856   sh=[-90,-15,0];
857   translate(sh){
858     FitTest_PairLink();
859     %FitTest_FrontCurve();
860     %FitTest_RearCurve();
861   }
862   rotate([0,0,180]){
863     translate(sh){
864       difference(){
865         union(){
866           FitTest_FrontCurve();
867           FitTest_RearCurve();
868         }
869         #FitTest_PairLink(true);
870       }
871     }
872   }
873 }
874
875 module RoundCornerDemo_plat(cnr){
876   mirror([0,0,1]) linear_extrude(height=1) polygon(cnr);
877 }
878
879 module RoundCornerDemo(){ ////toplevel
880   cnr = [ [-2,-3], [13,-3], [-12,9] ];
881   translate([0,25,0]) RoundCornerDemo_plat(cnr);
882   translate([25,0,0]) RoundCornerAdd(cnr);
883   translate([-25,0,0]) RoundCornerCut(cnr);
884   translate([0,-25,0]) RoundCorner_selector(cnr, 0);
885   difference(){
886     RoundCornerDemo_plat(cnr);
887     RoundCornerCut(cnr);
888   }
889   RoundCornerAdd(cnr);
890 }
891
892 module Demo(){ ////toplevel
893   translate(demo_slop*[-2,1]) color("blue") Tile12();
894   translate(demo_slop*[-2,0]) color("red")  Tile02();
895   translate(demo_slop*[-2,1]) color("orange") Tile11();
896   translate(demo_slop*[-2,0]) color("purple") Tile01();
897   translate(demo_slop*[-3,1]) color("blue")   Tile10();
898   translate(demo_slop*[-3,0]) color("red")    Tile00();
899   %Machine();
900 }
901   
902 //TestPiece1();
903 //TestPiece2();
904 //Demo();
905
906 //Machine_NewRearProfile();
907 //Machine_NewRearCurve();
908 //Machine_NewFrontProfile();
909 //Machine_Curves();
910 //Machine();
911 //FitTest();
912 //MachineEnvelope();