Algorithm Search⌘K

Techniqueadvanced

Gear tooth generation by enveloping

Also called Litvin theory of gearing, generating method for gear teeth, equation of meshing.

Computes a tooth surface as the envelope of a rack or hob cutter in relative motion by the equation of meshing, the basis of Litvin's theory of gearing.

Gear tooth generation by enveloping finds the shape that a cutting tool leaves on a gear blank. The tool, a rack cutter (a straight bar of teeth), a pinion cutter or a hob (a cutter in the form of a worm), moves relative to the blank in a fixed generating motion. The cut tooth is the envelope of the tool positions: the curve that touches every position of the tool edge. The points of the envelope are the solutions of one scalar equation, the equation of meshing n⋅v=0\mathbf n \cdot \mathbf v = 0, which says that the tool point slides along the tool edge relative to the gear and does not cross it.

This page works in the plane, which is the transverse section of a spur gear. The gear frame turns with the gear blank, and ψ\psi is the angle of the blank. A tool point rc(u)\mathbf r_c(u) with unit normal nc(u)\mathbf n_c(u) in the tool frame is at F(u,ψ)=R(a(ψ)) rc(u)+t(ψ)F(u, \psi) = R(a(\psi))\,\mathbf r_c(u) + \mathbf t(\psi) in the gear frame, where R(a)R(a) turns a vector by the angle aa and J=R(90°)J = R(90°). The equation of meshing is

f(u,ψ)=(R(a) nc(u))⋅(a′(ψ) JR(a) rc(u)+t′(ψ))=0,f(u, \psi) = \big(R(a)\,\mathbf n_c(u)\big) \cdot \big(a'(\psi)\,J R(a)\,\mathbf r_c(u) + \mathbf t'(\psi)\big) = 0,

where the second factor is FψF_\psi, the velocity of the tool point relative to the gear per unit turn of the gear.

In plain words

Think of a gear blank as soft clay, and push a hard rack tooth through it while you turn the clay. At each moment the rack tooth scrapes away the clay that it covers. When the motion is over, the edge that is left is the tooth of the gear. Each point of that edge was touched by the rack at one moment, and at that moment the rack slid along the edge without biting into it.

The method turns this picture into an equation. For each point on the edge of the tool, you ask at which moment it moves only along its own edge, as seen from the clay. At that moment the point is on the finished tooth. A straight rack edge that rolls on a circle gives the involute, so one straight tool cuts gears with any number of teeth.

When it applies

  • The gear is cut by a generating process: a rack cutter (gear planing), a pinion cutter (gear shaping) or a hob (gear hobbing). In each one the tool and the blank turn and slide together as if they were a pair of gears in mesh. Form cutting, where a milling cutter has the shape of the tooth space, is not a generating process, and the tooth is a copy of the cutter.
  • The tool edge is a smooth curve with a known normal, and the motion is smooth in ψ\psi. A corner of the tool, such as the tip of a rack tooth, is a separate tool curve and has its own envelope.
  • You want the tooth as a curve, with exact points, normals and the parameter of the tool point that made each point. If only an approximate shape is needed, a simulated cut that subtracts many tool positions from the blank also works, as a swept volume, but it gives no equation and its error falls only as the square of the step.
  • In space the same equation holds for a tool surface rc(u,θ)\mathbf r_c(u, \theta), with one more parameter. This is how helical, bevel and worm gears are computed. This page treats the plane.

The template

The holes are the tool curve, the generating motion, the root solver and the branch check. The block below takes a list UU of tool parameters and a window [ψlo,ψhi][\psi_{lo}, \psi_{hi}] of turns of the blank, and returns the points of the cut tooth.

  1. ENVELOPE(r_c, n_c, a, t, U, ψ_lo, ψ_hi, K, KEEP)
  2. 1for each u in U ▷ hole 1: the tool r_c(u), n_c(u)
  3. 2f(ψ) ← (R(a(ψ)) n_c(u)) · (a′(ψ) J R(a(ψ)) r_c(u) + t′(ψ)) ▷ hole 2: the motion a, t
  4. 3for each of the K cells of [ψ_lo, ψ_hi] where f changes sign
  5. 4ψ* ← the root of f in the cell, by bisection ▷ hole 3: the root solver
  6. 5p ← R(a(ψ*)) r_c(u) + t(ψ*)
  7. 6if KEEP(u, ψ*, p) then output (u, ψ*, p) ▷ hole 4: the branch check

Hole 1, the tool. A rack cutter flank through the pitch point of the rack, at the pressure angle φ\varphi to the normal of the pitch line, is

rc(u)=u(sin⁡φ,cos⁡φ),nc=(cos⁡φ,−sin⁡φ).\mathbf r_c(u) = u(\sin\varphi, \cos\varphi), \qquad \mathbf n_c = (\cos\varphi, -\sin\varphi).

