chiark / gitweb /
screw-recess-test: recursion for test location
[reprap-play.git] / screw-recess-test.scad
index 2e4fb5ced435cb0a3c5f540c2132f50f4f484e83..3219a84fe307c623902a1dcb0b08205be9cd2d6b 100644 (file)
@@ -1,41 +1,68 @@
 // -*- C -*-
 
-cubez = 12;
-
-shaftdia = 4 + 0.5;
-recessdia = 10 + 1.0;
+module RecessScrewCutout_RecessCylinder(recessdia,zbelow, h){
+  translate([0,0,-zbelow]) cylinder(r=recessdia/2, h=h+1, $fn=40);
+}
 
-shaftz = cubez;
-recessz = 5;
+RecessedScrewCutout_defaultrecessdepth_flat = -0.30;
+RecessedScrewCutout_defaultrecessdepth_hex = -0.60;
 
-recesstopz = recessz + 0.5*recessdia + 0.1;
-xblocky = shaftdia + 0.1;
+function RecessedScrewCutout_recessdepth(recessdia,
+        recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) =
+  recessdepth_arg >= 0 ? recessdepth_arg : -recessdepth_arg * recessdia;
 
-cubexy = recessdia + 10;
+function RecessedScrewCutout_totaldepth(recessdia,
+        recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) =
+  RecessedScrewCutout_recessdepth(recessdia, recessdepth_arg) +
+  + 0.5*recessdia + 0.1;
 
-module RecessCylinder(h){
-  translate([0,0,-1]) cylinder(r=recessdia/2, h=h+1, $fn=40);
-}
+module RecessedScrewCutout(shaftdia, recessdia, shaftlen,
+        zbelow=1,
+        recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) {
+  // pass recessdepth_arg=-1 for the default for flat heads
+  // pass recessdepth_arg=-1 for the default for flat heads
+  recessdepth = RecessedScrewCutout_recessdepth(recessdia, recessdepth_arg);
+  recesstopz = RecessedScrewCutout_totaldepth(recessdia, recessdepth_arg);
 
-module Hole(){
-  translate([0,0,-1]) cylinder(r=shaftdia/2, h=shaftz+2, $fn=20);
-  RecessCylinder(recessz);
+  translate([0,0,-zbelow]) cylinder(r=shaftdia/2, h=shaftlen+zbelow, $fn=20);
+  RecessScrewCutout_RecessCylinder(recessdia,zbelow, recessdepth);
   intersection(){
-    translate([-recessdia*1.5, -xblocky/2, -1])
-      cube([recessdia*3, xblocky, recesstopz+3]);
+    cube([recessdia + 1, shaftdia + 0.1, recesstopz*2 + 1], center=true);
     translate([0, -recessdia, recesstopz])
       rotate([0,135,0]) cube([recessdia, recessdia*2, 10]);
-    RecessCylinder(recesstopz+1);
+    RecessScrewCutout_RecessCylinder(recessdia,zbelow, recesstopz+1);
   }
 }
 
-module Test(){
+//        shaftdia  recessdia
+tests = [[2 + 0.5,   4 + 1.0,   0 ],
+        [3 + 0.5,   6 + 1.0,  12 ],
+        [4 + 0.5,   8 + 1.0,  28 ],
+        [5 + 0.5,  10 + 1.0,  38 ],
+        [6 + 0.5,  12 + 1.0,  48 ]];
+
+module OneTest(t){
+  blocksz = t[1] + 7;
+  h = RecessedScrewCutout_totaldepth(t[1]) + 3;
   difference(){
-    translate([-cubexy/2, -cubexy/2, 0])
-      cube([cubexy,cubexy,cubez]);
-    Hole();
+    translate([-blocksz/2, -blocksz/2, 0])
+      cube([blocksz, blocksz, h]);
+    RecessedScrewCutout(t[0],t[1], h+1);
+  }
+}
+
+function Test_x(i) = i<=0 ? 0 :
+  Test_x(i-1) + tests[i-1][1]*0.5 + tests[i][1]*0.5 + 4.5;
+
+module Tests(){
+  for (i = [0:len(tests)-1]) {
+    echo(i, Test_x(i));
+    translate([Test_x(i), 0, 0])
+      OneTest(tests[i]);
   }
 }
 
-Test();
+//OneTest(tests[1]);
+Tests();
 //Hole();
+//Holes();