summaryrefslogtreecommitdiff
authorMichael Krelin <hacker@klever.net>2017-02-04 18:00:01 (UTC)
committer Michael Krelin <hacker@klever.net>2017-02-04 18:00:01 (UTC)
commit25836f14f59bdeb216a6fb189b6c4720db518c0d (patch) (side-by-side diff)
tree7851f58079da0f0d8a893fee1f7c0a47d51cf569
downloadextrudery-25836f14f59bdeb216a6fb189b6c4720db518c0d.zip
extrudery-25836f14f59bdeb216a6fb189b6c4720db518c0d.tar.gz
extrudery-25836f14f59bdeb216a6fb189b6c4720db518c0d.tar.bz2
Initial
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 @@
+/Makefile.local
+/*.stl
+/*.gcode
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9444a03
--- a/dev/null
+++ b/Makefile
@@ -0,0 +1,22 @@
+-include Makefile.local
+
+OPENSCAD_APP?=/Applications/OpenSCAD.app
+OPENSCAD_BIN?=${OPENSCAD_APP}/Contents/MacOS/OpenSCAD
+OPENSCAD_FLAGS=-D draft=false
+
+default:
+ @echo "And?"
+
+clean:
+ rm -f *.stl *.gcode
+
+stl-another-%:
+ $(MAKE) another-$*-{body,lever}.stl
+
+another-%-body.stl: another-%.scad another.scad
+ $(OPENSCAD_BIN) $(OPENSCAD_FLAGS) -D 'what="body"' -o "$@" "$<"
+another-%-lever.stl: another-%.scad another.scad
+ $(OPENSCAD_BIN) $(OPENSCAD_FLAGS) -D 'what="lever"' -o "$@" "$<"
+
+%.stl: %.scad
+ ${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 @@
+use <another.scad>;
+
+what="body";
+vitamins=false;
+
+rotate([180,0,0])
+the_extruder(what=what, vitamins=vitamins,
+
+ left=true,
+ pulley_d=12.65, pulley_elevation=1,
+ teeth_elevation = 7.88,
+ bore_l = 20
+);
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 @@
+use <another.scad>;
+
+what="body";
+vitamins=false;
+
+rotate([180,0,0])
+the_extruder(what=what, vitamins=vitamins,
+
+ left=false,
+ pulley_d=11.5, pulley_elevation=1,
+ teeth_elevation=7.5,
+ bore_l=17.6
+);
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 @@
+draft=true;
+layer_height=0.2; extrusion_width=0.4;
+epsilon=0.01;
+$fs=0.0125;
+
+use <threads.scad>;
+module pushfit_thread(h=10) {
+ thr = 3/8 + .5/25.4;
+ slit = 25.4*thr/2 + 0.4;
+ if(draft) cylinder(d=thr*25.4,h=h);
+ else english_thread(diameter=thr,threads_per_inch=28,length=h/25.4,internal=true);
+ translate([-2,-slit,0]) cube([4,2*slit,h]);
+}
+
+module the_extruder(
+ // motor properties
+ gearbox_d = 36,
+ mount_d = 28, // the distance between opposite mounting holes
+ mounthole_depth = 5,
+ protrusion_d = 22, protrusion_h = 2.2, // the dimensions of the protrusion on top of gearbox
+ bore_d = 8, bore_l = 17.6,
+ // pulley properties
+ pulley_d = 11.5, pulley_h=10,
+ pulley_elevation = 1, // pulley elevation above the protrusion
+ teeth_elevation = 7.5, // distance from the bottom of the pulley to its teeth
+ // idler properties
+ idler_d = 9.5, idler_h = 4, idler_id = 3, // idler dimensions: outer and inner diameters and height
+ // spring properties
+ spring_d = 10, spring_lc = 9.6, // spring diameter and compressed length
+ // filament path properties
+ filament_d = 1.75,
+ filament_path_d = 2,
+ filament_guide_d = 4, // PTFE filament guide diameter
+
+ // screw it
+ mount_screw_d = 3, mount_screw_l = 20,
+ mount_screwhead_d=6, mount_screwhead_h=3,
+
+ // empty spaces
+ idler_travel = 3, // how far should idler travel when pressed
+ idler_clearance=1,
+ pulley_clearance=2,
+ lever_v_clearance=.7, // vertical clearance for the lever
+ spring_d_clearance=1,
+ protrusion_tolerance_h=.5, // horizontal tolerance for the motor protrusion
+ protrusion_tolerance_v=.5, // vertical tolerance for the motor protrusion
+ mount_screw_d_tolerance=.5,
+ idler_v_tolerance=.5,
+
+ what="lever",
+ left=false,
+ vitamins = true
+) {
+ lever_shell = mount_screwhead_h+0.5;
+ lever_thickness=max(spring_d+layer_height*8,idler_h+idler_v_tolerance+2*lever_shell);
+ lsd = idler_d-idler_clearance*2;
+ longwing=gearbox_d/2+spring_d/2+lsd/2;
+ h_ = (pulley_d+idler_d)/(2*sqrt(2));
+ ri = sqrt( pow(h_,2) + pow(mount_d/2-h_,2) );
+ spring_dl = idler_travel*longwing/ri;
+
+ module mirrorleft() {
+ mirror([left?0:1,0,0]) children();
+ }
+ module place_idler() {
+ rotate([0,0,45])
+ translate([(pulley_d+idler_d)/2,0,0])
+ children();
+ }
+ module finger_indent(d=lever_thickness,depth/*=1*/,r/*=15*/) {
+ if(depth) {
+ hh = (-4*pow(depth,2)+pow(d,2))/(8*depth);
+ rr = depth+hh;
+ translate([0,0,hh]) sphere(r=rr,$fn=2*PI*rr);
+ }else if(r) {
+ hh=sqrt(pow(r,2)-pow(d,2)/4);
+ translate([0,0,hh]) sphere(r=r,$fn=2*PI*r);
+ }
+ }
+
+ // vitamins
+ % if(vitamins) mirrorleft() {
+ translate([0,0,-epsilon]) mirror([0,0,1]) cylinder(d=gearbox_d,h=1,$fn=60);
+ for(zr=[0:90:359]) rotate([0,0,zr]) translate([mount_d/2,0,0])
+ cylinder(d=mount_screw_d,h=20,$fn=30);
+ translate([0,0,-epsilon]) cylinder(d=protrusion_d,h=protrusion_h,$fn=30);
+ translate([0,0,protrusion_h]) {
+ cylinder(d=bore_d,h=bore_l,$fn=30);
+ translate([0,0,pulley_elevation]) {
+ cylinder(d=pulley_d,h=pulley_h,$fn=30);
+ translate([0,0,teeth_elevation]) {
+ place_idler() {
+ cylinder(d=idler_d,h=idler_h,center=true,$fn=30);
+ cylinder(d=idler_id,h=lever_thickness+2,center=true,$fn=30);
+ }//place idler
+ // filament path
+ rotate([0,0,45]) translate([(pulley_d-filament_path_d)/2,0,0]) {
+ rotate([90,0,0]) cylinder(d=filament_d,h=gearbox_d*2,center=true,$fn=15);
+ rotate([-90,0,0])
+ translate([0,0,mount_d/sqrt(2)/2+mount_screw_d])
+ pushfit_thread();
+ }
+ }//translate teeth
+ }//translate pulley
+ }//translate protrusion
+ }// vitamins to let
+
+ module lever() {
+ translate([0,0,protrusion_h+pulley_elevation+teeth_elevation]) {
+ difference() {
+ union() {
+ hull() {
+ place_idler()
+ cylinder(d=lsd,h=lever_thickness,center=true,$fn=60);
+ translate([mount_d/2,0,0])
+ cylinder(d=lsd,h=lever_thickness,center=true,$fn=60);
+ }//hull
+ hull() {
+ translate([mount_d/2,0,0])
+ cylinder(d=lsd,h=lever_thickness,center=true,$fn=60);
+ translate([mount_d/2,-longwing,0]) rotate([0,90,0])
+ cylinder(d=lever_thickness,h=lsd,center=true,$fn=60);
+ }//hull
+ }//union
+
+ // filament path
+ place_idler() translate([-(idler_d+filament_path_d)/2,0,0]) rotate([90,0,0]) {
+ cylinder(d=filament_path_d,h=3*gearbox_d,center=true,$fn=30);
+ translate([0,-filament_path_d/2/sqrt(2),0]) rotate([0,0,45])
+ cube(size=[filament_path_d/2,filament_path_d/2,3*gearbox_d],center=true);
+ }
+
+ // idler space and mounting hole
+ place_idler() {
+ difference() {
+ cylinder(d=idler_d+idler_clearance*2,h=idler_h+idler_v_tolerance,center=true,$fn=60);
+ // supports
+ for(y=[-lsd/2+extrusion_width:(lsd-2*extrusion_width)/3:lsd/2-extrusion_width])
+ translate([-lsd/2-1,y-extrusion_width/2,-idler_h/2-idler_v_tolerance/2-1])
+ cube(size=[lsd+2,extrusion_width,idler_h+idler_v_tolerance+2]);
+ }
+ cylinder(d=mount_screw_d+mount_screw_d_tolerance,h=lever_thickness+2,center=true,$fn=30);
+ translate([0,0,lever_thickness/2-mount_screwhead_h])
+ cylinder(d=mount_screwhead_d,h=mount_screwhead_h+1,$fn=2*PI*mount_screwhead_d);
+ }
+ // mounting screw hole
+ translate([mount_d/2,0,0])
+ cylinder(d=mount_screw_d+mount_screw_d_tolerance,h=lever_thickness+2,center=true,$fn=2*PI*mount_screw_d);
+
+ // lever end
+ translate([mount_d/2,0,0]) rotate([0,90,0]) {
+ translate([0,-longwing,lsd/2]) finger_indent(d=lever_thickness-1,r=15);
+ translate([0,-longwing,0])
+ mirror([0,0,1])
+ difference() {
+ cylinder(d=spring_d+spring_d_clearance,h=lsd,$fn=2*PI*spring_d);
+ sphere(d=spring_d*3/4,$fn=PI*spring_d);
+ }
+ }//rotate-translate
+ }//difference
+ // bridging patch
+ place_idler()
+ translate([0,0,lever_thickness/2-mount_screwhead_h])
+ mirror([0,0,1])
+ cylinder(d=mount_screwhead_d,h=layer_height);
+ }//translate
+ }//lever module
+
+ module body() {
+ filament_elevation=protrusion_h+pulley_elevation+teeth_elevation;
+ ls_z = filament_elevation;
+ body_h = max(protrusion_h+bore_l,mount_screw_l-mounthole_depth/2+mount_screwhead_h,ls_z*2);
+ ls_h = lever_thickness+lever_v_clearance;
+ difference() {
+ union() {
+ cylinder(d=gearbox_d,h=body_h,$fn=2*PI*gearbox_d);
+ // finger and spring support
+ fsw = gearbox_d/2+mount_screwhead_d/2;
+ translate([-gearbox_d/2,0,0]) difference() {
+ union() {
+ hull() {
+ translate([0,-longwing,ls_z])
+ rotate([0,90,0])
+ cylinder(d=lever_thickness,h=fsw,$fn=2*PI*lever_thickness);
+ hh=body_h-ls_z;
+ translate([0,0,ls_z-lever_thickness/2])
+ mirror([0,1,0]) cube(size=[fsw,longwing-hh+lever_thickness/sqrt(2),hh+lever_thickness/2]);
+ hhh=ls_z;
+ translate([0,0,0])
+ mirror([0,1,0]) cube(size=[fsw,longwing-hhh+lever_thickness/sqrt(2),hhh+lever_thickness/2]);
+ }
+ }
+ translate([0,-longwing,ls_z]) rotate([0,-90,0])
+ finger_indent(d=lever_thickness-1,r=15);
+ } // translate
+
+ // pushfit bracket
+ translate([0,0,filament_elevation])
+ rotate([0,0,45]) translate([pulley_d/2,0,0])
+ rotate([-90,0,0])
+ translate([0,0,mount_d/sqrt(2)/2+mount_screw_d-gearbox_d/2/*TODO:*/])
+ cylinder(r=min(body_h-filament_elevation,filament_elevation)/sin(60)-epsilon,h=10+gearbox_d/2/*TODO:*/,$fn=6);
+ }//union (first child of difference)
+ // protrusion
+ translate([0,0,-1])
+ cylinder(d=protrusion_d+protrusion_tolerance_h,h=protrusion_h+protrusion_tolerance_v+1,$fn=2*PI*protrusion_d);
+ // mount screw holes
+ for(zr=[0:90:359]) rotate([0,0,zr]) translate([mount_d/2,0,0]) {
+ translate([0,0,mount_screw_l-mounthole_depth/2-layer_height-1])
+ mirror([0,0,1])
+ cylinder(d=mount_screw_d+mount_screw_d_tolerance,
+ h=mount_screw_l-mounthole_depth/2-layer_height+1,
+ $fn=2*PI*mount_screw_d);
+ translate([0,0,mount_screw_l-mounthole_depth/2])
+ cylinder(d=mount_screwhead_d,h=body_h+1,$fn=2*PI*mount_screwhead_d);
+ }//for
+ // pushfit threads
+ translate([0,0,filament_elevation])
+ rotate([0,0,45]) translate([pulley_d/2,0,0])
+ rotate([-90,0,0])
+ translate([0,0,mount_d/sqrt(2)/2+mount_screw_d+epsilon])
+ rotate([0,0,180]) {
+ pushfit_thread(h=10);
+ cylinder(d=filament_guide_d,h=gearbox_d,center=true,$fn=2*PI*filament_guide_d);
+ translate([0,-filament_guide_d/2/sqrt(2),0])
+ rotate([0,0,45])
+ cube(size=[filament_guide_d/2,filament_guide_d/2,gearbox_d],center=true);
+ }
+ // pulley
+ cylinder(d=pulley_d+pulley_clearance,h=body_h+1,$fn=2*PI*(pulley_d+pulley_clearance));
+ // leverspace
+ hull() for(x=[0,gearbox_d])
+ rotate([0,0,45])
+ translate([x,0,ls_z-ls_h/2])
+ cylinder(d=idler_d+idler_clearance,h=ls_h,$fn=2*PI*idler_d);
+
+ a=cos(45)*(pulley_d+idler_d)/2;
+ b=mount_d/2-a;
+ x=sqrt(pow(a,2)+pow(b,2));
+ translate([mount_d/2,0,ls_z])
+ intersection() {
+ r = x+idler_d/2+1;/* TODO: */
+ cylinder(r=r,h=ls_h,center=true);
+ translate([-r-1,0,-1]) cube(size=[2*r+2,r+1,ls_h+2]);
+ }
+
+ rotate([0,0,-45])
+ translate([0,0,ls_z-ls_h/2])
+ cube(size=[gearbox_d,gearbox_d,lever_thickness+lever_v_clearance]);
+ translate([0,0,ls_z-ls_h/2]) {
+ translate([mount_screwhead_d/2,0,0])
+ mirror([0,1,0])
+ cube(size=[gearbox_d,gearbox_d/2+1,lever_thickness+lever_v_clearance]);
+ }
+ //translate([-mount_d/2,-longwing,filament_elevation])
+ translate([mount_d/2,-longwing,filament_elevation])
+ rotate([0,-90,0]) difference() {
+ cylinder(d=spring_d+spring_d_clearance,h=spring_lc+spring_dl,$fn=PI*spring_d);
+ translate([0,0,spring_lc+spring_dl]) sphere(d=spring_d*3/4,$fn=PI*spring_d);
+ }
+ //sphere(d=spring_d*3/4,$fn=PI*spring_d);
+ *difference() {
+ // spring support
+ translate([0,-longwing,filament_elevation])
+ sphere(d=spring_d*3/4,$fn=PI*spring_d);
+ }
+
+ }//difference
+
+ intersection() {
+ difference() {
+ translate([0,0,ls_z-ls_h/2-epsilon])
+ cylinder(d=gearbox_d,h=ls_h+2*epsilon,$fn=2*PI*gearbox_d);
+ cylinder(d=pulley_d+pulley_clearance,h=body_h+1,$fn=2*PI*(pulley_d+pulley_clearance));
+ }
+ // supports
+ // TODO: hardcoded stuff below…
+ if(false) { // parallel
+ for(y=[-gearbox_d:4:gearbox_d])
+ translate([0,y-extrusion_width/2,0])
+ cube(size=[gearbox_d,extrusion_width,body_h]);
+ }else{ // radial
+ for(zr=[-65:(65+50)/7:50])
+ rotate([0,0,zr]) translate([0,-extrusion_width/2,0])
+ cube(size=[gearbox_d,extrusion_width,body_h]);
+ }
+ }
+
+ }//body module
+
+ mirrorleft()
+ if(what=="lever") color("green",0.7) lever();
+ else if(what=="body") color("yellow",0.7) body();
+ else if(what=="both") {
+ color("green",0.7) lever();
+ color("yellow",0.7) body();
+ }
+}
+
+the_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 @@
+/*
+ * ISO-standard metric threads, following this specification:
+ * http://en.wikipedia.org/wiki/ISO_metric_screw_thread
+ *
+ * Dan Kirshner - dan_kirshner@yahoo.com
+ *
+ * You are welcome to make free use of this software. Retention of my
+ * authorship credit would be appreciated.
+ *
+ * Version 1.9. 2016-07-03 Option: tapered.
+ * Version 1.8. 2016-01-08 Option: (non-standard) angle.
+ * Version 1.7. 2015-11-28 Larger x-increment - for small-diameters.
+ * Version 1.6. 2015-09-01 Options: square threads, rectangular threads.
+ * Version 1.5. 2015-06-12 Options: thread_size, groove.
+ * Version 1.4. 2014-10-17 Use "faces" instead of "triangles" for polyhedron
+ * 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.
+//
+// Standard M8 x 1.
+// metric_thread (diameter=8, pitch=1, length=4);
+
+// Square thread.
+// metric_thread (diameter=8, pitch=1, length=4, square=true);
+
+// Non-standard: long pitch, same thread size.
+//metric_thread (diameter=8, pitch=4, length=4, thread_size=1, groove=true);
+
+// Non-standard: 20 mm diameter, long pitch, square "trough" width 3 mm,
+// depth 1 mm.
+//metric_thread (diameter=20, pitch=8, length=16, square=true, thread_size=6,
+// groove=true, rectangle=0.333);
+
+// English: 1/4 x 20.
+//english_thread (diameter=1/4, threads_per_inch=20, length=1);
+
+// Tapered. Example -- pipe size 3/4" -- per:
+// http://www.engineeringtoolbox.com/npt-national-pipe-taper-threads-d_750.html
+// english_thread (diameter=1.05, threads_per_inch=14, length=3/4, taper=1/16);
+
+// Thread for mounting on Rohloff hub.
+//difference () {
+// cylinder (r=20, h=10, $fn=100);
+//
+// metric_thread (diameter=34, pitch=1, length=10, internal=true, n_starts=6);
+//}
+
+
+// ----------------------------------------------------------------------------
+function segments (diameter) = min (50, ceil (diameter*6));
+
+
+// ----------------------------------------------------------------------------
+// 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.
+// thread_size - (non-standard) size of a single thread "V" - independent of
+// pitch. Default: same as pitch.
+// groove - (non-standard) subtract inverted "V" from cylinder (rather than
+// add protruding "V" to cylinder).
+// square - Square threads (per
+// https://en.wikipedia.org/wiki/Square_thread_form).
+// rectangle - (non-standard) "Rectangular" thread - ratio depth/width
+// Default: 1 (square).
+// angle - (non-standard) angle (deg) of thread side from perpendicular to
+// axis (default = standard = 30 degrees).
+// taper - diameter change per length (National Pipe Thread/ANSI B1.20.1
+// is 1" diameter per 16" length).
+module metric_thread (diameter=8, pitch=1, length=1, internal=false, n_starts=1,
+ thread_size=-1, groove=false, square=false, rectangle=0,
+ angle=30, taper=0)
+{
+ // thread_size: size of thread "V" different than travel per turn (pitch).
+ // Default: same as pitch.
+ local_thread_size = thread_size == -1 ? pitch : thread_size;
+ local_rectangle = rectangle ? rectangle : 1;
+
+ n_segments = segments (diameter);
+ h = (square || rectangle) ? local_thread_size*local_rectangle/2 : local_thread_size * cos (angle);
+
+ h_fac1 = (square || rectangle) ? 0.90 : 0.625;
+
+ // External thread includes additional relief.
+ h_fac2 = (square || rectangle) ? 0.95 : 5.3/8;
+
+ if (! groove) {
+ metric_thread_turns (diameter, pitch, length, internal, n_starts,
+ local_thread_size, groove, square, rectangle, angle,
+ taper);
+ }
+
+ difference () {
+
+ // Solid center, including Dmin truncation.
+ tapered_diameter = diameter - length*taper;
+ if (groove) {
+ cylinder (r1=diameter/2, r2=tapered_diameter/2,
+ h=length, $fn=n_segments);
+ } else if (internal) {
+ cylinder (r1=diameter/2 - h*h_fac1, r2=tapered_diameter/2 - h*h_fac1,
+ h=length, $fn=n_segments);
+ } else {
+
+ // External thread.
+ cylinder (r1=diameter/2 - h*h_fac2, r2=tapered_diameter/2 - h*h_fac2,
+ h=length, $fn=n_segments);
+ }
+
+ if (groove) {
+ metric_thread_turns (diameter, pitch, length, internal, n_starts,
+ local_thread_size, groove, square, rectangle,
+ angle, taper);
+ }
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+// 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, thread_size=-1, groove=false,
+ square=false, rectangle=0, angle=30, taper=0)
+{
+ // 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,
+ thread_size, groove, square, rectangle, angle, taper);
+}
+
+// ----------------------------------------------------------------------------
+module metric_thread_turns (diameter, pitch, length, internal, n_starts,
+ thread_size, groove, square, rectangle, angle,
+ taper)
+{
+ // Number of turns needed.
+ n_turns = floor (length/pitch);
+
+ intersection () {
+
+ // Start one below z = 0. Gives an extra turn at each end.
+ for (i=[-1*n_starts : n_turns+1]) {
+ translate ([0, 0, i*pitch]) {
+ metric_thread_turn (diameter, pitch, internal, n_starts,
+ thread_size, groove, square, rectangle, angle,
+ taper, i*pitch);
+ }
+ }
+
+ // Cut to length.
+ translate ([0, 0, length/2]) {
+ cube ([diameter*3, diameter*3, length], center=true);
+ }
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+module metric_thread_turn (diameter, pitch, internal, n_starts, thread_size,
+ groove, square, rectangle, angle, taper, z)
+{
+ n_segments = segments (diameter);
+ fraction_circle = 1.0/n_segments;
+ for (i=[0 : n_segments-1]) {
+ rotate ([0, 0, i*360*fraction_circle]) {
+ translate ([0, 0, i*n_starts*pitch*fraction_circle]) {
+ current_diameter = diameter - taper*(z + i*n_starts*pitch*fraction_circle);
+ thread_polyhedron (current_diameter/2, pitch, internal, n_starts,
+ thread_size, groove, square, rectangle, angle);
+ }
+ }
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+// z (see diagram) as function of current radius.
+// (Only good for first half-pitch.)
+function z_fct (current_radius, radius, pitch, angle)
+ = 0.5* (current_radius - (radius - 0.875*pitch*cos (angle)))
+ /cos (angle);
+
+// ----------------------------------------------------------------------------
+module thread_polyhedron (radius, pitch, internal, n_starts, thread_size,
+ groove, square, rectangle, angle)
+{
+ n_segments = segments (radius*2);
+ fraction_circle = 1.0/n_segments;
+
+ local_rectangle = rectangle ? rectangle : 1;
+
+ h = (square || rectangle) ? thread_size*local_rectangle/2 : thread_size * cos (angle);
+ outer_r = radius + (internal ? h/20 : 0); // Adds internal relief.
+ //echo (str ("outer_r: ", outer_r));
+
+ // A little extra on square thread -- make sure overlaps cylinder.
+ h_fac1 = (square || rectangle) ? 1.1 : 0.875;
+ inner_r = radius - h*h_fac1; // Does NOT do Dmin_truncation - do later with
+ // cylinder.
+
+ translate_y = groove ? outer_r + inner_r : 0;
+ reflect_x = groove ? 1 : 0;
+
+ // Make these just slightly bigger (keep in proportion) so polyhedra will
+ // overlap.
+ x_incr_outer = (! groove ? outer_r : inner_r) * fraction_circle * 2 * PI * 1.02;
+ x_incr_inner = (! groove ? inner_r : outer_r) * fraction_circle * 2 * PI * 1.02;
+ z_incr = n_starts * pitch * fraction_circle * 1.005;
+
+ /*
+ (angles x0 and x3 inner are actually 60 deg)
+
+ /\ (x2_inner, z2_inner) [2]
+ / \
+ (x3_inner, z3_inner) / \
+ [3] \ \
+ |\ \ (x2_outer, z2_outer) [6]
+ | \ /
+ | \ /|
+ z |[7]\/ / (x1_outer, z1_outer) [5]
+ | | | /
+ | x | |/
+ | / | / (x0_outer, z0_outer) [4]
+ | / | / (behind: (x1_inner, z1_inner) [1]
+ |/ | /
+ y________| |/
+ (r) / (x0_inner, z0_inner) [0]
+
+ */
+
+ x1_outer = outer_r * fraction_circle * 2 * PI;
+
+ z0_outer = z_fct (outer_r, radius, thread_size, angle);
+ //echo (str ("z0_outer: ", z0_outer));
+
+ //polygon ([[inner_r, 0], [outer_r, z0_outer],
+ // [outer_r, 0.5*pitch], [inner_r, 0.5*pitch]]);
+ z1_outer = z0_outer + z_incr;
+
+ // Give internal square threads some clearance in the z direction, too.
+ bottom = internal ? 0.235 : 0.25;
+ top = internal ? 0.765 : 0.75;
+
+ translate ([0, translate_y, 0]) {
+ mirror ([reflect_x, 0, 0]) {
+
+ if (square || rectangle) {
+
+ // Rule for face ordering: look at polyhedron from outside: points must
+ // be in clockwise order.
+ polyhedron (
+ points = [
+ [-x_incr_inner/2, -inner_r, bottom*thread_size], // [0]
+ [x_incr_inner/2, -inner_r, bottom*thread_size + z_incr], // [1]
+ [x_incr_inner/2, -inner_r, top*thread_size + z_incr], // [2]
+ [-x_incr_inner/2, -inner_r, top*thread_size], // [3]
+
+ [-x_incr_outer/2, -outer_r, bottom*thread_size], // [4]
+ [x_incr_outer/2, -outer_r, bottom*thread_size + z_incr], // [5]
+ [x_incr_outer/2, -outer_r, top*thread_size + z_incr], // [6]
+ [-x_incr_outer/2, -outer_r, top*thread_size] // [7]
+ ],
+
+ faces = [
+ [0, 3, 7, 4], // This-side trapezoid
+
+ [1, 5, 6, 2], // Back-side trapezoid
+
+ [0, 1, 2, 3], // Inner rectangle
+
+ [4, 7, 6, 5], // Outer rectangle
+
+ // These are not planar, so do with separate triangles.
+ [7, 2, 6], // Upper rectangle, bottom
+ [7, 3, 2], // Upper rectangle, top
+
+ [0, 5, 1], // Lower rectangle, bottom
+ [0, 4, 5] // Lower rectangle, top
+ ]
+ );
+ } else {
+
+ // Rule for face ordering: look at polyhedron from outside: points must
+ // be in clockwise order.
+ polyhedron (
+ points = [
+ [-x_incr_inner/2, -inner_r, 0], // [0]
+ [x_incr_inner/2, -inner_r, z_incr], // [1]
+ [x_incr_inner/2, -inner_r, thread_size + z_incr], // [2]
+ [-x_incr_inner/2, -inner_r, thread_size], // [3]
+
+ [-x_incr_outer/2, -outer_r, z0_outer], // [4]
+ [x_incr_outer/2, -outer_r, z0_outer + z_incr], // [5]
+ [x_incr_outer/2, -outer_r, thread_size - z0_outer + z_incr], // [6]
+ [-x_incr_outer/2, -outer_r, thread_size - z0_outer] // [7]
+ ],
+
+ faces = [
+ [0, 3, 7, 4], // This-side trapezoid
+
+ [1, 5, 6, 2], // Back-side trapezoid
+
+ [0, 1, 2, 3], // Inner rectangle
+
+ [4, 7, 6, 5], // Outer rectangle
+
+ // These are not planar, so do with separate triangles.
+ [7, 2, 6], // Upper rectangle, bottom
+ [7, 3, 2], // Upper rectangle, top
+
+ [0, 5, 1], // Lower rectangle, bottom
+ [0, 4, 5] // Lower rectangle, top
+ ]
+ );
+ }
+ }
+ }
+}
+
+