Here the pitch line of the rack is the xx axis of the rack frame, and ucos⁡φu \cos\varphi is the height of the point above it. The straight flank reaches the height −km-km toward the blank, where mm is the module and k=1k = 1 for full depth teeth. The tip of the cutter, which goes 0.25m0.25m deeper, is a separate curve and cuts the root fillet. A pinion cutter of pitch radius rcr_c has an involute flank with the base radius rccos⁡φr_c\cos\varphi, placed so that it has the same point and normal as the rack flank at the pitch point.

Hole 2, the motion. Put the center of the blank at the origin of the fixed frame. A blank with zz teeth has the pitch radius r=mz/2r = mz/2. For a rack, the pitch line of the rack is the line y=ry = r, tangent to the pitch circle at the pitch point P=(0,r)P = (0, r), and it rolls on the pitch circle without slip. So when the blank turns by ψ\psi, the rack moves by −rψ-r\psi along xx. Carried into the gear frame, which turns by −ψ-\psi relative to the fixed frame,

a(ψ)=−ψ,t(ψ)=R(−ψ) (−rψ, r).a(\psi) = -\psi, \qquad \mathbf t(\psi) = R(-\psi)\,(-r\psi,\ r).

For a pinion cutter with center (0,r+rc)(0, r + r_c), the pitch circles roll on each other, so the cutter turns by −(r/rc)ψ-(r/r_c)\psi, and a(ψ)=−(1+r/rc)ψa(\psi) = -(1 + r/r_c)\psi and t(ψ)=R(−ψ)(0,r+rc)\mathbf t(\psi) = R(-\psi)(0, r + r_c).

Hole 3, the root solver. For each uu, line L3 samples ff on KK cells and line L4 halves each cell with a sign change until it is shorter than the tolerance, as in the bisection method. Newton's method needs fewer steps when a good start is known, for example the root at the last uu. For a rack the root has a closed form, derived below.

Hole 4, the branch check. Every root is a point of the envelope, but not every point of the envelope is on the cut tooth. The tool may remove the point at some other position. The check in line L6 tests the point against the tool at the other positions near ψ∗\psi^*: for the rack, it computes the smallest signed distance from pp to the tooth of the rack, which is the region behind the flank and above the tip line, over a range of turns. A negative value means that the rack covers pp at some turn, so pp is cut away.

Why the roots are the points of the envelope

Write FuF_u and FψF_\psi for the partial derivatives of F(u,ψ)F(u, \psi). The vector Fu=R(a) rc′(u)F_u = R(a)\,\mathbf r_c'(u) is tangent to the tool edge at its position ψ\psi, and n=R(a) nc(u)\mathbf n = R(a)\,\mathbf n_c(u) is normal to it, so n⋅Fu=0\mathbf n \cdot F_u = 0 and f=n⋅Fψf = \mathbf n \cdot F_\psi.

  1. Every point of an envelope solves the equation. Let Γ(ψ)=F(u(ψ),ψ)\Gamma(\psi) = F(u(\psi), \psi) be a curve that touches the tool edge at its position ψ\psi for every ψ\psi in an interval, with u(ψ)u(\psi) differentiable. Then Γ′=Fuu′+Fψ\Gamma' = F_u u' + F_\psi. Since Γ\Gamma touches the tool edge there, Γ′\Gamma' is parallel to FuF_u, so n⋅Γ′=0\mathbf n \cdot \Gamma' = 0. This gives 0=(n⋅Fu) u′+n⋅Fψ=f(u(ψ),ψ)0 = (\mathbf n \cdot F_u)\,u' + \mathbf n \cdot F_\psi = f(u(\psi), \psi).
  2. Every regular branch of solutions is an envelope. Let f(u0,ψ0)=0f(u_0, \psi_0) = 0 with fu(u0,ψ0)≠0f_u(u_0, \psi_0) \ne 0. By the implicit function theorem there is a differentiable u(ψ)u(\psi) near ψ0\psi_0 with f(u(ψ),ψ)=0f(u(\psi), \psi) = 0. Put Γ(ψ)=F(u(ψ),ψ)\Gamma(\psi) = F(u(\psi), \psi). Then n⋅Γ′=(n⋅Fu) u′+f=0\mathbf n \cdot \Gamma' = (\mathbf n \cdot F_u)\,u' + f = 0, so Γ′\Gamma' is parallel to the tool edge, and Γ\Gamma touches the tool at each of its points where Γ′≠0\Gamma' \ne 0.
  3. The equation is the fundamental law of gearing. The motion of the tool relative to the gear is, at each instant with a′≠0a' \ne 0, a turn about the instant center II of the two frames, so Fψ=a′ J(p−I)F_\psi = a'\,J(p - I) and f=a′ n⋅J(p−I)f = a'\,\mathbf n \cdot J(p - I). This is zero exactly when p−Ip - I is parallel to n\mathbf n: the normal of the tool at the contact point passes through II. When the pitch curves of the tool and the blank roll without slip, II is their point of contact, the pitch point, by the theory of the instant center of velocity. So the cut gear and the tool satisfy the fundamental law of gearing: they are conjugate, and the gear meshes with any gear that the same tool would cut. ■\blacksquare

