chiark / gitweb /
6901f29a2d225b6b234ea182c6a103005c0348c2
[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 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.75;
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 Machine(){ ////toplevel
517   Machine_Arm();
518   Machine_Curves();
519 }
520
521 module MachineEnvelope(){
522   // used for testing
523   p_arm_bl = [-cutout_tile11_x, -cutout_tile01_y];
524   y_arm_t  = cutout_tile11_y;
525   p_crv_fl = p_arm_bl + [rearedge_len, -frontcurve_avoid_y];
526   y_crv_b  = y_arm_t + rearcurve_avoid_y;
527
528   translate([0,0,-50]) linear_extrude(height= 100){
529     translate(p_arm_bl) square([400, y_arm_t] - p_arm_bl);
530     translate(p_crv_fl) square([400, y_crv_b] - p_crv_fl);
531   }
532 }
533
534 function Rectangle_corners(c0, sz) =
535   // returns the corners of a rectangle from c0 to c0+sz
536   // if sz is positive, the corners are anticlockwise starting with c0
537   [ c0 + [ 0,     0     ],
538     c0 + [ sz[0], 0     ],
539     c0 + [ sz[0], sz[1] ],
540     c0 + [ 0,     sz[1] ] ];
541
542 function Rectangle_corners2posts(c) =
543   [ c[0] + thehd_tr,
544     c[1] + thehd_tl,
545     c[2] + thehd_bl,
546     c[3] + thehd_br ];
547
548 module Rectangle_TileBase(c) { TileBase(c[0], c[2]); }
549
550 function Posts_interpolate_one(c0,c1) = [c0, (c0+c1)/2, c1];
551
552 module Tile02(){ ////toplevel
553   sz = [100,170];
554   c0 = tile02_tr + -sz;
555   c = Rectangle_corners(c0, sz);
556   posts = Rectangle_corners2posts(c);
557   rcs = R_CNR(c,0);
558   difference(){
559     union(){
560       Rectangle_TileBase(c);
561       Posts(posts);
562       RoundEdge(R_EDGE(c,0));
563       RoundEdge(R_EDGE(c,3));
564       InterlockEdge(R_EDGE(c,2), 0);
565     }
566     InterlockEdge(R_EDGE(c,1), 1);
567     RoundCornerCut(rcs);
568   }
569   RoundCornerAdd(rcs);
570 }
571
572 module Tile12(){ ////toplevel
573   sz = [100,250];
574   c0 = tile02_tr + [-sz[0], 0];
575   c = Rectangle_corners(c0, sz);
576   posts = Rectangle_corners2posts(c);
577   rcs = R_CNR(c,3);
578   difference(){
579     union(){
580       Rectangle_TileBase(c);
581       Posts(posts);
582       RoundEdge(R_EDGE(c,2));
583       RoundEdge(R_EDGE(c,3));
584     }
585     InterlockEdge(R_EDGE(c,0), 1);
586     InterlockEdge(R_EDGE(c,1), 1);
587     RoundCornerCut(rcs);
588   }
589   RoundCornerAdd(rcs);
590 }
591
592 tile_01_11_cnr = tile01_tr + [-cutout_tile11_x, 0];
593 tile_11_10_cnr = tile01_tr + [0, cutout_tile11_y];
594 tile_01_00_cnr = tile01_tr - [0, cutout_tile01_y];
595
596 module Tile11(){ ////toplevel
597   sz = [250,250];
598   c0 = tile01_tr + [-sz[0],0];
599   c = Rectangle_corners(c0, sz);
600   cnr_posts = Rectangle_corners2posts(c);
601   posts = concat(
602                  Posts_interpolate_one(cnr_posts[0],
603                                        cnr_posts[1] - [cutout_tile11_x, 0]),
604                  [ cnr_posts[1] + [0, cutout_tile11_y],
605                    cnr_posts[2],
606                    cnr_posts[3]
607                    ]);
608   difference(){
609     union(){
610       Rectangle_TileBase(c);
611       Posts(posts);
612       RoundEdge(R_EDGE(c,2));
613       InterlockEdge(R_EDGE(c,3));
614     }
615     InterlockEdge(c[0], tile_01_11_cnr, 1);
616     InterlockEdge(tile_11_10_cnr, c[2], 1);
617     Machine();
618   }
619 }    
620
621 module Tile01(){ ////toplevel
622   sz = [250,170];
623   c0 = tile01_tr + -sz;
624   c = Rectangle_corners(c0, sz);
625   cnr_posts = Rectangle_corners2posts(c);
626   posts = concat(
627                  Posts_interpolate_one(R_EDGE(cnr_posts,0)),
628                  [ cnr_posts[2] + [0, -cutout_tile01_y] ],
629                  Posts_interpolate_one(cnr_posts[2] - [cutout_tile11_x, 0],
630                                        cnr_posts[3])
631                  );
632   difference(){
633     union(){
634       Rectangle_TileBase(c);
635       Posts(posts);
636       RoundEdge(R_EDGE(c,0));
637       InterlockEdge(tile_01_11_cnr, c[3]);
638       InterlockEdge(R_EDGE(c,3));
639     }
640     InterlockEdge(c[1], tile_01_00_cnr, 1);
641     Machine();
642   }
643 }    
644
645 module Tile10(){ ////toplevel
646   sz = [250,250];
647   c0 = tile01_tr + [0,0];
648   c = Rectangle_corners(c0, sz);
649   cnr_posts = Rectangle_corners2posts(c);
650   cty = cutout_tile11_y;
651   rcy = cty + rearcurve_avoid_y;
652   posts = [ cnr_posts[0] + [ 0,                             cty ],
653             cnr_posts[1] + [ -sz[0] + rearedge_len - cutout_l_end_x, cty ],
654             cnr_posts[1] + [ 0,                             rcy ],
655             cnr_posts[2],
656             cnr_posts[3] ];
657   rcs = R_CNR(c,2);
658   difference(){
659     union(){
660       Rectangle_TileBase(c);
661       Posts(posts);
662       RoundEdge(R_EDGE(c,1));
663       RoundEdge(R_EDGE(c,2));
664       InterlockEdge(c[3], tile_11_10_cnr);
665     }
666     RoundCornerCut(rcs);
667     Machine();
668   }
669   RoundCornerAdd(rcs);
670 }
671
672 module Tile00(){ ////toplevel
673   sz = [250,170];
674   c0 = tile01_tr + [0,-sz[1]];
675   c = Rectangle_corners(c0, sz);
676
677   // the edge c[1]..c[2] needs a diagonal chunk, from c1bis to c2bis
678   c2bis = [ -cutout_l_end_x + rearedge_len + frontcurve_strt_len, c[2][1] ];
679   c1bis = [ c[1][0],
680             c[2][1] -
681             (c[2][0] - c2bis[0]) * tan(90 - frontcurve_dualcurve_angle) ];
682
683   cnr_posts = Rectangle_corners2posts(c);
684   cty = cutout_tile01_y;
685   rcy = cty + frontcurve_avoid_y;
686   posts = [ cnr_posts[0],
687             cnr_posts[1],
688             cnr_posts[2] + [ 0,                             -rcy ],
689             cnr_posts[2] + [ -sz[0] + rearedge_len - cutout_l_end_x, -cty ],
690             cnr_posts[3] + [ 0,                             -cty ]
691             ];
692   rcs = R_CNR(c,1);
693   rc2 = [c1bis,c2bis,c[1]];
694   difference(){
695     union(){
696       difference(){
697         union(){
698           Rectangle_TileBase(c);
699           Posts(posts);
700           RoundEdge(R_EDGE(c,0));
701           RoundEdge(c[1], c1bis);
702           InterlockEdge(tile_01_00_cnr, c[0]);
703         }
704         RoundCornerCut(rcs);
705         translate([0,0,-20]) linear_extrude(height=40) {
706           polygon([ c1bis, c1bis + [50,0], c2bis + [50,0], c2bis ]);
707         }
708       }
709       RoundEdge(c1bis, c2bis);
710     }
711     Machine();
712     RoundCornerCut(rc2);
713   }
714   RoundCornerAdd(rcs);
715   RoundCornerAdd(rc2);
716 }
717
718 module FitTest_general(c0,sz, dobrace=false, bracexx=0){
719   c = Rectangle_corners(c0, sz);
720   brace = [7,7,9];
721   bsz = sz + [bracexx,0,0];
722   difference(){
723     union(){
724       Rectangle_TileBase(c);
725       if (dobrace) {
726         translate(concat(c0, [-brace[2] + 0.1])){
727           difference(){
728             cube(concat(bsz, [brace[2]]) - [5,0,0]);
729             translate(brace + [0,0, -25])
730               cube(concat(bsz, [50]) - brace*2 + [10,0,0]);
731           }
732         }
733       }
734       RoundEdge(R_EDGE(c,1));
735     }
736     Machine();
737   }
738 }
739
740 module FitTest_PairLink(cut=false){ ////toplevel
741   cy0=-55; cy1=85; cx=127;
742   bar = [10,10];
743   legrad = 12;
744   footrad_min = 1; footrad_max = 4; footrad_depth = 5;
745   strap = [3,5];
746   adj_neg_slop = 1.0;
747   bar_z_slop = 1.75;
748
749   // calculated
750   straphole_x_max = legrad/sqrt(2) + footrad_max;
751   dz = cut ? adj_neg_slop : 0;
752
753   translate([cx - bar[0]/2, cy0, dz + bar_z_slop])
754     cube([bar[0], cy1-cy0, bar[1] - bar_z_slop]);
755
756   for (endy=[cy0,cy1]) {
757     $fn=32;
758     translate([cx,endy,dz]){
759       // feet
760       for (rot=[45:90:315]) rotate(rot) {
761         translate([legrad,0,0]){
762           hull(){
763             cylinder(r= footrad_max, h=1);
764             translate([0,0,-footrad_depth])
765               cylinder(r= footrad_min, h=1);
766           }
767           translate([0,0,-10])
768             cylinder(r= footrad_min +
769                      adj_neg_slop * (footrad_max-footrad_min)/footrad_depth,
770                      h=20);
771         }
772       }
773       // legs
774       for (rot=[45,135]) rotate(rot) {
775         hull(){
776           for (s=[-1,+1]){
777             translate([s*legrad,0,0])
778               cylinder(r= footrad_max, h=bar[1]);
779           }
780         }
781       }
782       // strap holes
783       if (cut) {
784         for (rot=[0,180]) rotate(rot) {
785             translate([ straphole_x_max - strap[0]/2, 0,0 ])
786               cube(concat(strap,[20]), center=true);
787           }
788       }
789     }
790   }
791 }
792
793 module FitTest_RearCurve(){ ////toplevel
794   difference(){
795     FitTest_general([110,0], [170,100]);
796     FitTest_PairLink(true);
797   }
798 }
799
800 module FitTest_FrontCurve(){ ////toplevel
801   p0 = [110,-80];
802   sz = [170,80];
803   difference(){
804     intersection() {
805       Tile00();
806       translate([0,0,-8]) linear_extrude(height=18) {
807         translate(p0) square(sz);
808       }
809     }
810     FitTest_PairLink(true);
811   }
812 }
813
814 module FitTest_Entire(){ ////toplevel
815   p0 = [-40,-80];
816   szrear = [270,180];
817   szfront = [250,szrear[1]];
818   difference(){
819     FitTest_general(p0, szrear, dobrace=true, bracexx=0);
820     FitTest_PairLink(true);
821     translate(concat(p0,[0]) + [szfront[0],-10,-40])
822       cube([100, -p0[1], 80]);
823   }
824   intersection(){
825     FitTest_RearCurve();
826     translate(concat(p0,[-20])) cube(concat(szrear,[40]));
827   }
828   FitTest_FrontCurve();
829 }
830
831 module FitTest_EntireDemo(){ ////toplevel
832   FitTest_Entire();
833   //%Tile00();
834 }
835
836 module FitTest_PairDemo(){ ////toplevel
837   sh=[-100,-15,0];
838   translate(sh){
839     FitTest_PairLink();
840     %FitTest_FrontCurve();
841     %FitTest_RearCurve();
842   }
843   rotate([0,0,180]){
844     translate(sh){
845       difference(){
846         union(){
847           FitTest_FrontCurve();
848           FitTest_RearCurve();
849         }
850         #FitTest_PairLink(true);
851       }
852     }
853   }
854 }
855
856 module RoundCornerDemo_plat(cnr){
857   mirror([0,0,1]) linear_extrude(height=1) polygon(cnr);
858 }
859
860 module RoundCornerDemo(){ ////toplevel
861   cnr = [ [-2,-3], [13,-3], [-12,9] ];
862   translate([0,25,0]) RoundCornerDemo_plat(cnr);
863   translate([25,0,0]) RoundCornerAdd(cnr);
864   translate([-25,0,0]) RoundCornerCut(cnr);
865   translate([0,-25,0]) RoundCorner_selector(cnr, 0);
866   difference(){
867     RoundCornerDemo_plat(cnr);
868     RoundCornerCut(cnr);
869   }
870   RoundCornerAdd(cnr);
871 }
872
873 module Demo(){ ////toplevel
874   translate(demo_slop*[-2,1]) color("blue") Tile12();
875   translate(demo_slop*[-2,0]) color("red")  Tile02();
876   translate(demo_slop*[-2,1]) color("orange") Tile11();
877   translate(demo_slop*[-2,0]) color("purple") Tile01();
878   translate(demo_slop*[-3,1]) color("blue")   Tile10();
879   translate(demo_slop*[-3,0]) color("red")    Tile00();
880   %Machine();
881 }
882   
883 //TestPiece1();
884 //TestPiece2();
885 //Demo();
886
887 //Machine_NewRearProfile();
888 //Machine_NewRearCurve();
889 //Machine_NewFrontProfile();
890 //Machine_Curves();
891 //Machine();
892 //FitTest();
893 //MachineEnvelope();