chiark / gitweb /
sewing-table: RoundCorner rework: promote R_EDGE (nfc)
[reprap-play.git] / sewing-table.scad.m4
index 3bfe20824412ea7d07a25f890b25fc6a40ef23dc..9a091699d37c244106368363f463faf8f903cd3c 100644 (file)
@@ -94,12 +94,15 @@ rearcurve_double_inrad = 26.10 + 8.04;
 
 reartablet_z = 2.54;
 reartablet_x = 5 + 1;
-reartablet_y = 5;
+reartablet_y = 8;
 
 frontcurve_side_skew = 3.5 / 72;
 frontcurve_avoid_y = 70;
 frontcurve_z_slop = 0.75;
 
+frontcurve_strt_len = 60;
+frontcurve_dualcurve_angle = 90 - 65;
+
 // calculated
 
 TEST = false;
@@ -123,6 +126,8 @@ thehd_tl = [ -thehd_tr[0], thehd_tr[1] ];
 thehd_bl = -thehd_tr;
 thehd_br = -thehd_tl;
 
+tablet_z_slop = rearcurve_z_slop;
+
 interlock_rad = interlock_dia/2;
 interlock_negative_rad = interlock_rad + 0.125;
 
@@ -190,15 +195,23 @@ module TileBase(botleft, topright){
          translate(concat(botleft_post, [-1]))
            cube(concat(topright_post-botleft_post, [tile_th+2]));
        }
+       shufflesz = max(test_edge, tile_hard_edge_hole_dist)*2;
        minkowski(){
-         Machine();
-         cube(max(test_edge, tile_hard_edge_hole_dist)*2, center=true);
+         MachineEnvelope();
+         cube(shufflesz, center=true);
        }
       }
     }
   }
 }
 
