Rev Author Line No. Line
4536 jacho 1 /*
2 * polyScrewThread_r1.scad by aubenc @ Thingiverse
3 *
4 * This script contains the library modules that can be used to generate
5 * threaded rods, screws and nuts.
6 *
7 * http://www.thingiverse.com/thing:8796
8 *
9 * CC Public Domain
10 */
11  
12 module screw_thread(od,st,lf0,lt,rs,cs)
13 {
14 or=od/2;
15 ir=or-st/2*cos(lf0)/sin(lf0);
16 pf=2*PI*or;
17 sn=floor(pf/rs);
18 lfxy=360/sn;
19 ttn=round(lt/st+1);
20 zt=st/sn;
21  
22 intersection()
23 {
24 if (cs >= -1)
25 {
26 thread_shape(cs,lt,or,ir,sn,st);
27 }
28  
29 full_thread(ttn,st,sn,zt,lfxy,or,ir);
30 }
31 }
32  
33 module hex_nut(df,hg,sth,clf,cod,crs)
34 {
35  
36 difference()
37 {
38 hex_head(hg,df);
39  
40 hex_countersink_ends(sth/2,cod,clf,crs,hg);
41  
42 screw_thread(cod,sth,clf,hg,crs,-2);
43 }
44 }
45  
46  
47 module hex_screw(od,st,lf0,lt,rs,cs,df,hg,ntl,ntd)
48 {
49 ntr=od/2-(st/2)*cos(lf0)/sin(lf0);
50  
51 union()
52 {
53 hex_head(hg,df);
54  
55 translate([0,0,hg])
56 if ( ntl == 0 )
57 {
58 cylinder(h=0.01, r=ntr, center=true);
59 }
60 else
61 {
62 if ( ntd == -1 )
63 {
64 cylinder(h=ntl+0.01, r=ntr, $fn=floor(od*PI/rs), center=false);
65 }
66 else if ( ntd == 0 )
67 {
68 union()
69 {
70 cylinder(h=ntl-st/2,
71 r=od/2, $fn=floor(od*PI/rs), center=false);
72  
73 translate([0,0,ntl-st/2])
74 cylinder(h=st/2,
75 r1=od/2, r2=ntr,
76 $fn=floor(od*PI/rs), center=false);
77 }
78 }
79 else
80 {
81 cylinder(h=ntl, r=ntd/2, $fn=ntd*PI/rs, center=false);
82 }
83 }
84  
85 translate([0,0,ntl+hg]) screw_thread(od,st,lf0,lt,rs,cs);
86 }
87 }
88  
89 module hex_screw_0(od,st,lf0,lt,rs,cs,df,hg,ntl,ntd)
90 {
91 ntr=od/2-(st/2)*cos(lf0)/sin(lf0);
92  
93 union()
94 {
95 hex_head_0(hg,df);
96  
97 translate([0,0,hg])
98 if ( ntl == 0 )
99 {
100 cylinder(h=0.01, r=ntr, center=true);
101 }
102 else
103 {
104 if ( ntd == -1 )
105 {
106 cylinder(h=ntl+0.01, r=ntr, $fn=floor(od*PI/rs), center=false);
107 }
108 else if ( ntd == 0 )
109 {
110 union()
111 {
112 cylinder(h=ntl-st/2,
113 r=od/2, $fn=floor(od*PI/rs), center=false);
114  
115 translate([0,0,ntl-st/2])
116 cylinder(h=st/2,
117 r1=od/2, r2=ntr,
118 $fn=floor(od*PI/rs), center=false);
119 }
120 }
121 else
122 {
123 cylinder(h=ntl, r=ntd/2, $fn=ntd*PI/rs, center=false);
124 }
125 }
126  
127 translate([0,0,ntl+hg]) screw_thread(od,st,lf0,lt,rs,cs);
128 }
129 }
130  
131 module thread_shape(cs,lt,or,ir,sn,st)
132 {
133 if ( cs == 0 )
134 {
135 cylinder(h=lt, r=or, $fn=sn, center=false);
136 }
137 else
138 {
139 union()
140 {
141 translate([0,0,st/2])
142 cylinder(h=lt-st+0.005, r=or, $fn=sn, center=false);
143  
144 if ( cs == -1 || cs == 2 )
145 {
146 cylinder(h=st/2, r1=ir, r2=or, $fn=sn, center=false);
147 }
148 else
149 {
150 cylinder(h=st/2, r=or, $fn=sn, center=false);
151 }
152  
153 translate([0,0,lt-st/2])
154 if ( cs == 1 || cs == 2 )
155 {
156 cylinder(h=st/2, r1=or, r2=ir, $fn=sn, center=false);
157 }
158 else
159 {
160 cylinder(h=st/2, r=or, $fn=sn, center=false);
161 }
162 }
163 }
164 }
165  
166 module full_thread(ttn,st,sn,zt,lfxy,or,ir)
167 {
168 if(ir >= 0.2)
169 {
170 for(i=[0:ttn-1])
171 {
172 for(j=[0:sn-1])
173 assign( pt = [ [0, 0, i*st-st ],
174 [ir*cos(j*lfxy), ir*sin(j*lfxy), i*st+j*zt-st ],
175 [ir*cos((j+1)*lfxy), ir*sin((j+1)*lfxy), i*st+(j+1)*zt-st ],
176 [0,0,i*st],
177 [or*cos(j*lfxy), or*sin(j*lfxy), i*st+j*zt-st/2 ],
178 [or*cos((j+1)*lfxy), or*sin((j+1)*lfxy), i*st+(j+1)*zt-st/2 ],
179 [ir*cos(j*lfxy), ir*sin(j*lfxy), i*st+j*zt ],
180 [ir*cos((j+1)*lfxy), ir*sin((j+1)*lfxy), i*st+(j+1)*zt ],
181 [0, 0, i*st+st ] ])
182 {
183 polyhedron(points=pt,
184 triangles=[ [1,0,3],[1,3,6],[6,3,8],[1,6,4],
185 [0,1,2],[1,4,2],[2,4,5],[5,4,6],[5,6,7],[7,6,8],
186 [7,8,3],[0,2,3],[3,2,7],[7,2,5] ]);
187 }
188 }
189 }
190 else
191 {
192 echo("Step Degrees too agresive, the thread will not be made!!");
193 echo("Try to increase de value for the degrees and/or...");
194 echo(" decrease the pitch value and/or...");
195 echo(" increase the outer diameter value.");
196 }
197 }
198  
199 module hex_head(hg,df)
200 {
201 rd0=df/2/sin(60);
202 x0=0; x1=df/2; x2=x1+hg/2;
203 y0=0; y1=hg/2; y2=hg;
204  
205 intersection()
206 {
207 cylinder(h=hg, r=rd0, $fn=6, center=false);
208  
209 rotate_extrude(convexity=10, $fn=6*round(df*PI/6/0.5))
210 polygon([ [x0,y0],[x1,y0],[x2,y1],[x1,y2],[x0,y2] ]);
211 }
212 }
213  
214 module hex_head_0(hg,df)
215 {
216 cylinder(h=hg, r=df/2/sin(60), $fn=6, center=false);
217 }
218  
219 module hex_countersink_ends(chg,cod,clf,crs,hg)
220 {
221 translate([0,0,-0.1])
222 cylinder(h=chg+0.01,
223 r1=cod/2,
224 r2=cod/2-(chg+0.1)*cos(clf)/sin(clf),
225 $fn=floor(cod*PI/crs), center=false);
226  
227 translate([0,0,hg-chg+0.1])
228 cylinder(h=chg+0.01,
229 r1=cod/2-(chg+0.1)*cos(clf)/sin(clf),
230 r2=cod/2,
231 $fn=floor(cod*PI/crs), center=false);
232 }
233