chiark / gitweb /
screw-recess-test: actual results
[reprap-play.git] / screw-recess-test.scad
1 // -*- C -*-
2
3 module RecessScrewCutout_RecessCylinder(recessdia,zbelow, h){
4   translate([0,0,-zbelow]) cylinder(r=recessdia/2, h=h+1, $fn=40);
5 }
6
7 RecessedScrewCutout_defaultrecessdepth_flat = -0.30;
8 RecessedScrewCutout_defaultrecessdepth_hex = -0.60;
9
10 function RecessedScrewCutout_recessdepth(recessdia,
11         recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) =
12   recessdepth_arg >= 0 ? recessdepth_arg : -recessdepth_arg * recessdia;
13
14 function RecessedScrewCutout_totaldepth(recessdia,
15         recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) =
16   RecessedScrewCutout_recessdepth(recessdia, recessdepth_arg) +
17   + 0.5*recessdia + 0.1;
18
19 module RecessedScrewCutout(shaftdia, recessdia, shaftlen,
20         zbelow=1,
21         recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) {
22   // pass recessdepth_arg=-1 for the default for flat heads
23   // pass recessdepth_arg=-1 for the default for flat heads
24   recessdepth = RecessedScrewCutout_recessdepth(recessdia, recessdepth_arg);
25   recesstopz = RecessedScrewCutout_totaldepth(recessdia, recessdepth_arg);
26
27   translate([0,0,-zbelow]) cylinder(r=shaftdia/2, h=shaftlen+zbelow, $fn=20);
28   RecessScrewCutout_RecessCylinder(recessdia,zbelow, recessdepth);
29   intersection(){
30     cube([recessdia + 1, shaftdia + 0.1, recesstopz*2 + 1], center=true);
31     translate([0, -recessdia, recesstopz])
32       rotate([0,135,0]) cube([recessdia, recessdia*2, 10]);
33     RecessScrewCutout_RecessCylinder(recessdia,zbelow, recesstopz+1);
34   }
35 }
36
37 //        shaftdia  recessdia
38 tests = [[2 + 0.5,   4 + 1.0 ],   // shaft came out ~1.0
39          [3 + 0.5,   6 + 1.0 ],   // shaft came out ~2.0
40          [4 + 0.5,   8 + 1.0 ],   // shaft came out ~3.3
41          [5 + 0.5,  10 + 1.0 ],   // shaft came out ~4.5
42          [6 + 0.5,  12 + 1.0 ]];  // shaft came out ~5.4
43
44 module OneTest(t){
45   blocksz = t[1] + 7;
46   h = RecessedScrewCutout_totaldepth(t[1]) + 3;
47   difference(){
48     translate([-blocksz/2, -blocksz/2, 0])
49       cube([blocksz, blocksz, h]);
50     RecessedScrewCutout(t[0],t[1], h+1);
51   }
52 }
53
54 function Test_x(i) = i<=0 ? 0 :
55   Test_x(i-1) + tests[i-1][1]*0.5 + tests[i][1]*0.5 + 4.5;
56
57 module Tests(){
58   for (i = [0:len(tests)-1]) {
59     echo(i, Test_x(i));
60     translate([Test_x(i), 0, 0])
61       OneTest(tests[i]);
62   }
63 }
64
65 //OneTest(tests[1]);
66 Tests();
67 //Hole();
68 //Holes();