At a point where Γ′=0\Gamma' = 0 the envelope has a cusp. Litvin and Fuentes (Chapter 6) treat these singular points of the generated curve, and in gear cutting they mark the start of undercutting.

Why a rack cuts an involute

Take the rack of holes 1 and 2. In the fixed frame the flank at the turn ψ\psi is the line through (−rψ,r)+u(sin⁡φ,cos⁡φ)(-r\psi, r) + u(\sin\varphi, \cos\varphi) with the normal (cos⁡φ,−sin⁡φ)(\cos\varphi, -\sin\varphi). By step 3 the contact point CC is where the normal passes through P=(0,r)P = (0, r). The normal line through the flank point meets the line y=ry = r at x=−rψ+u/sin⁡φx = -r\psi + u/\sin\varphi, so

ψ∗=ursin⁡φ,C=P+ucos⁡φsin⁡φ (−cos⁡φ, sin⁡φ).\psi^* = \frac{u}{r\sin\varphi}, \qquad C = P + \frac{u\cos\varphi}{\sin\varphi}\,(-\cos\varphi,\ \sin\varphi).

So all contacts lie on one fixed line ℓ\ell through PP in the direction (−cos⁡φ,sin⁡φ)(-\cos\varphi, \sin\varphi), which is the line of action. The distance from the center OO to ℓ\ell is rcos⁡φ=rbr\cos\varphi = r_b, so ℓ\ell touches the base circle of radius rbr_b at the point T=rb(sin⁡φ,cos⁡φ)T = r_b(\sin\varphi, \cos\varphi), at the distance rsin⁡φr\sin\varphi from PP. Measured from TT, the contact is at

∣TC∣=rsin⁡φ+ucos⁡φsin⁡φ=rsin⁡φ+ψ∗rcos⁡φ=rb(tan⁡φ+ψ∗).|TC| = r\sin\varphi + \frac{u\cos\varphi}{\sin\varphi} = r\sin\varphi + \psi^* r\cos\varphi = r_b(\tan\varphi + \psi^*).

Now look from the gear frame, which has turned by −ψ∗-\psi^*. There ℓ\ell is still tangent to the base circle, at the point R(−ψ∗)TR(-\psi^*)T with polar angle π2−φ−ψ∗\tfrac{\pi}{2} - \varphi - \psi^*, and CC is at the distance rb(tan⁡φ+ψ∗)r_b(\tan\varphi + \psi^*) from it along the tangent. This is the end of a taut string that is wound on the base circle and unwound from the polar angle θ0=π2−φ+tan⁡φ=π2+inv⁡φ\theta_0 = \tfrac{\pi}{2} - \varphi + \tan\varphi = \tfrac{\pi}{2} + \operatorname{inv}\varphi, since the free length equals rbr_b times the angle unwound. So CC traces the involute of the base circle with the roll angle t=tan⁡φ+ψ∗t = \tan\varphi + \psi^*, and in polar form θ+inv⁡α=θ0\theta + \operatorname{inv}\alpha = \theta_0 with cos⁡α=rb/ρ\cos\alpha = r_b/\rho, as on the page on the involute gear tooth. The base radius rcos⁡φr\cos\varphi depends only on the pitch radius and the angle of the rack, so one rack cuts correct involute gears of every size. ■\blacksquare

The argument needs ∣TC∣≥0|TC| \ge 0, that is ψ∗≥−tan⁡φ\psi^* \ge -\tan\varphi, or a flank height ucos⁡φ≥−rsin⁡2φu\cos\varphi \ge -r\sin^2\varphi. A lower point of the flank makes a contact past TT, on the other branch of the envelope behind the cusp at the base circle, and hole 4 finds that the rack cuts into the involute there. The rack tip at the height −km-km stays above this limit if and only if km≤rsin⁡2φkm \le r\sin^2\varphi, which is the bound z≥2k/sin⁡2φz \ge 2k/\sin^2\varphi of gear undercutting.

Cost

One evaluation of ff is a fixed number of operations. For each uu, lines L3 and L4 take KK evaluations for the scan and log⁡2 ⁣((ψhi−ψlo)/(Kε))\log_2\!\big((\psi_{hi} - \psi_{lo})/(K\varepsilon)\big) for each root at the tolerance ε\varepsilon, so ∣U∣|U| points cost O(∣U∣(K+log⁡(1/ε)))O\big(|U|(K + \log(1/\varepsilon))\big) evaluations, plus the branch checks. With the closed form for the rack, each point costs O(1)O(1). A simulated cut with MM positions of the tool costs O(∣U∣M)O(|U|M) and has an error of order (Δψ)2(\Delta\psi)^2 in the normal direction.

Classic examples

