From 9f82c5746a794129d1ef1f235f6f9de60009e3c3 Mon Sep 17 00:00:00 2001
From: Adrian Mariano <avm4@cornell.edu>
Date: Wed, 2 Aug 2023 22:06:24 -0400
Subject: [PATCH] doc tweaks

---
 gears.scad | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/gears.scad b/gears.scad
index 2b2d004..c0b4b0f 100644
--- a/gears.scad
+++ b/gears.scad
@@ -3181,7 +3181,7 @@ function _working_pressure_angle(teeth1,profile_shift1, teeth2, profile_shift2,
   )
   assert(rhs>0, "Total profile shift is too small, so working pressure angle is negative, and no valid gear separation exists")
   let(
-      pa_eff = root_find(function (x) _invol(x)-rhs, -40, 75)
+      pa_eff = root_find(function (x) _invol(x)-rhs, 1, 75)
   )
   pa_eff;
 
@@ -3311,9 +3311,9 @@ function gear_skew_angle(teeth1,teeth2,helical1,helical2,profile_shift1,profile_
 //   mod=4;
 //   desired=115;
 //   pshift = get_profile_shift(desired,teeth1,teeth2,mod=mod);  // Returns 0.82
-//   shorten = pshift - (desired-112)/mod;     // Returns 0.07
 //   ps1 = pshift/2;
 //   ps2 = pshift/2;
+//   shorten=gear_shorten(teeth1,teeth2,0,ps1,ps2);       // Returns 0.07
 //   d = gear_dist(mod=mod, teeth1,teeth2,0,ps1,ps2);
 //   spur_gear2d(mod=mod,teeth=teeth1,profile_shift=ps1,shorten=shorten,gear_spin=-90,shaft_diam=5);
 //   right(d)
@@ -3325,9 +3325,9 @@ function gear_skew_angle(teeth1,teeth2,helical1,helical2,profile_shift1,profile_
 //   mod=4;
 //   desired=110;
 //   pshift = get_profile_shift(desired,teeth1,teeth2,mod=mod);  // Returns -0.46
-//   shorten = pshift - (desired-112)/mod;     // Returns 0.04
 //   ps1 = 0.8*pshift;
 //   ps2 = 0.2*pshift;
+//   shorten=gear_shorten(teeth1,teeth2,0,ps1,ps2);  // Returns 0.04
 //   d = gear_dist(mod=mod, teeth1,teeth2,0,ps1,ps2);
 //   spur_gear2d(mod=mod,teeth=teeth1,profile_shift=ps1,shorten=shorten,gear_spin=-90,shaft_diam=5);
 //   right(d)
@@ -3409,7 +3409,7 @@ function auto_profile_shift(teeth, pressure_angle=20, helical=0, min_teeth, prof
 //     spur_gear2d(mod=mod,teeth=teeth1,profile_shift=ps1,gear_spin=-90);
 //   right(d)
 //     spur_gear2d(mod=mod,teeth=teeth2,profile_shift=ps2,gear_spin=-90);
-// Example(2D,Med,VPT=[53.9088,1.83058,26.0319],VPR=[0,0,0],VPD=140): Applying the correct shortening factor restores the clearance to its normal value.  
+// Example(2D,Med,VPT=[53.9088,1.83058,26.0319],VPR=[0,0,0],VPD=140,NoAxes): Applying the correct shortening factor restores the clearance to its normal value.  
 //   teeth1=25;
 //   teeth2=19;
 //   mod=4;
@@ -3422,7 +3422,10 @@ function auto_profile_shift(teeth, pressure_angle=20, helical=0, min_teeth, prof
 //   right(d)
 //     spur_gear2d(mod=mod,teeth=teeth2,profile_shift=ps2,shorten=shorten,gear_spin=-90);
 function gear_shorten(teeth1,teeth2,helical=0,profile_shift1="auto",profile_shift2="auto",pressure_angle=20) =
-    let(
+    teeth1==0 || teeth2==0 ? 0
+  : let(
+         profile_shift1 = auto_profile_shift(teeth1,pressure_angle,helical,profile_shift=profile_shift1),
+         profile_shift2 = auto_profile_shift(teeth2,pressure_angle,helical,profile_shift=profile_shift2),
          ax = gear_dist(mod=1,teeth1,teeth2,helical,profile_shift1,profile_shift2,pressure_angle=pressure_angle),
          y = ax - (teeth1+teeth2)/2/cos(helical)
     )
@@ -3445,10 +3448,12 @@ function gear_shorten(teeth1,teeth2,helical=0,profile_shift1="auto",profile_shif
 //   helical1 = The helical angle (from vertical) of the teeth on the second gear.
 //   profile_shift1 = Profile shift factor x for the first gear.  Default: "auto"
 //   profile_shift2 = Profile shift factor x for the second gear.  Default: "auto"
-//   --
+//   ---
 //   pressure_angle = The pressure angle of the gear.
 function gear_shorten_skew(teeth1,teeth2,helical1,helical2,profile_shift1="auto",profile_shift2="auto",pressure_angle=20) =
     let(
+         profile_shift1 = auto_profile_shift(teeth1,pressure_angle,helical1,profile_shift=profile_shift1),
+         profile_shift2 = auto_profile_shift(teeth2,pressure_angle,helical2,profile_shift=profile_shift2),
          ax = gear_dist(mod=1,teeth1,teeth2,helical,profile_shift1,profile_shift2,pressure_angle=pressure_angle),
          y = ax - (teeth1+teeth2)/2/cos(helical)
     )