summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--.gitignore3
-rw-r--r--Makefile22
-rw-r--r--another-E0.scad13
-rw-r--r--another-E1.scad13
-rw-r--r--another.scad300
-rw-r--r--threads.scad332
6 files changed, 683 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c25a6bd
--- a/dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
1/Makefile.local
2/*.stl
3/*.gcode
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9444a03
--- a/dev/null
+++ b/Makefile
@@ -0,0 +1,22 @@
1-include Makefile.local
2
3OPENSCAD_APP?=/Applications/OpenSCAD.app
4OPENSCAD_BIN?=${OPENSCAD_APP}/Contents/MacOS/OpenSCAD
5OPENSCAD_FLAGS=-D draft=false
6
7default:
8 @echo "And?"
9
10clean:
11 rm -f *.stl *.gcode
12
13stl-another-%:
14 $(MAKE) another-$*-{body,lever}.stl
15
16another-%-body.stl: another-%.scad another.scad
17 $(OPENSCAD_BIN) $(OPENSCAD_FLAGS) -D 'what="body"' -o "$@" "$<"
18another-%-lever.stl: another-%.scad another.scad
19 $(OPENSCAD_BIN) $(OPENSCAD_FLAGS) -D 'what="lever"' -o "$@" "$<"
20
21%.stl: %.scad
22 ${OPENSCAD_BIN} ${OPENSCAD_FLAGS} -o "$@" "$<"
diff --git a/another-E0.scad b/another-E0.scad
new file mode 100644
index 0000000..2f639b9
--- a/dev/null
+++ b/another-E0.scad
@@ -0,0 +1,13 @@
1use <another.scad>;
2
3what="body";
4vitamins=false;
5
6rotate([180,0,0])
7the_extruder(what=what, vitamins=vitamins,
8
9 left=true,
10 pulley_d=12.65, pulley_elevation=1,
11 teeth_elevation = 7.88,
12 bore_l = 20
13);
diff --git a/another-E1.scad b/another-E1.scad
new file mode 100644
index 0000000..bbd42f0
--- a/dev/null
+++ b/another-E1.scad
@@ -0,0 +1,13 @@
1use <another.scad>;
2
3what="body";
4vitamins=false;
5
6rotate([180,0,0])
7the_extruder(what=what, vitamins=vitamins,
8
9 left=false,
10 pulley_d=11.5, pulley_elevation=1,
11 teeth_elevation=7.5,
12 bore_l=17.6
13);
diff --git a/another.scad b/another.scad
new file mode 100644
index 0000000..f78d1b0
--- a/dev/null
+++ b/another.scad
@@ -0,0 +1,300 @@
1draft=true;
2layer_height=0.2; extrusion_width=0.4;
3epsilon=0.01;
4$fs=0.0125;
5
6use <threads.scad>;
7module pushfit_thread(h=10) {
8 thr = 3/8 + .5/25.4;
9 slit = 25.4*thr/2 + 0.4;
10 if(draft) cylinder(d=thr*25.4,h=h);
11 else english_thread(diameter=thr,threads_per_inch=28,length=h/25.4,internal=true);
12 translate([-2,-slit,0]) cube([4,2*slit,h]);
13}
14
15module the_extruder(
16 // motor properties
17 gearbox_d = 36,
18 mount_d = 28, // the distance between opposite mounting holes
19 mounthole_depth = 5,
20 protrusion_d = 22, protrusion_h = 2.2, // the dimensions of the protrusion on top of gearbox
21 bore_d = 8, bore_l = 17.6,
22 // pulley properties
23 pulley_d = 11.5, pulley_h=10,
24 pulley_elevation = 1, // pulley elevation above the protrusion
25 teeth_elevation = 7.5, // distance from the bottom of the pulley to its teeth
26 // idler properties
27 idler_d = 9.5, idler_h = 4, idler_id = 3,// idler dimensions: outer and inner diameters and height
28 // spring properties
29 spring_d = 10, spring_lc = 9.6, // spring diameter and compressed length
30 // filament path properties
31 filament_d = 1.75,
32 filament_path_d = 2,
33 filament_guide_d = 4, // PTFE filament guide diameter
34
35 // screw it
36 mount_screw_d = 3, mount_screw_l = 20,
37 mount_screwhead_d=6, mount_screwhead_h=3,
38
39 // empty spaces
40 idler_travel = 3, // how far should idler travel when pressed
41 idler_clearance=1,
42 pulley_clearance=2,
43 lever_v_clearance=.7, // vertical clearance for the lever
44 spring_d_clearance=1,
45 protrusion_tolerance_h=.5, // horizontal tolerance for the motor protrusion
46 protrusion_tolerance_v=.5, // vertical tolerance for the motor protrusion
47 mount_screw_d_tolerance=.5,
48 idler_v_tolerance=.5,
49
50 what="lever",
51 left=false,
52 vitamins = true
53) {
54 lever_shell = mount_screwhead_h+0.5;
55 lever_thickness=max(spring_d+layer_height*8,idler_h+idler_v_tolerance+2*lever_shell);
56 lsd = idler_d-idler_clearance*2;
57 longwing=gearbox_d/2+spring_d/2+lsd/2;
58 h_ = (pulley_d+idler_d)/(2*sqrt(2));
59 ri = sqrt( pow(h_,2) + pow(mount_d/2-h_,2) );
60 spring_dl = idler_travel*longwing/ri;
61
62 module mirrorleft() {
63 mirror([left?0:1,0,0]) children();
64 }
65 module place_idler() {
66 rotate([0,0,45])
67 translate([(pulley_d+idler_d)/2,0,0])
68 children();
69 }
70 module finger_indent(d=lever_thickness,depth/*=1*/,r/*=15*/) {
71 if(depth) {
72 hh = (-4*pow(depth,2)+pow(d,2))/(8*depth);
73 rr = depth+hh;
74 translate([0,0,hh]) sphere(r=rr,$fn=2*PI*rr);
75 }else if(r) {
76 hh=sqrt(pow(r,2)-pow(d,2)/4);
77 translate([0,0,hh]) sphere(r=r,$fn=2*PI*r);
78 }
79 }
80
81 // vitamins
82 % if(vitamins) mirrorleft() {
83 translate([0,0,-epsilon]) mirror([0,0,1]) cylinder(d=gearbox_d,h=1,$fn=60);
84 for(zr=[0:90:359]) rotate([0,0,zr]) translate([mount_d/2,0,0])
85 cylinder(d=mount_screw_d,h=20,$fn=30);
86 translate([0,0,-epsilon]) cylinder(d=protrusion_d,h=protrusion_h,$fn=30);
87 translate([0,0,protrusion_h]) {
88 cylinder(d=bore_d,h=bore_l,$fn=30);
89 translate([0,0,pulley_elevation]) {
90 cylinder(d=pulley_d,h=pulley_h,$fn=30);
91 translate([0,0,teeth_elevation]) {
92 place_idler() {
93 cylinder(d=idler_d,h=idler_h,center=true,$fn=30);
94 cylinder(d=idler_id,h=lever_thickness+2,center=true,$fn=30);
95 }//place idler
96 // filament path
97 rotate([0,0,45]) translate([(pulley_d-filament_path_d)/2,0,0]) {
98 rotate([90,0,0]) cylinder(d=filament_d,h=gearbox_d*2,center=true,$fn=15);
99 rotate([-90,0,0])
100 translate([0,0,mount_d/sqrt(2)/2+mount_screw_d])
101 pushfit_thread();
102 }
103 }//translate teeth
104 }//translate pulley
105 }//translate protrusion
106 }// vitamins to let
107
108 module lever() {
109 translate([0,0,protrusion_h+pulley_elevation+teeth_elevation]) {
110 difference() {
111 union() {
112 hull() {
113 place_idler()
114 cylinder(d=lsd,h=lever_thickness,center=true,$fn=60);
115 translate([mount_d/2,0,0])
116 cylinder(d=lsd,h=lever_thickness,center=true,$fn=60);
117 }//hull
118 hull() {
119 translate([mount_d/2,0,0])
120 cylinder(d=lsd,h=lever_thickness,center=true,$fn=60);
121 translate([mount_d/2,-longwing,0]) rotate([0,90,0])
122 cylinder(d=lever_thickness,h=lsd,center=true,$fn=60);
123 }//hull
124 }//union
125
126 // filament path
127 place_idler() translate([-(idler_d+filament_path_d)/2,0,0]) rotate([90,0,0]) {
128 cylinder(d=filament_path_d,h=3*gearbox_d,center=true,$fn=30);
129 translate([0,-filament_path_d/2/sqrt(2),0]) rotate([0,0,45])
130 cube(size=[filament_path_d/2,filament_path_d/2,3*gearbox_d],center=true);
131 }
132
133 // idler space and mounting hole
134 place_idler() {
135 difference() {
136 cylinder(d=idler_d+idler_clearance*2,h=idler_h+idler_v_tolerance,center=true,$fn=60);
137 // supports
138 for(y=[-lsd/2+extrusion_width:(lsd-2*extrusion_width)/3:lsd/2-extrusion_width])
139 translate([-lsd/2-1,y-extrusion_width/2,-idler_h/2-idler_v_tolerance/2-1])
140 cube(size=[lsd+2,extrusion_width,idler_h+idler_v_tolerance+2]);
141 }
142 cylinder(d=mount_screw_d+mount_screw_d_tolerance,h=lever_thickness+2,center=true,$fn=30);
143 translate([0,0,lever_thickness/2-mount_screwhead_h])
144 cylinder(d=mount_screwhead_d,h=mount_screwhead_h+1,$fn=2*PI*mount_screwhead_d);
145 }
146 // mounting screw hole
147 translate([mount_d/2,0,0])
148 cylinder(d=mount_screw_d+mount_screw_d_tolerance,h=lever_thickness+2,center=true,$fn=2*PI*mount_screw_d);
149
150 // lever end
151 translate([mount_d/2,0,0]) rotate([0,90,0]) {
152 translate([0,-longwing,lsd/2]) finger_indent(d=lever_thickness-1,r=15);
153 translate([0,-longwing,0])
154 mirror([0,0,1])
155 difference() {
156 cylinder(d=spring_d+spring_d_clearance,h=lsd,$fn=2*PI*spring_d);
157 sphere(d=spring_d*3/4,$fn=PI*spring_d);
158 }
159 }//rotate-translate
160 }//difference
161 // bridging patch
162 place_idler()
163 translate([0,0,lever_thickness/2-mount_screwhead_h])
164 mirror([0,0,1])
165 cylinder(d=mount_screwhead_d,h=layer_height);
166 }//translate
167 }//lever module
168
169 module body() {
170 filament_elevation=protrusion_h+pulley_elevation+teeth_elevation;
171 ls_z = filament_elevation;
172 body_h = max(protrusion_h+bore_l,mount_screw_l-mounthole_depth/2+mount_screwhead_h,ls_z*2);
173 ls_h = lever_thickness+lever_v_clearance;
174 difference() {
175 union() {
176 cylinder(d=gearbox_d,h=body_h,$fn=2*PI*gearbox_d);
177 // finger and spring support
178 fsw = gearbox_d/2+mount_screwhead_d/2;
179 translate([-gearbox_d/2,0,0]) difference() {
180 union() {
181 hull() {
182 translate([0,-longwing,ls_z])
183 rotate([0,90,0])
184 cylinder(d=lever_thickness,h=fsw,$fn=2*PI*lever_thickness);
185 hh=body_h-ls_z;
186 translate([0,0,ls_z-lever_thickness/2])
187 mirror([0,1,0]) cube(size=[fsw,longwing-hh+lever_thickness/sqrt(2),hh+lever_thickness/2]);
188 hhh=ls_z;
189 translate([0,0,0])
190 mirror([0,1,0]) cube(size=[fsw,longwing-hhh+lever_thickness/sqrt(2),hhh+lever_thickness/2]);
191 }
192 }
193 translate([0,-longwing,ls_z]) rotate([0,-90,0])
194 finger_indent(d=lever_thickness-1,r=15);
195 } // translate
196
197 // pushfit bracket
198 translate([0,0,filament_elevation])
199 rotate([0,0,45]) translate([pulley_d/2,0,0])
200 rotate([-90,0,0])
201 translate([0,0,mount_d/sqrt(2)/2+mount_screw_d-gearbox_d/2/*TODO:*/])
202 cylinder(r=min(body_h-filament_elevation,filament_elevation)/sin(60)-epsilon,h=10+gearbox_d/2/*TODO:*/,$fn=6);
203 }//union (first child of difference)
204 // protrusion
205 translate([0,0,-1])
206 cylinder(d=protrusion_d+protrusion_tolerance_h,h=protrusion_h+protrusion_tolerance_v+1,$fn=2*PI*protrusion_d);
207 // mount screw holes
208 for(zr=[0:90:359]) rotate([0,0,zr]) translate([mount_d/2,0,0]) {
209 translate([0,0,mount_screw_l-mounthole_depth/2-layer_height-1])
210 mirror([0,0,1])
211 cylinder(d=mount_screw_d+mount_screw_d_tolerance,
212 h=mount_screw_l-mounthole_depth/2-layer_height+1,
213 $fn=2*PI*mount_screw_d);
214 translate([0,0,mount_screw_l-mounthole_depth/2])
215 cylinder(d=mount_screwhead_d,h=body_h+1,$fn=2*PI*mount_screwhead_d);
216 }//for
217 // pushfit threads
218 translate([0,0,filament_elevation])
219 rotate([0,0,45]) translate([pulley_d/2,0,0])
220 rotate([-90,0,0])
221 translate([0,0,mount_d/sqrt(2)/2+mount_screw_d+epsilon])
222 rotate([0,0,180]) {
223 pushfit_thread(h=10);
224 cylinder(d=filament_guide_d,h=gearbox_d,center=true,$fn=2*PI*filament_guide_d);
225 translate([0,-filament_guide_d/2/sqrt(2),0])
226 rotate([0,0,45])
227 cube(size=[filament_guide_d/2,filament_guide_d/2,gearbox_d],center=true);
228 }
229 // pulley
230 cylinder(d=pulley_d+pulley_clearance,h=body_h+1,$fn=2*PI*(pulley_d+pulley_clearance));
231 // leverspace
232 hull() for(x=[0,gearbox_d])
233 rotate([0,0,45])
234 translate([x,0,ls_z-ls_h/2])
235 cylinder(d=idler_d+idler_clearance,h=ls_h,$fn=2*PI*idler_d);
236
237 a=cos(45)*(pulley_d+idler_d)/2;
238 b=mount_d/2-a;
239 x=sqrt(pow(a,2)+pow(b,2));
240 translate([mount_d/2,0,ls_z])
241 intersection() {
242 r = x+idler_d/2+1;/* TODO: */
243 cylinder(r=r,h=ls_h,center=true);
244 translate([-r-1,0,-1]) cube(size=[2*r+2,r+1,ls_h+2]);
245 }
246
247 rotate([0,0,-45])
248 translate([0,0,ls_z-ls_h/2])
249 cube(size=[gearbox_d,gearbox_d,lever_thickness+lever_v_clearance]);
250 translate([0,0,ls_z-ls_h/2]) {
251 translate([mount_screwhead_d/2,0,0])
252 mirror([0,1,0])
253 cube(size=[gearbox_d,gearbox_d/2+1,lever_thickness+lever_v_clearance]);
254 }
255 //translate([-mount_d/2,-longwing,filament_elevation])
256 translate([mount_d/2,-longwing,filament_elevation])
257 rotate([0,-90,0]) difference() {
258 cylinder(d=spring_d+spring_d_clearance,h=spring_lc+spring_dl,$fn=PI*spring_d);
259 translate([0,0,spring_lc+spring_dl]) sphere(d=spring_d*3/4,$fn=PI*spring_d);
260 }
261 //sphere(d=spring_d*3/4,$fn=PI*spring_d);
262 *difference() {
263 // spring support
264 translate([0,-longwing,filament_elevation])
265 sphere(d=spring_d*3/4,$fn=PI*spring_d);
266 }
267
268 }//difference
269
270 intersection() {
271 difference() {
272 translate([0,0,ls_z-ls_h/2-epsilon])
273 cylinder(d=gearbox_d,h=ls_h+2*epsilon,$fn=2*PI*gearbox_d);
274 cylinder(d=pulley_d+pulley_clearance,h=body_h+1,$fn=2*PI*(pulley_d+pulley_clearance));
275 }
276 // supports
277 // TODO: hardcoded stuff below…
278 if(false) { // parallel
279 for(y=[-gearbox_d:4:gearbox_d])
280 translate([0,y-extrusion_width/2,0])
281 cube(size=[gearbox_d,extrusion_width,body_h]);
282 }else{ // radial
283 for(zr=[-65:(65+50)/7:50])
284 rotate([0,0,zr]) translate([0,-extrusion_width/2,0])
285 cube(size=[gearbox_d,extrusion_width,body_h]);
286 }
287 }
288
289 }//body module
290
291 mirrorleft()
292 if(what=="lever") color("green",0.7) lever();
293 else if(what=="body") color("yellow",0.7) body();
294 else if(what=="both") {
295 color("green",0.7) lever();
296 color("yellow",0.7) body();
297 }
298}
299
300the_extruder(what="both",left=false);
diff --git a/threads.scad b/threads.scad
new file mode 100644
index 0000000..8dd0b7b
--- a/dev/null
+++ b/threads.scad
@@ -0,0 +1,332 @@
1/*
2 * ISO-standard metric threads, following this specification:
3 * http://en.wikipedia.org/wiki/ISO_metric_screw_thread
4 *
5 * Dan Kirshner - dan_kirshner@yahoo.com
6 *
7 * You are welcome to make free use of this software. Retention of my
8 * authorship credit would be appreciated.
9 *
10 * Version 1.9. 2016-07-03 Option: tapered.
11 * Version 1.8. 2016-01-08 Option: (non-standard) angle.
12 * Version 1.7. 2015-11-28 Larger x-increment - for small-diameters.
13 * Version 1.6. 2015-09-01 Options: square threads, rectangular threads.
14 * Version 1.5. 2015-06-12 Options: thread_size, groove.
15 * Version 1.4. 2014-10-17 Use "faces" instead of "triangles" for polyhedron
16 * Version 1.3. 2013-12-01 Correct loop over turns -- don't have early cut-off
17 * Version 1.2. 2012-09-09 Use discrete polyhedra rather than linear_extrude ()
18 * Version 1.1. 2012-09-07 Corrected to right-hand threads!
19 */
20
21// Examples.
22//
23// Standard M8 x 1.
24// metric_thread (diameter=8, pitch=1, length=4);
25
26// Square thread.
27// metric_thread (diameter=8, pitch=1, length=4, square=true);
28
29// Non-standard: long pitch, same thread size.
30//metric_thread (diameter=8, pitch=4, length=4, thread_size=1, groove=true);
31
32// Non-standard: 20 mm diameter, long pitch, square "trough" width 3 mm,
33// depth 1 mm.
34//metric_thread (diameter=20, pitch=8, length=16, square=true, thread_size=6,
35// groove=true, rectangle=0.333);
36
37// English: 1/4 x 20.
38//english_thread (diameter=1/4, threads_per_inch=20, length=1);
39
40// Tapered. Example -- pipe size 3/4" -- per:
41// http://www.engineeringtoolbox.com/npt-national-pipe-taper-threads-d_750.html
42// english_thread (diameter=1.05, threads_per_inch=14, length=3/4, taper=1/16);
43
44// Thread for mounting on Rohloff hub.
45//difference () {
46// cylinder (r=20, h=10, $fn=100);
47//
48// metric_thread (diameter=34, pitch=1, length=10, internal=true, n_starts=6);
49//}
50
51
52// ----------------------------------------------------------------------------
53function segments (diameter) = min (50, ceil (diameter*6));
54
55
56// ----------------------------------------------------------------------------
57// internal - true = clearances for internal thread (e.g., a nut).
58// false = clearances for external thread (e.g., a bolt).
59// (Internal threads should be "cut out" from a solid using
60// difference ()).
61// n_starts - Number of thread starts (e.g., DNA, a "double helix," has
62// n_starts=2). See wikipedia Screw_thread.
63// thread_size - (non-standard) size of a single thread "V" - independent of
64// pitch. Default: same as pitch.
65// groove - (non-standard) subtract inverted "V" from cylinder (rather than
66// add protruding "V" to cylinder).
67// square - Square threads (per
68// https://en.wikipedia.org/wiki/Square_thread_form).
69// rectangle - (non-standard) "Rectangular" thread - ratio depth/width
70// Default: 1 (square).
71// angle - (non-standard) angle (deg) of thread side from perpendicular to
72// axis (default = standard = 30 degrees).
73// taper - diameter change per length (National Pipe Thread/ANSI B1.20.1
74// is 1" diameter per 16" length).
75module metric_thread (diameter=8, pitch=1, length=1, internal=false, n_starts=1,
76 thread_size=-1, groove=false, square=false, rectangle=0,
77 angle=30, taper=0)
78{
79 // thread_size: size of thread "V" different than travel per turn (pitch).
80 // Default: same as pitch.
81 local_thread_size = thread_size == -1 ? pitch : thread_size;
82 local_rectangle = rectangle ? rectangle : 1;
83
84 n_segments = segments (diameter);
85 h = (square || rectangle) ? local_thread_size*local_rectangle/2 : local_thread_size * cos (angle);
86
87 h_fac1 = (square || rectangle) ? 0.90 : 0.625;
88
89 // External thread includes additional relief.
90 h_fac2 = (square || rectangle) ? 0.95 : 5.3/8;
91
92 if (! groove) {
93 metric_thread_turns (diameter, pitch, length, internal, n_starts,
94 local_thread_size, groove, square, rectangle, angle,
95 taper);
96 }
97
98 difference () {
99
100 // Solid center, including Dmin truncation.
101 tapered_diameter = diameter - length*taper;
102 if (groove) {
103 cylinder (r1=diameter/2, r2=tapered_diameter/2,
104 h=length, $fn=n_segments);
105 } else if (internal) {
106 cylinder (r1=diameter/2 - h*h_fac1, r2=tapered_diameter/2 - h*h_fac1,
107 h=length, $fn=n_segments);
108 } else {
109
110 // External thread.
111 cylinder (r1=diameter/2 - h*h_fac2, r2=tapered_diameter/2 - h*h_fac2,
112 h=length, $fn=n_segments);
113 }
114
115 if (groove) {
116 metric_thread_turns (diameter, pitch, length, internal, n_starts,
117 local_thread_size, groove, square, rectangle,
118 angle, taper);
119 }
120 }
121}
122
123
124// ----------------------------------------------------------------------------
125// Input units in inches.
126// Note: units of measure in drawing are mm!
127module english_thread (diameter=0.25, threads_per_inch=20, length=1,
128 internal=false, n_starts=1, thread_size=-1, groove=false,
129 square=false, rectangle=0, angle=30, taper=0)
130{
131 // Convert to mm.
132 mm_diameter = diameter*25.4;
133 mm_pitch = (1.0/threads_per_inch)*25.4;
134 mm_length = length*25.4;
135
136 echo (str ("mm_diameter: ", mm_diameter));
137 echo (str ("mm_pitch: ", mm_pitch));
138 echo (str ("mm_length: ", mm_length));
139 metric_thread (mm_diameter, mm_pitch, mm_length, internal, n_starts,
140 thread_size, groove, square, rectangle, angle, taper);
141}
142
143// ----------------------------------------------------------------------------
144module metric_thread_turns (diameter, pitch, length, internal, n_starts,
145 thread_size, groove, square, rectangle, angle,
146 taper)
147{
148 // Number of turns needed.
149 n_turns = floor (length/pitch);
150
151 intersection () {
152
153 // Start one below z = 0. Gives an extra turn at each end.
154 for (i=[-1*n_starts : n_turns+1]) {
155 translate ([0, 0, i*pitch]) {
156 metric_thread_turn (diameter, pitch, internal, n_starts,
157 thread_size, groove, square, rectangle, angle,
158 taper, i*pitch);
159 }
160 }
161
162 // Cut to length.
163 translate ([0, 0, length/2]) {
164 cube ([diameter*3, diameter*3, length], center=true);
165 }
166 }
167}
168
169
170// ----------------------------------------------------------------------------
171module metric_thread_turn (diameter, pitch, internal, n_starts, thread_size,
172 groove, square, rectangle, angle, taper, z)
173{
174 n_segments = segments (diameter);
175 fraction_circle = 1.0/n_segments;
176 for (i=[0 : n_segments-1]) {
177 rotate ([0, 0, i*360*fraction_circle]) {
178 translate ([0, 0, i*n_starts*pitch*fraction_circle]) {
179 current_diameter = diameter - taper*(z + i*n_starts*pitch*fraction_circle);
180 thread_polyhedron (current_diameter/2, pitch, internal, n_starts,
181 thread_size, groove, square, rectangle, angle);
182 }
183 }
184 }
185}
186
187
188// ----------------------------------------------------------------------------
189// z (see diagram) as function of current radius.
190// (Only good for first half-pitch.)
191function z_fct (current_radius, radius, pitch, angle)
192 = 0.5* (current_radius - (radius - 0.875*pitch*cos (angle)))
193 /cos (angle);
194
195// ----------------------------------------------------------------------------
196module thread_polyhedron (radius, pitch, internal, n_starts, thread_size,
197 groove, square, rectangle, angle)
198{
199 n_segments = segments (radius*2);
200 fraction_circle = 1.0/n_segments;
201
202 local_rectangle = rectangle ? rectangle : 1;
203
204 h = (square || rectangle) ? thread_size*local_rectangle/2 : thread_size * cos (angle);
205 outer_r = radius + (internal ? h/20 : 0); // Adds internal relief.
206 //echo (str ("outer_r: ", outer_r));
207
208 // A little extra on square thread -- make sure overlaps cylinder.
209 h_fac1 = (square || rectangle) ? 1.1 : 0.875;
210 inner_r = radius - h*h_fac1; // Does NOT do Dmin_truncation - do later with
211 // cylinder.
212
213 translate_y = groove ? outer_r + inner_r : 0;
214 reflect_x = groove ? 1 : 0;
215
216 // Make these just slightly bigger (keep in proportion) so polyhedra will
217 // overlap.
218 x_incr_outer = (! groove ? outer_r : inner_r) * fraction_circle * 2 * PI * 1.02;
219 x_incr_inner = (! groove ? inner_r : outer_r) * fraction_circle * 2 * PI * 1.02;
220 z_incr = n_starts * pitch * fraction_circle * 1.005;
221
222 /*
223 (angles x0 and x3 inner are actually 60 deg)
224
225 /\ (x2_inner, z2_inner) [2]
226 / \
227 (x3_inner, z3_inner) / \
228 [3] \ \
229 |\ \ (x2_outer, z2_outer) [6]
230 | \ /
231 | \ /|
232 z |[7]\/ / (x1_outer, z1_outer) [5]
233 | | | /
234 | x | |/
235 | / | / (x0_outer, z0_outer) [4]
236 | / | / (behind: (x1_inner, z1_inner) [1]
237 |/ | /
238 y________| |/
239 (r) / (x0_inner, z0_inner) [0]
240
241 */
242
243 x1_outer = outer_r * fraction_circle * 2 * PI;
244
245 z0_outer = z_fct (outer_r, radius, thread_size, angle);
246 //echo (str ("z0_outer: ", z0_outer));
247
248 //polygon ([[inner_r, 0], [outer_r, z0_outer],
249 // [outer_r, 0.5*pitch], [inner_r, 0.5*pitch]]);
250 z1_outer = z0_outer + z_incr;
251
252 // Give internal square threads some clearance in the z direction, too.
253 bottom = internal ? 0.235 : 0.25;
254 top = internal ? 0.765 : 0.75;
255
256 translate ([0, translate_y, 0]) {
257 mirror ([reflect_x, 0, 0]) {
258
259 if (square || rectangle) {
260
261 // Rule for face ordering: look at polyhedron from outside: points must
262 // be in clockwise order.
263 polyhedron (
264 points = [
265 [-x_incr_inner/2, -inner_r, bottom*thread_size], // [0]
266 [x_incr_inner/2, -inner_r, bottom*thread_size + z_incr], // [1]
267 [x_incr_inner/2, -inner_r, top*thread_size + z_incr], // [2]
268 [-x_incr_inner/2, -inner_r, top*thread_size], // [3]
269
270 [-x_incr_outer/2, -outer_r, bottom*thread_size], // [4]
271 [x_incr_outer/2, -outer_r, bottom*thread_size + z_incr], // [5]
272 [x_incr_outer/2, -outer_r, top*thread_size + z_incr], // [6]
273 [-x_incr_outer/2, -outer_r, top*thread_size] // [7]
274 ],
275
276 faces = [
277 [0, 3, 7, 4], // This-side trapezoid
278
279 [1, 5, 6, 2], // Back-side trapezoid
280
281 [0, 1, 2, 3], // Inner rectangle
282
283 [4, 7, 6, 5], // Outer rectangle
284
285 // These are not planar, so do with separate triangles.
286 [7, 2, 6], // Upper rectangle, bottom
287 [7, 3, 2], // Upper rectangle, top
288
289 [0, 5, 1], // Lower rectangle, bottom
290 [0, 4, 5] // Lower rectangle, top
291 ]
292 );
293 } else {
294
295 // Rule for face ordering: look at polyhedron from outside: points must
296 // be in clockwise order.
297 polyhedron (
298 points = [
299 [-x_incr_inner/2, -inner_r, 0], // [0]
300 [x_incr_inner/2, -inner_r, z_incr], // [1]
301 [x_incr_inner/2, -inner_r, thread_size + z_incr], // [2]
302 [-x_incr_inner/2, -inner_r, thread_size], // [3]
303
304 [-x_incr_outer/2, -outer_r, z0_outer], // [4]
305 [x_incr_outer/2, -outer_r, z0_outer + z_incr], // [5]
306 [x_incr_outer/2, -outer_r, thread_size - z0_outer + z_incr], // [6]
307 [-x_incr_outer/2, -outer_r, thread_size - z0_outer] // [7]
308 ],
309
310 faces = [
311 [0, 3, 7, 4], // This-side trapezoid
312
313 [1, 5, 6, 2], // Back-side trapezoid
314
315 [0, 1, 2, 3], // Inner rectangle
316
317 [4, 7, 6, 5], // Outer rectangle
318
319 // These are not planar, so do with separate triangles.
320 [7, 2, 6], // Upper rectangle, bottom
321 [7, 3, 2], // Upper rectangle, top
322
323 [0, 5, 1], // Lower rectangle, bottom
324 [0, 4, 5] // Lower rectangle, top
325 ]
326 );
327 }
328 }
329 }
330}
331
332