A rack cutting a 20 tooth gear. Take m=4m = 4 mm, z=20z = 20 and φ=20°\varphi = 20°, so r=40r = 40 mm, rb=37.588r_b = 37.588 mm and θ0=90.854°\theta_0 = 90.854°. The table gives five points of one flank, by the height h=ucos⁡φh = u\cos\varphi of the rack point above the pitch line.

hh (mm) ψ∗\psi^* (rad) roll tt ρ\rho (mm) θ\theta
−4-4 −0.311145-0.311145 0.0528250.052825 37.64037.640 90.851°90.851°
−2-2 −0.155572-0.155572 0.2083980.208398 38.39538.395 90.685°90.685°
00 00 0.3639700.363970 40.00040.000 90.000°90.000°
22 0.1555720.155572 0.5195430.519543 42.35842.358 88.540°88.540°
44 0.3111450.311145 0.6751150.675115 45.35245.352 86.197°86.197°

Each point has θ+inv⁡α=90.854°=θ0\theta + \operatorname{inv}\alpha = 90.854° = \theta_0, so they lie on one involute. The rack tip at h=−4h = -4 mm cuts the lowest flank point at ρ=37.640\rho = 37.640 mm, just 0.0520.052 mm above the base circle, and the limit height rsin⁡2φ=4.679r\sin^2\varphi = 4.679 mm is above km=4km = 4 mm, so there is no undercut. The tip circle of the gear, ρ=44\rho = 44 mm, is reached at h=3.144h = 3.144 mm.

A pinion cutter cuts the same flank. A pinion cutter with 1212 teeth of the same module has rc=24r_c = 24 mm. With the closed form root ψ∗=−(rc/r)(tc−tan⁡φ)\psi^* = -(r_c/r)(t_c - \tan\varphi), where tct_c is the roll angle of the cutter flank, the cutter points at tc=tan⁡φ∓0.2t_c = \tan\varphi \mp 0.2 give ψ∗=±0.12\psi^* = \pm 0.12 and the gear points at ρ=41.758\rho = 41.758 and 38.69038.690 mm, both with θ+inv⁡α=90.854°\theta + \operatorname{inv}\alpha = 90.854°. This is the conjugacy of step 3: the cutter is an involute gear, and any gear that meshes with it on the same base pitch has the same involute flank.

Undercut of a 12 tooth gear. With z=12z = 12 and the same rack, r=24r = 24 mm and rsin⁡2φ=2.807r\sin^2\varphi = 2.807 mm, which is less than 44 mm. The rack tip makes its root at ψ∗=−0.5186\psi^* = -0.5186, behind the cusp, and the branch check finds that the rack covers this point by 0.0550.055 mm at a nearby turn. A simulated cut with dense positions of the rack confirms that near ρ=22.6\rho = 22.6 mm the cut flank lies 3.7×10−53.7 \times 10^{-5} rad inside the involute, and that at ρ=23\rho = 23 mm and above it agrees with the involute.

A cam with a roller follower. The profile of a cam with a roller follower is the envelope of the roller circle as the follower moves around the cam, in the frame of the cam. The tool is a circle and the motion is the inverted motion of the follower, and the envelope is an offset curve of the pitch curve. Cam profile synthesis computes it this way.

Variations

  • Profile shift. Move the pitch line of the rack away from the center by xmxm, so that the rack translates on the line y=r+xmy = r + xm but still moves by rψr\psi. The rolling line of the rack stays at y=ry = r, so the base circle stays rcos⁡φr\cos\varphi, and only the place of the involute on it changes. The tooth on the pitch circle becomes thicker by 2xmtan⁡φ2xm\tan\varphi, and the undercut limit becomes (k−x)m≤rsin⁡2φ(k - x)m \le r\sin^2\varphi.
  • Hobbing. A hob is a worm with gashes that make cutting edges. In the transverse section of a spur gear its threads look like a rack that moves along its pitch line while the hob turns, so the cut flank is the rack envelope above. The hob cuts all teeth in one continuous motion, with no stop to index from one tooth to the next.
  • Surfaces in space. For a tool surface rc(u,θ)\mathbf r_c(u, \theta) the envelope is the set of points with n(u,θ)⋅v(u,θ,ψ)=0\mathbf n(u, \theta) \cdot \mathbf v(u, \theta, \psi) = 0, one equation in three parameters, so it is a surface. Litvin and Fuentes write the motion as a product of 4×44 \times 4 matrices (Chapter 1) and the relative velocity from it (Chapter 2), and they compute helical, bevel, worm and face gears in this way.
  • Kinematic form. Step 3 replaces the equation of meshing by a geometric test: the normal of the tool at the point passes through the pitch point. This avoids derivatives of the motion and is the classical way to construct conjugate profiles by hand.
  • Simulated cutting. Subtract the tool region at many positions from the blank, and read the boundary. This is the brute force check of the method, and the right tool when the tool has many corners and edges, as in a swept volume computation.