+m4_dnl   R_EDGE(c,ix)
+m4_dnl        c is from Rectangle_corners and
+m4_dnl        ix is a corner number
+m4_dnl    expands to two comma-separated corners:
+m4_dnl    that denoted by ix, and the next one anticlockwise
+m4_define(`R_EDGE',`$1[$2],$1[(($2)+1)%4]')
+
 m4_dnl  INREFFRAME(left_cnr, right_cnr, morevars) { body; }
 m4_define(`INREFFRAME',`
   length_vec = ($2) - ($1);
@@ -231,36 +244,74 @@ module RoundEdge(left_cnr, right_cnr) {
   }
 }
 
-module RoundCornerCut(ci) {
-  // ci should be [this_cnr, right_cnr]
-  // where right_cnr is to the right (ie, anticlockwise)
+m4_define(`ROUNDCORNER_VARS',`
   this_cnr = ci[0];
   right_cnr = ci[1];
-  offr= round_cnr_rad - round_edge_rad;
-  INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
-    difference(){
-      cube(offr*2 - 0.1, center=true);
-      translate([offr, offr, 0])
-       cylinder(center=true, h=20, r= offr);
+  left_cnr = ci[2];
+  bigr= round_cnr_rad - round_edge_rad;
+  l_uvec = unitvector2d(left_cnr - this_cnr);
+  r_uvec = unitvector2d(right_cnr - this_cnr);
+  lp1 = left_cnr  + clockwise2d(l_uvec) * bigr;
+  lp2 = this_cnr  + clockwise2d(l_uvec) * bigr;
+  lp3 = this_cnr  - clockwise2d(r_uvec) * bigr;
+  lp4 = right_cnr - clockwise2d(r_uvec) * bigr;
+  ctr = line_intersection_2d(lp1,lp2,lp3,lp4);
+  ctr3 = concat(ctr,[0])
+')
+
+module RoundCorner_selector(ci, adj) {
+  ROUNDCORNER_VARS;
+  echo("RCS",l_uvec,ctr);
+  %union(){
+    INREFFRAME(this_cnr, right_cnr) {
+      cube(bigr*2 + adj, center=true);
+    }
+  }
+  intersection(){
+    union(){
+      INREFFRAME(ctr3,concat(lp1,[4])){
+       translate([0,0,-bigr]) linear_extrude(height=bigr*2) {
+         translate([-bigr*2 + adj, -bigr])
+           square([bigr*2, bigr*3]);
+       }
+      }
+    }
+    union(){
+      INREFFRAME(ctr3,concat(lp4,[0])){
+       translate([0,0,-bigr]) linear_extrude(height=bigr*2) {
+         translate([-bigr*2, -bigr*2])
+           square([bigr*2 + adj, bigr*3]);
+       }
+      }
     }
   }
 }
 
+module RoundCornerCut(ci) {
+  // ci should be [this_cnr, right_cnr, left_cnr]
+  // where right_cnr is to the right (ie, anticlockwise)
+  ROUNDCORNER_VARS;
+  difference(){
+    RoundCorner_selector(ci, -0.1);
+    translate(ctr3)
+      cylinder(center=true, h=20, r= bigr);
+  }
+}
+
 module RoundCornerAdd(ci) {
-  this_cnr = ci[0];
-  right_cnr = ci[1];
-  bigr = round_cnr_rad - round_edge_rad;
-  INREFFRAME(this_cnr, right_cnr) INREFFRAME_EDGE {
-    intersection(){
-      cube(bigr*2 + 0.1, center=true);
-      translate([bigr, bigr, 0])
+  ROUNDCORNER_VARS;
+  intersection(){
+    RoundCorner_selector(ci, +0.1);
+    INREFFRAME_EDGE {
+      translate(ctr3){
        rotate_extrude(convexity=10, $fn=50)
-       translate([bigr, 0])
-       difference(){
+         translate([bigr, 0])
+         difference(){
          circle(r= round_edge_rad, $fn=50);
          mirror([1,1])
            square([20,20]);
-        }
+       }
+      }
     }
   }
 }
@@ -391,7 +442,7 @@ module Machine_Arm(){
   translate([0,0,-30]) linear_extrude(height=60) {
     translate(tile01_tr + [0, (-cutout_tile01_y + cutout_tile11_y)/2]) {
       intersection(){
-       translate([-100, -ysz/2])
+       translate([-50, -ysz/2])
          square([400, ysz]);
        translate([ endrad - cutout_tile11_x - cutout_l_end_x_slop, 0 ])
          circle(r=endrad, $fa=0.01,$fd=5);
@@ -408,7 +459,7 @@ module Machine_Profile(){
                machine_front_profile);
   skew_angle = atan2( first_front[1] - first_rear[1],
                      first_front[0] - first_rear[0] );
-  echo(below_point, pol, skew_angle);
+  //echo(below_point, pol, skew_angle);
   hull(){
     for (z=[0,-40]) {
       translate([0,z]) {
@@ -432,30 +483,40 @@ module Machine_NewRearProfile(){
   sh = -[abs(posbox[0]), abs(posbox[1])];
   rot = atan2(-sideline[0], sideline[1]);
   sc = scaleline_mm / scaleline;
-  echo("SH",sh,rot,sc);
+  //echo("SH",sh,rot,sc);
   scale(sc) rotate(rot) translate(sh){
     import("sewing-table-rear-profile.dxf", convexity=10); // spline, Pink3
   }
 }
 
 module Machine_NewRearCurve(){
-  translate([ -rearcurve_double_inrad, 0, 10 ]){
-    rotate([180,0,0]) rotate([0,0,-90]) linear_extrude(height=30){
-      hull(){
-       Machine_NewRearProfile();
-      translate([0,-100]) Machine_NewRearProfile();
+  slant = atan2(4,210-10);
+  //echo("SL",slant);
+  translate([0,0, rearcurve_double_inrad]) rotate([slant,0,0]){
+    translate([ rearcurve_double_inrad,
+               0,
+               -rearcurve_double_inrad + 10 ]){
+      rotate([180,0,0]) rotate([0,0,90]) linear_extrude(height=30){
+       hull(){
+         Machine_NewRearProfile();
+         translate([0,-100]) Machine_NewRearProfile();
+       }
       }
     }
-  }
-  rotate([0,90,0]) rotate([-90,0,0]) {
-    intersection(){
-      rotate_extrude(convexity=10, $fn=64)
-       rotate(90)
-       translate([ 0, -rearcurve_double_inrad ])
-       Machine_NewRearProfile();
-      translate([0,0,-500])
-       cube([500,500,1000]);
+    rotate([0,90,0]) rotate([90,0,0]) {
+      intersection(){
+       rotate_extrude(convexity=10, $fn=64)
+         rotate(90)
+         translate([ 0, -rearcurve_double_inrad ])
+         Machine_NewRearProfile();
+       translate([0,0,-500])
+         cube([500,500,1000]);
+      }
     }
+    translate([1,0,-rearcurve_double_inrad])
+      rotate([0,-90,0]) rotate([0,0,-90])
+      linear_extrude(height= rearcurve_strt_len + 1)
+      Machine_NewRearProfile();
   }
 }
 
@@ -484,7 +545,7 @@ module Machine_Curves(){ ////toplevel
     //%cube([20,20,20]);
     translate([ -reartablet_x,
                -1,
-               -reartablet_z])
+               -reartablet_z + tablet_z_slop])
       mirror([0,0,1])
       cube([ reartablet_x+1,
             reartablet_y+1,
@@ -508,31 +569,7 @@ module Machine_Curves(){ ////toplevel
     translate([ rearcurve_strt_len,
                0,
                rearcurve_z_slop ]){
-      translate([ 1,
-                 0,
-                 0
-                 ]){
-       rotate([0,-90,0])rotate([0,0,-90]){
-         linear_extrude(height= rearcurve_strt_len + 1)
-         Machine_RearProfile();
-       }
-      }
-      translate([ 0,
-                 0,
-                 rearcurve_double_inrad ]) {
-       intersection(){
-         rotate([90,0,0]){
-           rotate_extrude(convexity=10, $fn=32) {
-             rotate([0,0,90]) translate([ 0,
-                         -rearcurve_double_inrad ]) {
-               Machine_RearProfile();
-             }
-           }
-         }
-         mirror([0,0,1])
-           translate([0,-75,0]) cube([150,150,150]);
-       }
-      }
+      Machine_NewRearCurve();
     }
   }
 }
@@ -542,6 +579,19 @@ module Machine(){ ////toplevel
   Machine_Curves();
 }
 
+module MachineEnvelope(){
+  // used for testing
+  p_arm_bl = [-cutout_tile11_x, -cutout_tile01_y];
+  y_arm_t  = cutout_tile11_y;
+  p_crv_fl = p_arm_bl + [rearedge_len, -frontcurve_avoid_y];
+  y_crv_b  = y_arm_t + rearcurve_avoid_y;
+
+  translate([0,0,-50]) linear_extrude(height= 100){
+    translate(p_arm_bl) square([400, y_arm_t] - p_arm_bl);
+    translate(p_crv_fl) square([400, y_crv_b] - p_crv_fl);
+  }
+}
+
 function Rectangle_corners(c0, sz) =
   // returns the corners of a rectangle from c0 to c0+sz
   // if sz is positive, the corners are anticlockwise starting with c0
@@ -560,26 +610,19 @@ module Rectangle_TileBase(c) { TileBase(c[0], c[2]); }
 
 function Posts_interpolate_one(c0,c1) = [c0, (c0+c1)/2, c1];
 
-m4_dnl   R_EDGE(c,ix)
-m4_dnl        c is from Rectangle_corners and
-m4_dnl        ix is a corner number
-m4_dnl    expands to two comma-separated corners:
-m4_dnl    that denoted by ix, and the next one anticlockwise
-m4_define(`R_EDGE',`$1[$2],$1[(($2)+1)%4]')
-
-module FitTest(){ ////toplevel
-  sz = [280,180];
-  c0 = [-50,-80];
+module FitTest_general(c0,sz, dobrace=false){
   c = Rectangle_corners(c0, sz);
   brace = [7,7,9];
   difference(){
     union(){
       Rectangle_TileBase(c);
-      translate(concat(c0, [-brace[2] + 0.1])){
-       difference(){
-         cube(concat(sz,[brace[2]]) - [5,0,0]);
-         translate(brace + [0,0, -25])
-           cube(concat(sz, [50]) - brace*2 + [10,0,0]);
+      if (dobrace) {
+       translate(concat(c0, [-brace[2] + 0.1])){
+         difference(){
+           cube(concat(sz,[brace[2]]) - [5,0,0]);
+           translate(brace + [0,0, -25])
+             cube(concat(sz, [50]) - brace*2 + [10,0,0]);
+         }
        }
       }
       RoundEdge(R_EDGE(c,1));
@@ -588,6 +631,14 @@ module FitTest(){ ////toplevel
   }
 }
 
+module FitTest_Entire(){ ////toplevel
+  FitTest_general([-40,-80], [275,180], dobrace=true);
+}
+
+module FitTest_RearCurve(){ ////toplevel
+  FitTest_general([110,0], [170,100]);
+}
+
 module Tile02(){ ////toplevel
   sz = [100,170];
   c0 = tile02_tr + -sz;
@@ -712,6 +763,13 @@ module Tile00(){ ////toplevel
   sz = [250,170];
   c0 = tile01_tr + [0,-sz[1]];
   c = Rectangle_corners(c0, sz);
+
+  // the edge c[1]..c[2] needs a diagonal chunk, from c1bis to c2bis
+  c2bis = [ -cutout_l_end_x + rearedge_len + frontcurve_strt_len, c[2][1] ];
+  c1bis = [ c[1][0],
+           c[2][1] -
+           (c[2][0] - c2bis[0]) * tan(90 - frontcurve_dualcurve_angle) ];
+
   cnr_posts = Rectangle_corners2posts(c);
   cty = cutout_tile01_y;
   rcy = cty + frontcurve_avoid_y;
@@ -724,16 +782,53 @@ module Tile00(){ ////toplevel
   rcs = [R_EDGE(c,1)];
   difference(){
     union(){
-      Rectangle_TileBase(c);
-      Posts(posts);
-      RoundEdge(R_EDGE(c,0));
-      RoundEdge(R_EDGE(c,1));
-      InterlockEdge(tile_01_00_cnr, c[0]);
+      difference(){
+       union(){
+         Rectangle_TileBase(c);
+         Posts(posts);
+         RoundEdge(R_EDGE(c,0));
+         RoundEdge(c[1], c1bis);
+         InterlockEdge(tile_01_00_cnr, c[0]);
+       }
+       RoundCornerCut(rcs);
+       translate([0,0,-20]) linear_extrude(height=40) {
+         polygon([ c1bis, c1bis + [50,0], c2bis + [50,0], c2bis ]);
+       }
+      }
+      RoundEdge(c1bis, c2bis);
     }
-    RoundCornerCut(rcs);
     Machine();
   }
   RoundCornerAdd(rcs);
+  RoundCornerAdd([c1bis,c2bis,c[1]]);
+}
+
+module FitTest_FrontCurve(){ ////toplevel
+  p0 = [110,-80];
+  sz = [170,80];
+  intersection() {
+    Tile00();
+    translate([0,0,-8]) linear_extrude(height=18) {
+      translate(p0) square(sz);
+    }
+  }
+}
+
+module RoundCornerDemo_plat(cnr){
+  mirror([0,0,1]) linear_extrude(height=1) polygon(cnr);
+}
+
+module RoundCornerDemo(){ ////toplevel
+  cnr = [ [0,0], [15,0], [-10,12] ];
+  translate([0,25,0]) RoundCornerDemo_plat(cnr);
+  translate([25,0,0]) RoundCornerAdd(cnr);
+  translate([-25,0,0]) RoundCornerCut(cnr);
+  translate([0,-25,0]) RoundCorner_selector(cnr, 0);
+  difference(){
+    RoundCornerDemo_plat(cnr);
+    RoundCornerCut(cnr);
+  }
+  RoundCornerAdd(cnr);
 }
 
 module Demo(){ ////toplevel
@@ -753,3 +848,7 @@ module Demo(){ ////toplevel
 //Machine_Profile();
 //Machine_NewRearProfile();
 //Machine_NewRearCurve();
+//Machine_Curves();
+//Machine();
+//FitTest();
+//MachineEnvelope();