chiark / gitweb /
e3dab4e2340c969e979bd932d6503c58f054a646
[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,   0,  0 ],
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,  15,  5 ],
12          [6 + 0.5,  12 + 1.0,  15, 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, recessdepth_arg) =
31   recessdepth_arg >= 0 ? recessdepth_arg : -recessdepth_arg * recessdia;
32
33 function RecessedScrewCutout_totaldepth(recessdia, recessdepth_arg) =
34   RecessedScrewCutout_recessdepth(recessdia, recessdepth_arg) +
35   + 0.5*recessdia + 0.1;
36
37 module RecessedScrewCutout(shaftdia, recessdia, shaftlen,
38         zbelow=1,
39         recessdepth_arg=RecessedScrewCutout_defaultrecessdepth_flat) {
40   // pass recessdepth_arg=-1 for the default for flat heads
41   // pass recessdepth_arg=-1 for the default for flat heads
42   recessdepth = RecessedScrewCutout_recessdepth(recessdia, recessdepth_arg);
43   recesstopz = RecessedScrewCutout_totaldepth(recessdia, recessdepth_arg);
44
45   translate([0,0,-zbelow]) cylinder(r=shaftdia/2, h=shaftlen+zbelow, $fn=20);
46   RecessScrewCutout_RecessCylinder(recessdia,zbelow, recessdepth);
47   intersection(){
48     cube([recessdia + 1, shaftdia + 0.1, recesstopz*2 + 1], center=true);
49     translate([0, -recessdia, recesstopz])
50       rotate([0,135,0]) cube([recessdia, recessdia*2, 10]);
51     RecessScrewCutout_RecessCylinder(recessdia,zbelow, recesstopz+1);
52   }
53 }
54
55 module Block(){
56   translate([blockminx, blockmaxx, 0])
57     cube([blockmaxx-blockminx, blockmaxy-blockminy, cubez]);
58 }
59
60 module Test(){
61   difference(){
62     Block();
63     union(){
64       for (t = tests) {
65         RecessedScrewCutout(t[0],t[1], shaftz+1);
66       }
67     }
68   }
69 }
70
71 module Holes(){
72   for (t = tests) {
73     translate([t[2], t[3], 0])
74       RecessedScrewCutout(t[0],t[1], shaftz+1);
75   }
76 }
77
78 module Demo(){
79   Block();
80   %Holes();
81 }
82
83 Demo();
84
85 //Test();
86 //Hole();
87 //Holes();