Pitfalls

  • Extra roots. The equation of meshing has other roots than the cut point. For a pinion cutter, the normal of a cutter point passes through the pitch point at two turns of the cutter, once for each tangent from the pitch point to the cutter base circle. For the 12 tooth cutter above at tc=tan⁡φ−0.2t_c = \tan\varphi - 0.2, a window of [−0.3,0.3][-0.3, 0.3] gives the true root ψ∗=0.12\psi^* = 0.12 and a second root at ψ=−0.2989\psi = -0.2989, whose point is not on the involute. Use a window around the expected contact, or the branch check.
  • The cusp is not material. Past the base circle the envelope turns back on a second branch. These points solve the equation, but the tool removes them, and taking them as the tooth gives a profile that crosses itself.
  • The tool tip is a separate curve. The flank of the rack is straight only up to the height kmkm. The rounded tip below it cuts the root fillet, which is the envelope of the tip circle, a trochoid. Using the flank formula below kmkm is wrong.
  • The rolling radius fixes the number of teeth. The rack must move by rψr\psi with r=mz/2r = mz/2. A different rolling radius still gives an involute, but its base pitch no longer fits zz teeth around the gear.
  • Errors in the derivatives. A wrong sign in a′a' or t′\mathbf t' moves every root and still gives a smooth curve. Check ff against a central difference of FF in ψ\psi, as the tests of this page do.

Code

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

gear_generation_by_enveloping.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/gear-generation-by-enveloping/. The authors are listed in prov/X68YYQ.jsonl.

"""Planar gear generation: the tooth profile as the envelope of a tool in relative motion.

A tool curve r_c(u) with unit normal n_c(u) is given in the tool frame. A generating
motion maps the tool frame into the gear frame by p_g = R(a(psi)) p_c + t(psi), where
psi is the turn of the gear. The equation of meshing

    f(u, psi) = (R(a) n_c(u)) . (a'(psi) J R(a) r_c(u) + t'(psi)) = 0

says that the tool point moves along the tool surface relative to the gear, so it is
a point of the envelope. For each u, its roots psi give the generated points.
"""

from __future__ import annotations

import math
from typing import Callable, List, Tuple

Vec = Tuple[float, float]


def rot(a: float, p: Vec) -> Vec:
    """R(a) p, the rotation by a counterclockwise."""
    c, s = math.cos(a), math.sin(a)
    return (c * p[0] - s * p[1], s * p[0] + c * p[1])


def perp(p: Vec) -> Vec:
    """J p, the rotation by +90 degrees."""
    return (-p[1], p[0])


def dot(p: Vec, q: Vec) -> float:
    return p[0] * q[0] + p[1] * q[1]


def inv(alpha: float) -> float:
    """The involute function tan(alpha) - alpha."""
    return math.tan(alpha) - alpha


def involute(rb: float, t: float) -> Vec:
    """The involute of the circle of radius rb about the origin, started at (rb, 0), at roll angle t."""
    c, s = math.cos(t), math.sin(t)
    return (rb * (c + t * s), rb * (s - t * c))


class Motion:
    """A planar generating motion: angle a(psi), translation t(psi) and their derivatives."""

    def __init__(self, a, da, t, dt):
        self.a, self.da, self.t, self.dt = a, da, t, dt

    def apply(self, psi: float, p: Vec) -> Vec:
        """Tool point p in the gear frame at the gear turn psi."""
        q, tr = rot(self.a(psi), p), self.t(psi)
        return (q[0] + tr[0], q[1] + tr[1])


def rack_motion(r: float) -> Motion:
    """A rack whose pitch line rolls on the pitch circle of radius r without slip.

    Fixed frame: gear center at the origin, rack pitch line y = r, pitch point (0, r).
    When the gear turns by psi counterclockwise, the rack moves by -r psi along x.
    """
    def t(psi):
        return rot(-psi, (-r * psi, r))

    def dt(psi):
        a, b = perp(t(psi)), rot(-psi, (-r, 0.0))
        return (-a[0] + b[0], -a[1] + b[1])

    return Motion(lambda psi: -psi, lambda psi: -1.0, t, dt)


def shaper_motion(r: float, rc: float) -> Motion:
    """A pinion cutter of pitch radius rc whose pitch circle rolls outside the gear pitch circle of radius r."""
    k = r / rc
    oc = (0.0, r + rc)

    def t(psi):
        return rot(-psi, oc)

    def dt(psi):
        a = perp(t(psi))
        return (-a[0], -a[1])

    return Motion(lambda psi: -(k + 1.0) * psi, lambda psi: -(k + 1.0), t, dt)


def rack_flank(phi: float):
    """The straight flank of a rack cutter through the pitch point, at the angle phi to the normal of the pitch line.

    Returns r_c(u) and the unit normal n_c(u) in the rack frame, whose origin is on the pitch line.
    """
    s, c = math.sin(phi), math.cos(phi)
    return (lambda u: (u * s, u * c)), (lambda u: (c, -s))


