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