forked from SolidCode/MCAD
-
Notifications
You must be signed in to change notification settings - Fork 192
/
nuts_and_bolts.scad
227 lines (216 loc) · 3.02 KB
/
nuts_and_bolts.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Copyright 2010 D1plo1d
// This library is dual licensed under the GPL 3.0 and the GNU Lesser General Public License as per http://creativecommons.org/licenses/LGPL/2.1/ .
//testNutsAndBolts();
module SKIPtestNutsAndBolts()
{
$fn = 360;
translate([0,15])nutHole(3, proj=2);
boltHole(3, length= 30, proj=2);
}
MM = "mm";
INCH = "inch"; //Not yet supported
//Based on: http://www.roymech.co.uk/Useful_Tables/Screws/Hex_Screws.htm
METRIC_NUT_AC_WIDTHS =
[
-1, //0 index is not used but reduces computation
-1,
4.38,//m2
6.40,//m3
8.10,//m4
9.20,//m5
11.50,//m6
-1,
15.00,//m8
-1,
19.60,//m10
-1,
22.10,//m12
-1,
-1,
-1,
27.70,//m16
-1,
-1,
-1,
34.60,//m20
-1,
-1,
-1,
41.60,//m24
-1,
-1,
-1,
-1,
-1,
53.1,//m30
-1,
-1,
-1,
-1,
-1,
63.5//m36
];
METRIC_NUT_THICKNESS =
[
-1, //0 index is not used but reduces computation
-1,
1.6,//m2
2.40,//m3
3.20,//m4
4.00,//m5
5.00,//m6
-1,
6.50,//m8
-1,
8.00,//m10
-1,
10.00,//m12
-1,
-1,
-1,
13.00,//m16
-1,
-1,
-1,
16.00//m20
-1,
-1,
-1,
19.00,//m24
-1,
-1,
-1,
-1,
-1,
24.00,//m30
-1,
-1,
-1,
-1,
-1,
29.00//m36
];
COARSE_THREAD_METRIC_BOLT_MAJOR_DIAMETERS =
[//based on max values
-1, //0 index is not used but reduces computation
-1,
1.6,//m2
2.98,//m3
3.978,//m4
4.976,//m5
5.974,//m6
-1,
7.972,//m8
-1,
9.968,//m10
-1,
11.966,//m12
-1,
-1,
-1,
15.962,//m16
-1,
-1,
-1,
19.958,//m20
-1,
-1,
-1,
23.952,//m24
-1,
-1,
-1,
-1,
-1,
29.947,//m30
-1,
-1,
-1,
-1,
-1,
35.940//m36
];
// Deprecated, but kept around for people who use the wrong spelling.
COURSE_METRIC_BOLT_MAJOR_THREAD_DIAMETERS = COARSE_THREAD_METRIC_BOLT_MAJOR_DIAMETERS;
//Based on: http://www.roymech.co.uk/Useful_Tables/Screws/cap_screws.htm
METRIC_BOLT_CAP_DIAMETERS =
[
-1, //0 index is not used but reduces computation
-1,
3.8,
5.50,//m3
7.00,//m4
8.50,//m5
10.00,//m6
-1,
13.00,//m8
-1,
16.00,//m10
-1,
18.00,//m12
-1,
-1,
-1,
24.00,//m16
-1,
-1,
-1,
30.00//m20
-1,
-1,
-1,
36.00,//m24
-1,
-1,
-1,
-1,
-1,
45.00,//m30
-1,
-1,
-1,
-1,
-1,
54.00//m36
];
module nutHole(size, units=MM, tolerance = +0.0001, proj = -1)
{
//takes a metric screw/nut size and looksup nut dimensions
radius = METRIC_NUT_AC_WIDTHS[size]/2+tolerance;
height = METRIC_NUT_THICKNESS[size]+tolerance;
if (proj == -1)
{
cylinder(r= radius, h=height, $fn = 6, center=[0,0]);
}
if (proj == 1)
{
circle(r= radius, $fn = 6);
}
if (proj == 2)
{
translate([-radius/2, 0])
square([radius*2, height]);
}
}
module boltHole(size, units=MM, length, tolerance = +0.0001, proj = -1)
{
radius = COARSE_THREAD_METRIC_BOLT_MAJOR_DIAMETERS[size]/2+tolerance;
capHeight = size+tolerance;
capRadius = METRIC_BOLT_CAP_DIAMETERS[size]/2+tolerance;
if (proj == -1)
{
translate([0, 0, -capHeight])
cylinder(r= capRadius, h=capHeight);
cylinder(r = radius, h = length);
}
if (proj == 1)
{
circle(r = radius);
}
if (proj == 2)
{
translate([-capRadius/2, -capHeight])
square([capRadius*2, capHeight]);
square([radius*2, length]);
}
}