def shaper_flank(rc: float, phi: float):
    """An involute flank of a pinion cutter with pitch radius rc, through the pitch point (0, -rc) of its frame.

    It has the same normal there as rack_flank(phi), so both tools cut the same gear flank.
    """
    rb = rc * math.cos(phi)
    beta = -math.pi / 2 + inv(phi)

    def curve(t):
        x, y = involute(rb, t)
        return rot(beta, (x, -y))

    def normal(t):
        return rot(beta, (math.sin(t), math.cos(t)))

    return curve, normal


def meshing(curve, normal, motion: Motion, u: float, psi: float) -> float:
    """f(u, psi): the normal part of the velocity of the tool point relative to the gear. Cost O(1)."""
    a = motion.a(psi)
    n = rot(a, normal(u))
    v = perp(rot(a, curve(u)))
    dt = motion.dt(psi)
    return dot(n, (motion.da(psi) * v[0] + dt[0], motion.da(psi) * v[1] + dt[1]))


def _bisect(f, lo: float, hi: float, flo: float, tol: float) -> float:
    """A root of f in [lo, hi], given that f(lo) = flo and f(hi) have opposite signs."""
    while hi - lo > tol * (1 + abs(lo)):
        mid = 0.5 * (lo + hi)
        fm = f(mid)
        if fm == 0:
            return mid
        if (fm < 0) == (flo < 0):
            lo, flo = mid, fm
        else:
            hi = mid
    return 0.5 * (lo + hi)


def envelope(curve: Callable[[float], Vec], normal: Callable[[float], Vec], motion: Motion,
             us: List[float], psi_lo: float, psi_hi: float, cells: int = 64,
             tol: float = 1e-14, keep=None) -> List[Tuple[float, float, Vec]]:
    """Points of the generated profile: for each u, every root psi of the equation of meshing in [psi_lo, psi_hi].

    keep(u, psi, p), if given, is the branch check: it returns False for a point that the tool removes
    at some other position. Precondition: psi_lo < psi_hi; two roots in the same cell of width
    (psi_hi - psi_lo)/cells are missed.
    Cost O(len(us) * (cells + log(1/tol))) evaluations of f, plus the calls to keep.
    Returns (u, psi, point in the gear frame).
    """
    out = []
    h = (psi_hi - psi_lo) / cells
    for u in us:  # @line L1
        def f(psi):
            return meshing(curve, normal, motion, u, psi)  # @line L2
        roots = []
        x0, f0 = psi_lo, f(psi_lo)
        for i in range(1, cells + 1):  # @line L3
            x1 = psi_hi if i == cells else psi_lo + i * h
            f1 = f(x1)
            if f0 == 0:
                roots.append(x0)
            elif f0 * f1 < 0:
                roots.append(_bisect(f, x0, x1, f0, tol))  # @line L4
            x0, f0 = x1, f1
        if f0 == 0:
            roots.append(x0)
        for psi in roots:
            p = motion.apply(psi, curve(u))  # @line L5
            if keep is None or keep(u, psi, p):  # @line L6
                out.append((u, psi, p))
    return out


def rack_clearance(phi: float, motion: Motion, p: Vec, psi_lo: float, psi_hi: float,
                   tip: float, samples: int = 400) -> float:
    """How far the gear point p stays outside one rack tooth over the sampled turns in [psi_lo, psi_hi].

    The tooth, in the rack frame, is the set of points q with n_c . q < 0 (behind the flank of
    rack_flank(phi)) and q_y > -tip (above the tip line, tip = addendum of the cutter).
    A negative result means that the tooth covers p at some sampled turn, so p is cut away.
    Cost O(samples).
    """
    _, normal = rack_flank(phi)
    n0 = normal(0.0)
    best = math.inf
    for i in range(samples + 1):
        psi = psi_lo + (psi_hi - psi_lo) * i / samples
        a, t = motion.a(psi), motion.t(psi)
        q = rot(-a, (p[0] - t[0], p[1] - t[1]))
        best = min(best, max(dot(n0, q), -tip - q[1]))
    return best
test_gear_generation_by_enveloping.py 188 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/gear-generation-by-enveloping/. The authors are listed in prov/X68YYQ.jsonl.

import math
import random
import unittest

from gear_generation_by_enveloping import (
    envelope, involute, inv, meshing, rack_clearance, rack_flank, rack_motion, rot,
    shaper_flank, shaper_motion,
)


def polar(p):
    return math.hypot(p[0], p[1]), math.atan2(p[1], p[0])


def closed_involute_point(rb, theta0, t):
    """The flank theta + inv(alpha) = theta0 of the gear: the mirror of involute(rb, t), turned by theta0."""
    x, y = involute(rb, t)
    return rot(theta0, (x, -y))


