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