forked from SolidCode/MCAD
-
Notifications
You must be signed in to change notification settings - Fork 190
/
threads.scad
245 lines (219 loc) · 6.93 KB
/
threads.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* Dan Kirshner - dan_kirshner@yahoo.com
* Chow Loong Jin - hyperair@debian.org
*
* You are welcome to make free use of this software. Retention of my
* authorship credit would be appreciated.
*
* Version 1.3. 2013-12-01 Correct loop over turns -- don't have early cut-off
* Version 1.2. 2012-09-09 Use discrete polyhedra rather than linear_extrude()
* Version 1.1. 2012-09-07 Corrected to right-hand threads!
*/
// Examples:
test_threads ();
module test_threads ($fa=5, $fs=0.1)
{
// M8
metric_thread(8, 1.5, 10);
translate ([10, 0, 0])
square_thread(8, 1.5, 10);
translate ([20, 0, 0])
acme_thread(8, 1.5, 10);
translate ([30, 0, 0])
buttress_thread(8, 1.5, 10);
translate ([40, 0, 0])
english_thread(1/4, 20, 1);
// Rohloff hub thread:
translate ([65, 0, 0])
metric_thread(34, 1, 10, internal=true, n_starts=6);
}
// ----------------------------------------------------------------------------
use <MCAD/general/utilities.scad>
use <MCAD/general/sweep.scad>
use <MCAD/general/facets.scad>
use <scad-utils/transformations.scad>
// ----------------------------------------------------------------------------
// internal - true = clearances for internal thread (e.g., a nut).
// false = clearances for external thread (e.g., a bolt).
// (Internal threads should be "cut out" from a solid using
// difference()).
// n_starts - Number of thread starts (e.g., DNA, a "double helix," has
// n_starts=2). See wikipedia Screw_thread.
module metric_thread (
diameter = 8,
pitch = 1,
length = 1,
internal = false,
n_starts = 1
)
{
trapezoidal_thread (
pitch = pitch,
length = length,
upper_angle = 30, lower_angle = 30,
outer_flat_length = pitch / 8,
major_radius = diameter / 2,
minor_radius = diameter / 2 - 5/8 * cos(30) * pitch,
internal = internal,
n_starts = n_starts
);
}
module square_thread (
diameter = 8,
pitch = 1,
length = 1,
internal = false,
n_starts = 1
)
{
trapezoidal_thread (
pitch = pitch,
length = length,
upper_angle = 0, lower_angle = 0,
outer_flat_length = pitch / 2,
major_radius = diameter / 2,
minor_radius = diameter / 2 - pitch / 2,
internal = internal,
n_starts = n_starts
);
}
module acme_thread (
diameter = 8,
pitch = 1,
length = 1,
internal = false,
n_starts = 1
)
{
trapezoidal_thread (
pitch = pitch,
length = length,
upper_angle = 29/2, lower_angle = 29/2,
outer_flat_length = 0.3707 * pitch,
major_radius = diameter / 2,
minor_radius = diameter / 2 - pitch / 2,
internal = internal,
n_starts = n_starts
);
}
module buttress_thread (
diameter = 8,
pitch = 1,
length = 1,
internal = false,
n_starts = 1,
buttress_angles = [3, 33],
pitch_flat_ratio = 6, // ratio of pitch to flat length
pitch_depth_ratio = 3/2 // ratio of pitch to thread depth
)
{
trapezoidal_thread (
pitch = pitch,
length = length,
upper_angle = buttress_angles[0], lower_angle = buttress_angles[1],
outer_flat_length = pitch / pitch_flat_ratio,
major_radius = diameter / 2,
minor_radius = diameter / 2 - pitch / pitch_depth_ratio,
internal = internal,
n_starts = n_starts
);
}
/**
* trapezoid_thread():
* generates a screw with a trapezoidal thread profile
*
* pitch = distance between the same part of adjacent teeth
* length = length of the screw to generate
* upper_angle = angle between the normal and the upper slant of a tooth
* lower_angle = ditto, but for the lower slant
* outer_flat_length = length of the flat part of the tooth along the outside
* major_radius = radius of the screw until the outer flat
* minor_radius = radius of the screw until the inner flat
* internal = if true, generates a thread suitable for difference() to make nuts
* n_starts = number of threads winding the screw
*/
module trapezoidal_thread (
pitch,
length,
upper_angle,
lower_angle,
outer_flat_length,
major_radius,
minor_radius,
internal = false,
n_starts = 1
)
{
// trapezoid calculation:
/*
upper flat
___________________
/| |\
/ | | \
left /__|_________________|__\ right
angle| | lower flat | |angle
| | | |
|left |right
flat |flat
*/
// looking at the tooth profile along the upper part of a screw held
// horizontally, which is a trapezoid longer at the bottom flat
tooth_height = major_radius - minor_radius;
left_angle = 90 - upper_angle;
right_angle = 90 - lower_angle;
upper_flat = outer_flat_length;
left_flat = tooth_height / tan (left_angle);
right_flat = tooth_height / tan (right_angle);
lower_flat = upper_flat + left_flat + right_flat;
clearance = 0.3/8 * tooth_height;
tooth_profile = [
[0, 0],
[tooth_height + 0.001, right_flat],
[tooth_height + 0.001, right_flat + upper_flat],
[0, lower_flat]
];
// convert length along the tooth profile to angle of twist of the screw
function length2twist (length) = length / pitch * (360 / n_starts);
function twist2length (angle) = angle / (360 / n_starts) * pitch;
// facet calculation
facets = get_fragments_from_r (minor_radius);
fa = 360 / facets;
slices = length2twist (length) / fa;
path_transforms = [
for (i=[0:slices + length2twist (pitch) / fa])
let (a=i * fa)
(
rotation (axis=[0, 0, a]) *
translation ([0, 0, twist2length (a) - pitch]) *
translation ([minor_radius - 0.001, 0, 0]) *
rotation (axis=[90, 0, 0])
)
];
cylinder (r=minor_radius, h=length);
difference () {
for (i=[0:n_starts])
rotate ([0, 0, i / n_starts * 360])
sweep (tooth_profile, path_transforms);
translate ([0, 0, length + pitch / 2])
cube ([major_radius * 2 + .1, major_radius * 2+ .1, pitch],
center=true);
translate ([0, 0, -pitch / 2])
cube ([major_radius * 2 + .1, major_radius * 2+ .1, pitch],
center=true);
}
}
// ----------------------------------------------------------------------------
// Input units in inches.
// Note: units of measure in drawing are mm!
module english_thread(diameter=0.25, threads_per_inch=20, length=1,
internal=false, n_starts=1)
{
// Convert to mm.
mm_diameter = diameter*25.4;
mm_pitch = (1.0/threads_per_inch)*25.4;
mm_length = length*25.4;
echo(str("mm_diameter: ", mm_diameter));
echo(str("mm_pitch: ", mm_pitch));
echo(str("mm_length: ", mm_length));
metric_thread(mm_diameter, mm_pitch, mm_length, internal, n_starts);
}