def random_rack_case(rng, undercut_free=True):
    while True:
        m = rng.uniform(0.5, 10.0)
        phi = math.radians(rng.uniform(14.5, 30.0))
        z = rng.randint(8, 120)
        r = m * z / 2
        if not undercut_free or r * math.sin(phi) ** 2 >= m:
            return m, phi, z, r


class TestRackGeneration(unittest.TestCase):
    def test_root_and_point_match_closed_form_involute(self):
        rng = random.Random(1)
        for _ in range(600):
            m, phi, z, r = random_rack_case(rng, undercut_free=False)
            rb = r * math.cos(phi)
            theta0 = math.pi / 2 + inv(phi)
            limit = r * math.sin(phi) * math.tan(phi)
            u = rng.uniform(-min(m / math.cos(phi), limit), 1.25 * m / math.cos(phi))
            curve, normal = rack_flank(phi)
            pts = envelope(curve, normal, rack_motion(r), [u], -1.5, 1.5)
            self.assertEqual(len(pts), 1)
            _, psi, p = pts[0]
            self.assertAlmostEqual(psi, u / (r * math.sin(phi)), delta=1e-11)
            t = (r * math.sin(phi) + u / math.tan(phi)) / rb
            q = closed_involute_point(rb, theta0, t)
            self.assertLess(math.dist(p, q), 1e-9 * r)
            rho, theta = polar(p)
            self.assertGreaterEqual(rho, rb * (1 - 1e-12))
            self.assertAlmostEqual(theta + inv(math.acos(min(1.0, rb / rho))), theta0, delta=1e-7)

    def test_root_on_grid_node_is_found_once(self):
        curve, normal = rack_flank(math.radians(20))
        pts = envelope(curve, normal, rack_motion(40.0), [0.0], -1.0, 1.0, cells=64)
        self.assertEqual(len(pts), 1)
        self.assertEqual(pts[0][1], 0.0)
        self.assertLess(math.dist(pts[0][2], (0.0, 40.0)), 1e-12)

    def test_meshing_is_normal_part_of_relative_velocity(self):
        rng = random.Random(2)
        h = 1e-6
        for _ in range(300):
            m, phi, z, r = random_rack_case(rng, undercut_free=False)
            if rng.random() < 0.5:
                curve, normal = rack_flank(phi)
                motion = rack_motion(r)
                u = rng.uniform(-2 * m, 2 * m)
            else:
                rc = m * rng.randint(10, 40) / 2
                curve, normal = shaper_flank(rc, phi)
                motion = shaper_motion(r, rc)
                u = rng.uniform(0.0, 1.0)
            psi = rng.uniform(-0.5, 0.5)
            a = motion.apply(psi + h, curve(u))
            b = motion.apply(psi - h, curve(u))
            v = ((a[0] - b[0]) / (2 * h), (a[1] - b[1]) / (2 * h))
            n = rot(motion.a(psi), normal(u))
            expect = n[0] * v[0] + n[1] * v[1]
            self.assertAlmostEqual(meshing(curve, normal, motion, u, psi), expect,
                                   delta=1e-5 * (1 + abs(expect)) * r)

    def test_point_is_touched_but_not_cut_by_the_rack(self):
        rng = random.Random(3)
        for _ in range(60):
            m, phi, z, r = random_rack_case(rng)
            motion = rack_motion(r)
            curve, normal = rack_flank(phi)
            u = rng.uniform(-m / math.cos(phi), 1.25 * m / math.cos(phi))
            (_, psi, p), = envelope(curve, normal, motion, [u], -1.5, 1.5)
            c = rack_clearance(phi, motion, p, psi - 0.3, psi + 0.3, m, 600)
            self.assertGreater(c, -1e-9 * r)
            self.assertLess(c, 1e-9 * r)

    def test_brute_force_swept_boundary_is_the_involute(self):
        rng = random.Random(4)
        for _ in range(18):
            m, phi, z, r = random_rack_case(rng)
            z = max(z, 18)
            r = m * z / 2
            rb = r * math.cos(phi)
            theta0 = math.pi / 2 + inv(phi)
            motion = rack_motion(r)
            curve, normal = rack_flank(phi)
            (_, _, low), = envelope(curve, normal, motion, [-m / math.cos(phi)], -1.5, 1.5)
            rho = rng.uniform(math.hypot(*low) + 1e-3 * m, r + m)
            w = 6 * m / r

            def cleared(theta):
                p = (rho * math.cos(theta), rho * math.sin(theta))
                return rack_clearance(phi, motion, p, -w, w, m, 2000) >= 0

            expect = theta0 - inv(math.acos(rb / rho))
            lo, hi = expect - 0.5 * m / rho, expect + 0.5 * m / rho
            self.assertTrue(cleared(lo))
            self.assertFalse(cleared(hi))
            for _ in range(45):
                mid = 0.5 * (lo + hi)
                if cleared(mid):
                    lo = mid
                else:
                    hi = mid
            self.assertAlmostEqual(lo, expect, delta=1e-6)

    def test_undercut_iff_addendum_above_r_sin2_phi(self):
        rng = random.Random(5)
        seen = [0, 0]
        while min(seen) < 40:
            m = rng.uniform(1.0, 6.0)
            phi = math.radians(rng.uniform(14.5, 25.0))
            z = rng.randint(6, 40)
            r = m * z / 2
            ratio = r * math.sin(phi) ** 2 / m
            if abs(ratio - 1) < 0.03:
                continue
            motion = rack_motion(r)
            curve, normal = rack_flank(phi)
            (_, psi, p), = envelope(curve, normal, motion, [-m / math.cos(phi)], -2.0, 2.0)
            c = rack_clearance(phi, motion, p, psi - 0.3, psi + 0.3, m, 3000)
            if ratio >= 1:
                self.assertGreater(c, -1e-9 * r)
            else:
                self.assertLess(c, -1e-6 * m)
            seen[ratio >= 1] += 1


