-
Notifications
You must be signed in to change notification settings - Fork 0
/
polyScrewThread_r1.scad
233 lines (204 loc) · 5.67 KB
/
polyScrewThread_r1.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
/*
* polyScrewThread_r1.scad by aubenc @ Thingiverse
*
* This script contains the library modules that can be used to generate
* threaded rods, screws and nuts.
*
* http://www.thingiverse.com/thing:8796
*
* CC Public Domain
*/
module screw_thread(od,st,lf0,lt,rs,cs)
{
or=od/2;
ir=or-st/2*cos(lf0)/sin(lf0);
pf=2*PI*or;
sn=floor(pf/rs);
lfxy=360/sn;
ttn=round(lt/st+1);
zt=st/sn;
intersection()
{
if (cs >= -1)
{
thread_shape(cs,lt,or,ir,sn,st);
}
full_thread(ttn,st,sn,zt,lfxy,or,ir);
}
}
module hex_nut(df,hg,sth,clf,cod,crs)
{
difference()
{
hex_head(hg,df);
hex_countersink_ends(sth/2,cod,clf,crs,hg);
screw_thread(cod,sth,clf,hg,crs,-2);
}
}
module hex_screw(od,st,lf0,lt,rs,cs,df,hg,ntl,ntd)
{
ntr=od/2-(st/2)*cos(lf0)/sin(lf0);
union()
{
hex_head(hg,df);
translate([0,0,hg])
if ( ntl == 0 )
{
cylinder(h=0.01, r=ntr, center=true);
}
else
{
if ( ntd == -1 )
{
cylinder(h=ntl+0.01, r=ntr, $fn=floor(od*PI/rs), center=false);
}
else if ( ntd == 0 )
{
union()
{
cylinder(h=ntl-st/2,
r=od/2, $fn=floor(od*PI/rs), center=false);
translate([0,0,ntl-st/2])
cylinder(h=st/2,
r1=od/2, r2=ntr,
$fn=floor(od*PI/rs), center=false);
}
}
else
{
cylinder(h=ntl, r=ntd/2, $fn=ntd*PI/rs, center=false);
}
}
translate([0,0,ntl+hg]) screw_thread(od,st,lf0,lt,rs,cs);
}
}
module hex_screw_0(od,st,lf0,lt,rs,cs,df,hg,ntl,ntd)
{
ntr=od/2-(st/2)*cos(lf0)/sin(lf0);
union()
{
hex_head_0(hg,df);
translate([0,0,hg])
if ( ntl == 0 )
{
cylinder(h=0.01, r=ntr, center=true);
}
else
{
if ( ntd == -1 )
{
cylinder(h=ntl+0.01, r=ntr, $fn=floor(od*PI/rs), center=false);
}
else if ( ntd == 0 )
{
union()
{
cylinder(h=ntl-st/2,
r=od/2, $fn=floor(od*PI/rs), center=false);
translate([0,0,ntl-st/2])
cylinder(h=st/2,
r1=od/2, r2=ntr,
$fn=floor(od*PI/rs), center=false);
}
}
else
{
cylinder(h=ntl, r=ntd/2, $fn=ntd*PI/rs, center=false);
}
}
translate([0,0,ntl+hg]) screw_thread(od,st,lf0,lt,rs,cs);
}
}
module thread_shape(cs,lt,or,ir,sn,st)
{
if ( cs == 0 )
{
cylinder(h=lt, r=or, $fn=sn, center=false);
}
else
{
union()
{
translate([0,0,st/2])
cylinder(h=lt-st+0.005, r=or, $fn=sn, center=false);
if ( cs == -1 || cs == 2 )
{
cylinder(h=st/2, r1=ir, r2=or, $fn=sn, center=false);
}
else
{
cylinder(h=st/2, r=or, $fn=sn, center=false);
}
translate([0,0,lt-st/2])
if ( cs == 1 || cs == 2 )
{
cylinder(h=st/2, r1=or, r2=ir, $fn=sn, center=false);
}
else
{
cylinder(h=st/2, r=or, $fn=sn, center=false);
}
}
}
}
module full_thread(ttn,st,sn,zt,lfxy,or,ir)
{
if(ir >= 0.2)
{
for(i=[0:ttn-1])
{
for(j=[0:sn-1])
assign( pt = [ [0, 0, i*st-st ],
[ir*cos(j*lfxy), ir*sin(j*lfxy), i*st+j*zt-st ],
[ir*cos((j+1)*lfxy), ir*sin((j+1)*lfxy), i*st+(j+1)*zt-st ],
[0,0,i*st],
[or*cos(j*lfxy), or*sin(j*lfxy), i*st+j*zt-st/2 ],
[or*cos((j+1)*lfxy), or*sin((j+1)*lfxy), i*st+(j+1)*zt-st/2 ],
[ir*cos(j*lfxy), ir*sin(j*lfxy), i*st+j*zt ],
[ir*cos((j+1)*lfxy), ir*sin((j+1)*lfxy), i*st+(j+1)*zt ],
[0, 0, i*st+st ] ])
{
polyhedron(points=pt,
triangles=[ [1,0,3],[1,3,6],[6,3,8],[1,6,4],
[0,1,2],[1,4,2],[2,4,5],[5,4,6],[5,6,7],[7,6,8],
[7,8,3],[0,2,3],[3,2,7],[7,2,5] ]);
}
}
}
else
{
echo("Step Degrees too agresive, the thread will not be made!!");
echo("Try to increase de value for the degrees and/or...");
echo(" decrease the pitch value and/or...");
echo(" increase the outer diameter value.");
}
}
module hex_head(hg,df)
{
rd0=df/2/sin(60);
x0=0; x1=df/2; x2=x1+hg/2;
y0=0; y1=hg/2; y2=hg;
intersection()
{
cylinder(h=hg, r=rd0, $fn=6, center=false);
rotate_extrude(convexity=10, $fn=6*round(df*PI/6/0.5))
polygon([ [x0,y0],[x1,y0],[x2,y1],[x1,y2],[x0,y2] ]);
}
}
module hex_head_0(hg,df)
{
cylinder(h=hg, r=df/2/sin(60), $fn=6, center=false);
}
module hex_countersink_ends(chg,cod,clf,crs,hg)
{
translate([0,0,-0.1])
cylinder(h=chg+0.01,
r1=cod/2,
r2=cod/2-(chg+0.1)*cos(clf)/sin(clf),
$fn=floor(cod*PI/crs), center=false);
translate([0,0,hg-chg+0.1])
cylinder(h=chg+0.01,
r1=cod/2-(chg+0.1)*cos(clf)/sin(clf),
r2=cod/2,
$fn=floor(cod*PI/crs), center=false);
}