chiark / gitweb /
19c7c63c224f6b5b996f57b48bb6c71700278628
[reprap-play.git] / screw-recess-test.scad
1 // -*- C -*-
2
3 cubez = 12;
4
5 shaftz = cubez;
6
7 //        shaftdia  recessdia
8 tests = [[2 + 0.5,   6 + 1.0,   4, -4 ],
9          [3 + 0.5,   9 + 1.0,   0, 10 ],
10          [4 + 0.5,  10 + 1.0,   0, 25 ],
11          [5 + 0.5,  10 + 1.0,  17,  4 ],
12          [6 + 0.5,  12 + 1.0,  17, 20 ]];
13
14 last_test = tests[len(tests)-1];
15
16 blockminx = -5;
17 blockminy = -5;
18 blockmaxx = 25;
19 blockmaxy = 20;
20
21 cubexy = 20;
22
23 module RecessScrewCutout_RecessCylinder(recessdia,zbelow, h){
24   translate([0,0,-zbelow]) cylinder(r=recessdia/2, h=h+1, $fn=40);
25 }
26
27 RecessedScrewCutout_defaultrecessdepth_flat = -0.35;
28 RecessedScrewCutout_defaultrecessdepth_hex = -0.70;
29
30 function RecessedScrewCutout_recessdepth(recessdia,
31         recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) =
32   recessdepth_arg >= 0 ? recessdepth_arg : -recessdepth_arg * recessdia;
33
34 function RecessedScrewCutout_totaldepth(recessdia,
35         recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) =
36   RecessedScrewCutout_recessdepth(recessdia, recessdepth_arg) +
37   + 0.5*recessdia + 0.1;
38
39 module RecessedScrewCutout(shaftdia, recessdia, shaftlen,
40         zbelow=1,
41         recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) {
42   // pass recessdepth_arg=-1 for the default for flat heads
43   // pass recessdepth_arg=-1 for the default for flat heads
44   recessdepth = RecessedScrewCutout_recessdepth(recessdia, recessdepth_arg);
45   recesstopz = RecessedScrewCutout_totaldepth(recessdia, recessdepth_arg);
46
47   translate([0,0,-zbelow]) cylinder(r=shaftdia/2, h=shaftlen+zbelow, $fn=20);
48   RecessScrewCutout_RecessCylinder(recessdia,zbelow, recessdepth);
49   intersection(){
50     cube([recessdia + 1, shaftdia + 0.1, recesstopz*2 + 1], center=true);
51     translate([0, -recessdia, recesstopz])
52       rotate([0,135,0]) cube([recessdia, recessdia*2, 10]);
53     RecessScrewCutout_RecessCylinder(recessdia,zbelow, recesstopz+1);
54   }
55 }
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();