class TestShaperGeneration(unittest.TestCase):
    def test_shaper_cuts_the_same_involute_as_the_rack(self):
        rng = random.Random(6)
        checked = 0
        for _ in range(300):
            m, phi, z, r = random_rack_case(rng, undercut_free=False)
            rc = m * rng.randint(10, 40) / 2
            rb = r * math.cos(phi)
            theta0 = math.pi / 2 + inv(phi)
            curve, normal = shaper_flank(rc, phi)
            motion = shaper_motion(r, rc)
            t = math.tan(phi) + rng.uniform(-0.15, 0.15)
            expect = -(rc / r) * (t - math.tan(phi))
            pts = envelope(curve, normal, motion, [t], expect - 0.02, expect + 0.02, cells=4)
            self.assertEqual(len(pts), 1)
            _, psi, p = pts[0]
            self.assertAlmostEqual(psi, expect, delta=1e-11)
            # The contact is (t - tan(phi)) rc cos(phi) from the pitch point along the line of action.
            # Past the tangent point of the gear base circle, r sin(phi) away, the point is undercut.
            if rc * math.cos(phi) * (t - math.tan(phi)) <= 0.999 * r * math.sin(phi):
                rho, theta = polar(p)
                self.assertGreaterEqual(rho, rb)
                self.assertAlmostEqual(theta + inv(math.acos(rb / rho)), theta0, delta=1e-7)
                checked += 1
        self.assertGreater(checked, 200)

    def test_wide_window_shows_a_second_branch(self):
        phi = math.radians(20)
        curve, normal = shaper_flank(24.0, phi)
        pts = envelope(curve, normal, shaper_motion(40.0, 24.0), [math.tan(phi) - 0.2], -0.3, 0.3)
        self.assertEqual(len(pts), 2)
        rb = 40.0 * math.cos(phi)
        theta0 = math.pi / 2 + inv(phi)
        errs = sorted(abs(polar(p)[1] + inv(math.acos(rb / polar(p)[0])) - theta0) for _, _, p in pts)
        self.assertLess(errs[0], 1e-9)
        self.assertGreater(errs[1], 1e-2)


if __name__ == "__main__":
    unittest.main()

Exercises

  1. Show directly from f(u,ψ)=0f(u, \psi) = 0 for the rack of hole 2 that ψ∗=u/(rsin⁡φ)\psi^* = u/(r\sin\varphi), without the instant center.
  2. Keep the module and let the number of teeth of a pinion cutter grow without bound. Show that its flank near the pitch point tends to the straight flank of the rack, and that the motion of hole 2 for the cutter tends to the motion for the rack.
  3. Show that the cusp of the rack envelope is at ρ=rb\rho = r_b, and find the flank height ucos⁡φu\cos\varphi that cuts it.
  4. Find the smallest profile shift xx that lets a rack with k=1k = 1 and φ=20°\varphi = 20° cut 1212 teeth without undercut.
  5. A tool is a circle of radius RfR_f whose center moves on a curve c(s)c(s) without turning. Write the equation of meshing and show that the envelope is the pair of offset curves at the distance RfR_f.

References

  1. Faydor L. Litvin and Alfonso Fuentes, Gear Geometry and Applied Theory, 2nd edition, Cambridge University Press, 2004, Chapter 1 (coordinate transformation), Chapter 2 (relative velocity), Chapter 6 (conjugated surfaces and curves, the envelope and the equation of meshing) and Chapter 10 (spur involute gears, generation by a rack cutter)
  2. Development of Gear Technology and Theory of Gearing, the history of the theory of gearing, with Olivier (1842) and Gochman (1886)
  3. Robert L. Norton, Design of Machinery, 6th edition, McGraw-Hill, 2019, Section 9.2 (p. 493, the involute) and Section 9.4 (p. 500, interference and undercutting)
  4. Richard G. Budynas and J. Keith Nisbett, Shigley's Mechanical Engineering Design, 10th edition, McGraw-Hill, Section 13-7, interference and the smallest pinion cut by a rack

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • three classic examples