Algorithm Search⌘K

Algorithmcore

Cam profile synthesis

Also called cam contour generation, cam layout by inversion.

Computes the cam contour as the envelope of the follower positions for a given displacement law, in closed form for flat-faced and roller followers.

Time
Θ(m + N log m) worst · average · best
Space
Θ(m + N) extra
Where
N = the number of cam angles sampled; m = the number of segments of the cam program
Properties
deterministiciterative

Cam profile synthesis computes the outline of a disk cam from the motion that its follower must make. A disk cam is a plate that turns on a shaft. Its follower is a part that slides in a fixed guide and is kept against the edge of the cam by a spring, so the shape of the edge drives the follower. The input is the displacement s(θ)s(\theta) of the follower as a function of the cam angle, built from cam follower motion laws. The method is inversion: hold the cam still and turn the ground and the follower the other way. The follower then takes one position for each cam angle, and the cam outline is the envelope of these positions, the curve that touches each of them. For a roller follower and for a flat-faced follower the envelope has a closed form, so each point of the outline costs a fixed number of operations, with no search and no root finding.

In plain words

Draw the cam standing still in the middle of the page. Walk the follower around it, and at each step put the follower where the motion plan says it must be at that angle. The cam edge must touch the follower at each step and must not cut into it. So the edge is the curve that just touches all the drawn followers. For a round roller, the edge is a fixed distance inside the path of the roller center. For a flat foot, the edge is the curve that all the drawn foot lines touch. The same formulas also tell you how steep the push is and how sharp the edge is, so you can see at once if the cam is too small.

The problem

Input.

  • A cam program: segments i=1,…,mi = 1, \ldots, m, each with a motion law fif_i on [0,1][0, 1] (fi(0)=0f_i(0) = 0, fi(1)=1f_i(1) = 1, or fi=0f_i = 0 for a dwell), a cam angle βi>0\beta_i > 0 and a lift LiL_i (negative for a return), with ∑βi=2π\sum \beta_i = 2\pi and ∑Li=0\sum L_i = 0.
  • The base circle radius Rb>0R_b > 0: the radius of the smallest circle about the cam center that touches the cam profile.
  • The follower. A translating roller follower has a roller of radius Rf≥0R_f \ge 0, and the line of its motion is at the offset ε\varepsilon from the cam center. A translating flat-faced follower has a flat face square to its line of motion.
  • The number of samples N≥1N \ge 1.

Output. For θ=2πk/N\theta = 2\pi k/N, k=0,…,N−1k = 0, \ldots, N - 1, in the frame of the cam: the point of the cam profile that touches the follower, and the checks that decide if the cam works, the pressure angle and the radius of curvature.

For the roller follower, the prime circle has the radius Rp=Rb+RfR_p = R_b + R_f. It is the circle through the roller center at zero lift. The pitch curve is the path of the roller center relative to the cam. The cam turns counterclockwise. The fixed frame has the cam center at the origin and the follower moving along the line x=εx = \varepsilon in the direction +y+y.

The algorithm

Here R(α)R(\alpha) is the rotation by α\alpha. A point pp fixed to the ground is at R(−θ)pR(-\theta)p in the frame of a cam that has turned by θ\theta.

  1. CAM-PROFILE(P, R_b, R_f, ε, N) ▷ P = segments (f_i, β_i, L_i); translating roller follower
  2. 1check Σ β_i = 2π and Σ L_i = 0; θ_1 ← 0, h_1 ← 0, θ_{i+1} ← θ_i + β_i, h_{i+1} ← h_i + L_i
  3. 2R_p ← R_b + R_f, d_0 ← √(R_p² − ε²)
  4. 3for k ← 0 to N − 1, with θ ← 2πk/N, do
  5. 4i ← the segment with θ_i ≤ θ < θ_{i+1}, x ← (θ − θ_i)/β_i
  6. 5s ← h_i + L_i f_i(x), s′ ← L_i f_i′(x)/β_i, s″ ← L_i f_i″(x)/β_i²
  7. 6u ← d_0 + s, w ← s′ − ε, D ← √(u² + w²)
  8. 7C ← R(−θ)(ε, u) ▷ roller center: a point of the pitch curve
  9. 8K ← R(−θ)(ε + R_f w/D, u − R_f u/D) ▷ contact: a point of the cam profile
  10. 9φ ← atan2(w, u) ▷ pressure angle
  11. 10ρ ← D³/(u² + w(w + s′) − u s″) ▷ radius of curvature of the pitch curve
  12. 11output (θ, s, C, K, φ, ρ), marked undercut if 0 < ρ ≤ R_f
  13. FLAT-FACE-PROFILE(P, R_b, N) ▷ translating follower, flat face square to its axis
  14. 12for k ← 0 to N − 1, with θ ← 2πk/N, do
  15. 13s, s′, s″ as in lines L4 and L5
  16. 14Q ← R(−θ)(s′, R_b + s) ▷ contact: a point of the cam profile
  17. 15ρ ← R_b + s + s″ ▷ radius of curvature; it must be positive
  18. 16output (θ, s, Q, ρ); the contact is at the distance s′ from the axis along the face

Line L5 is the chain rule on s=hi+Lifi((θ−θi)/βi)s = h_i + L_i f_i((\theta - \theta_i)/\beta_i). Line L7 is the inversion: in the fixed frame the roller center is at (ε,d0+s)(\varepsilon, d_0 + s), and d0d_0 puts it on the prime circle at zero lift. The pitch curve has the tangent R(−θ)(u,w)R(-\theta)(u, w). Line L8 steps from the roller center by RfR_f along the normal toward the cam, so the cam profile is the inner offset of the pitch curve at the distance RfR_f, as on the offset curve page. Line L9 is the angle between the common normal and the line of motion. Line L10 is the radius of curvature of the pitch curve, positive where the curve is convex. With ε=0\varepsilon = 0 it is the formula [(Rp+s)2+s′2]3/2/[(Rp+s)2+2s′2−s′′(Rp+s)][(R_p + s)^2 + s'^2]^{3/2}/[(R_p + s)^2 + 2s'^2 - s''(R_p + s)] of Norton, Section 8.6. The cam profile then has the radius ρ−Rf\rho - R_f at KK. For the flat face, line L14 is the envelope of the face lines, and line L15 is the radius of the profile itself.

Example

Take a rise of 2020 mm with the cycloidal law over 90°90°, a dwell of 90°90°, a return of 2020 mm with the 3-4-5 polynomial over 90°90°, and a dwell of 90°90°. Take Rb=40R_b = 40 mm, a roller of Rf=10R_f = 10 mm and no offset, so Rp=d0=50R_p = d_0 = 50 mm. In the rise, β=π/2\beta = \pi/2 and the cycloidal law gives s′=(40/π)(1−cos⁡4θ)s' = (40/\pi)(1 - \cos 4\theta) and s′′=(160/π)sin⁡4θs'' = (160/\pi)\sin 4\theta. Lengths are in mm, and s′s', s′′s'' are per radian of cam angle.

θ\theta ss s′s' s′′s'' pitch point CC cam point KK φ\varphi ρ\rho
0°0° 0 0 0 (0, 50) (0, 40) 0°0° 50.00
22.5°22.5° 1.8169 12.7324 50.9296 (19.8295, 47.8726) (18.3178, 37.9875) 13.81°13.81° 410.36
45°45° 10 25.4648 0 (42.4264, 42.4264) (38.6799, 33.1548) 23.00°23.00° 56.55
67.5°67.5° 18.1831 12.7324 −50.9296-50.9296 (62.9930, 26.0925) (54.6136, 20.6348) 10.58°10.58° 39.51
90°90° 20 0 0 (70, 0) (60, 0) 0°0° 70.00
225°225° 10 −23.8732-23.8732 0 (−42.4264-42.4264, −42.4264-42.4264) (−33.2422-33.2422, −38.4705-38.4705) −21.70°-21.70° 56.81

At 45°45°, line L6 gives u=60u = 60, w=80/π=25.4648w = 80/\pi = 25.4648 and D=65.18D = 65.18, and line L9 gives φ=arctan⁡(25.4648/60)=23.00°\varphi = \arctan(25.4648/60) = 23.00°. Line L7 turns (0,60)(0, 60) by −45°-45° to (42.4264,42.4264)(42.4264, 42.4264). Line L10 gives 65.183/(3600+1296.91)=56.5565.18^3/(3600 + 1296.91) = 56.55.

With N=3600N = 3600 samples, the largest pressure angle is 23.23°23.23° at θ=41.9°\theta = 41.9° in the rise and −21.94°-21.94° at 228.5°228.5° in the return. The smallest radius of the pitch curve is 39.4239.42 mm at 65.9°65.9°, so the cam itself has the radius 29.4229.42 mm there, and no sample is marked as undercut. An offset of ε=5\varepsilon = 5 mm lowers the peak in the rise to 19.07°19.07° but raises the peak in the return to −26.13°-26.13°. An offset helps one direction of motion at the cost of the other.

The same program with a flat-faced follower and Rb=40R_b = 40 mm has the smallest radius ρ=7.15\rho = 7.15 mm at 66.5°66.5°. The smallest value of s+s′′s + s'' over the cycle is −32.85-32.85 mm, so line L15 needs Rb>32.85R_b > 32.85 mm. The contact moves along the face from s′=−23.87s' = -23.87 mm to s′=25.46s' = 25.46 mm, so the face must be at least 49.3449.34 mm wide.

A small cam shows the undercut. Take a cycloidal rise of 2020 mm over 40°40°, a dwell of 140°140°, a cycloidal return over 40°40° and a dwell of 140°140°, with Rb=10R_b = 10 mm and Rf=9R_f = 9 mm. The pitch curve then has a convex radius of only 6.596.59 mm, less than the roller, and line L11 marks 30 of 720 samples, near 30°30° and near 189°189°. The pressure angle reaches 64.3°64.3°, far above the usual limits on the cam pressure angle page. With Rb=60R_b = 60 mm no sample is marked.

Correctness

Four facts make the output right. Line L5 gives ss, s′s' and s′′s'' by the chain rule. In the frame of the cam, the roller center at the angle θ\theta is the fixed point (ε,d0+s)(\varepsilon, d_0 + s) turned by −θ-\theta, which is line L7. The roller circles have the envelope C±RfnC \pm R_f n, where nn is the unit normal of the pitch curve, because a point of the envelope satisfies (p−C)⋅C′=0(p - C)\cdot C' = 0. The face lines q⋅e(θ)=Rb+sq\cdot e(\theta) = R_b + s, with e=R(−θ)(0,1)e = R(-\theta)(0, 1), have the envelope (Rb+s)e+s′e′(R_b + s)e + s'e', which is line L14.

These facts show that each output point is on the envelope. The proof also shows that the follower does not cut the cam. If ρ>Rf\rho > R_f at every angle, the tangent of the profile turns once in one direction, and the whole cam lies on the inner side of the tangent line at each contact point. So the roller is at the distance RfR_f from the cam, and touches it at KK. If 0<ρ<Rf0 < \rho < R_f at an angle, the roller at nearby angles covers the point KK, which is the undercut of line L11. For the flat face the same argument works when Rb+s+s′′>0R_b + s + s'' > 0 at every angle. The full proof is below.

Proof: The computed points lie on the cam profile, and the follower touches the cam without cutting itfull

We use the notation of the page. The cam turns counterclockwise by θ\theta about the origin OO. R(α)R(\alpha) is the rotation by α\alpha, and J=R(π/2)J = R(\pi/2), so J(a,b)=(−b,a)J(a, b) = (-b, a). The program is a list of segments with laws fif_i, angles βi>0\beta_i > 0 and lifts LiL_i, with ∑βi=2π\sum \beta_i = 2\pi and ∑Li=0\sum L_i = 0. We assume that each fif_i is C2C^2 on [0,1][0, 1] and that ss and s′s' are continuous across the segment ends, so ss is C1C^1 on the cycle and s′′s'' is piecewise continuous. All derivatives below are with respect to θ\theta. At a segment end where s′′s'' jumps, the statements about s′′s'', α′\alpha' and ρ\rho hold on each side.

Lemma 1 (the program). Line L5 returns s(θ)s(\theta), s′(θ)s'(\theta) and s′′(θ)s''(\theta).

Proof. Line L1 sets θi=∑j<iβj\theta_i = \sum_{j < i} \beta_j and hi=∑j<iLjh_i = \sum_{j < i} L_j, so segment ii covers [θi,θi+1)[\theta_i, \theta_{i+1}) and starts at the height hih_i. Line L4 finds the segment that holds θ\theta and sets x=(θ−θi)/βix = (\theta - \theta_i)/\beta_i, so dx/dθ=1/βidx/d\theta = 1/\beta_i. On that segment s=hi+Lifi(x)s = h_i + L_i f_i(x), and the chain rule gives s′=Lifi′(x)/βis' = L_i f_i'(x)/\beta_i and s′′=Lifi′′(x)/βi2s'' = L_i f_i''(x)/\beta_i^2. Since ∑Li=0\sum L_i = 0 and ∑βi=2π\sum \beta_i = 2\pi, the end of the last segment has height h1=0h_1 = 0 at the angle 2π2\pi, so ss is 2π2\pi-periodic. □\square

Lemma 2 (inversion). In the frame of the cam, the roller center at the angle θ\theta is C(θ)=R(−θ)(ε,u)C(\theta) = R(-\theta)(\varepsilon, u) with u=d0+su = d_0 + s, which is line L7. Its derivative is C′=R(−θ)(u,w)C' = R(-\theta)(u, w) with w=s′−εw = s' - \varepsilon.

Proof. In the fixed frame the follower slides on the line x=εx = \varepsilon, and at s=0s = 0 the roller center is on the prime circle of radius Rp=Rb+RfR_p = R_b + R_f, so it is at (ε,d0)(\varepsilon, d_0) with ε2+d02=Rp2\varepsilon^2 + d_0^2 = R_p^2. That is line L2. At lift ss it is at p(θ)=(ε,d0+s)p(\theta) = (\varepsilon, d_0 + s). A point with cam coordinates cc is at R(θ)cR(\theta) c in the fixed frame, so the fixed point pp has the cam coordinates R(−θ)pR(-\theta) p. Since ddθR(−θ)=−R(−θ)J\frac{d}{d\theta} R(-\theta) = -R(-\theta) J,

C′=R(−θ)(−J(ε,u)+(0,s′))=R(−θ)((u,−ε)+(0,s′))=R(−θ)(u,w).□C' = R(-\theta)\bigl(-J(\varepsilon, u) + (0, s')\bigr) = R(-\theta)\bigl((u, -\varepsilon) + (0, s')\bigr) = R(-\theta)(u, w). \qquad \square

Put D=u2+w2=∣C′∣D = \sqrt{u^2 + w^2} = |C'|, the unit tangent T=R(−θ)(u,w)/DT = R(-\theta)(u, w)/D and the unit normal n=JT=R(−θ)(−w,u)/Dn = JT = R(-\theta)(-w, u)/D. We assume u>0u > 0, which holds when s>−d0s > -d_0, for example when s≥0s \ge 0. Then D>0D > 0 and the pitch curve is regular.

Lemma 3 (the turning of the tangent). The angle of TT is α(θ)=φ(θ)−θ\alpha(\theta) = \varphi(\theta) - \theta, where φ=atan2⁡(w,u)\varphi = \operatorname{atan2}(w, u) is the value of line L9, and the signed curvature of the pitch curve is κ=α′/D\kappa = \alpha'/D. Line L10 computes ρ=−1/κ=−D/α′\rho = -1/\kappa = -D/\alpha'.

Proof. The vector (u,w)(u, w) has the angle φ\varphi, and R(−θ)R(-\theta) subtracts θ\theta. The curvature of a plane curve is the rate of turn of its tangent per unit length, and the length grows at the rate DD, so κ=α′/D\kappa = \alpha'/D. With u′=s′u' = s' and w′=s′′w' = s'',

φ′=uw′−wu′D2=us′′−ws′D2,α′=φ′−1=−u2+w(w+s′)−us′′D2,\varphi' = \frac{u w' - w u'}{D^2} = \frac{u s'' - w s'}{D^2}, \qquad \alpha' = \varphi' - 1 = -\frac{u^2 + w(w + s') - u s''}{D^2},

so −D/α′=D3/(u2+w(w+s′)−us′′)-D/\alpha' = D^3/(u^2 + w(w + s') - u s''), which is line L10. □\square

As θ\theta grows the pitch curve runs clockwise about OO, so a convex arc has α′<0\alpha' < 0 and ρ>0\rho > 0, and ρ\rho is then the ordinary radius of curvature. On a circle of radius RpR_p about OO (a dwell with ε=0\varepsilon = 0) we get ρ=Rp\rho = R_p. Since φ\varphi is periodic, α\alpha changes by exactly −2π-2\pi over one cycle. The normal n=JTn = JT is to the left of the direction of travel, which is the outer side of a clockwise convex arc.

Lemma 4 (the contact point). The roller circles ∣p−C(θ)∣=Rf|p - C(\theta)| = R_f have the envelope C±RfnC \pm R_f n. Line L8 computes K=C−RfnK = C - R_f n, the branch on the side of the cam, and K′=(D+Rfα′)T=D(1−Rf/ρ) TK' = (D + R_f\alpha')T = D(1 - R_f/\rho)\,T.

Proof. Write the family as F(p,θ)=∣p−C(θ)∣2−Rf2=0F(p, \theta) = |p - C(\theta)|^2 - R_f^2 = 0. A point of the envelope also satisfies ∂F/∂θ=−2(p−C)⋅C′=0\partial F/\partial\theta = -2(p - C)\cdot C' = 0, so p−Cp - C is a multiple of nn of length RfR_f. In the fixed frame, −Rfn-R_f n is Rf(w,−u)/DR_f(w, -u)/D, so K=R(−θ)(ε+Rfw/D, u−Rfu/D)K = R(-\theta)(\varepsilon + R_f w/D,\ u - R_f u/D), which is line L8. For the derivative, n′=α′Jn=−α′Tn' = \alpha' J n = -\alpha' T, so K′=C′−Rfn′=DT+Rfα′TK' = C' - R_f n' = DT + R_f \alpha' T. With α′=−D/ρ\alpha' = -D/\rho this is D(1−Rf/ρ)TD(1 - R_f/\rho)T. □\square

At KK the roller circle and the profile have the common normal nn. The force between them, without friction, acts along nn. In the fixed frame nn is (−w,u)/D(-w, u)/D and the follower moves along (0,1)(0, 1), so the angle between the force and the motion has the tangent w/uw/u. This is the pressure angle φ\varphi of line L9.

Theorem (no interference). Assume ρ(θ)>Rf\rho(\theta) > R_f for every θ\theta. Then the profile KK is a closed convex curve with radius of curvature ρ−Rf\rho - R_f. For every θ0\theta_0, every point qq of the region Ω\Omega bounded by KK satisfies ∣q−C(θ0)∣≥Rf|q - C(\theta_0)| \ge R_f, with equality at q=K(θ0)q = K(\theta_0). So at each angle the roller touches the cam at K(θ0)K(\theta_0) and does not cut into it.

Proof. By Lemma 4, K′K' is a positive multiple of TT, so KK has the same tangent angle α\alpha as the pitch curve, and its speed is D(1−Rf/ρ)D(1 - R_f/\rho). Its radius of curvature is −∣K′∣/α′=ρ−Rf-|K'|/\alpha' = \rho - R_f. Fix θ0\theta_0 and write n0=n(θ0)n_0 = n(\theta_0) and α0=α(θ0)\alpha_0 = \alpha(\theta_0). Let g(θ)=(K(θ)−K(θ0))⋅n0g(\theta) = (K(\theta) - K(\theta_0))\cdot n_0 on [θ0,θ0+2π][\theta_0, \theta_0 + 2\pi]. Since T(θ)=(cos⁡α,sin⁡α)T(\theta) = (\cos\alpha, \sin\alpha) and n0=(−sin⁡α0,cos⁡α0)n_0 = (-\sin\alpha_0, \cos\alpha_0),

g′(θ)=K′(θ)⋅n0=D(1−Rfρ)sin⁡(α(θ)−α0).g'(\theta) = K'(\theta)\cdot n_0 = D\Bigl(1 - \frac{R_f}{\rho}\Bigr)\sin(\alpha(\theta) - \alpha_0).

The factor in front is positive. Since α′<0\alpha' < 0 and the total change is −2π-2\pi, the difference α(θ)−α0\alpha(\theta) - \alpha_0 falls strictly from 00 to −2π-2\pi. It is in (−π,0)(-\pi, 0) up to an angle θ1\theta_1 and in (−2π,−π)(-2\pi, -\pi) after it, so gg falls on [θ0,θ1][\theta_0, \theta_1] and rises on [θ1,θ0+2π][\theta_1, \theta_0 + 2\pi]. As g(θ0)=0g(\theta_0) = 0 and g(θ0+2π)=0g(\theta_0 + 2\pi) = 0 by periodicity, g≤0g \le 0 everywhere. So the whole curve KK lies in the closed half-plane H0={q:(q−K(θ0))⋅n0≤0}H_0 = \{q : (q - K(\theta_0))\cdot n_0 \le 0\}. A closed curve whose tangent turns once in one direction is a simple convex curve, so Ω\Omega is well defined. It lies in the convex hull of KK, and so in H0H_0. For q∈H0q \in H_0, since C(θ0)−K(θ0)=Rfn0C(\theta_0) - K(\theta_0) = R_f n_0,

∣q−C(θ0)∣≥(C(θ0)−q)⋅n0=Rf+(K(θ0)−q)⋅n0≥Rf,|q - C(\theta_0)| \ge (C(\theta_0) - q)\cdot n_0 = R_f + (K(\theta_0) - q)\cdot n_0 \ge R_f,

with equality at q=K(θ0)q = K(\theta_0). ■\blacksquare

Proposition (the undercut flag). If 0<ρ(θ0)<Rf0 < \rho(\theta_0) < R_f and s′′s'' is continuous at θ0\theta_0, then the roller at angles close to θ0\theta_0 covers the point K(θ0)K(\theta_0). So the cam cannot have K(θ0)K(\theta_0) on its boundary, and the follower does not follow the program near θ0\theta_0. This is the case that line L11 marks.

Proof. Let f(θ)=∣K(θ0)−C(θ)∣2f(\theta) = |K(\theta_0) - C(\theta)|^2. Then f(θ0)=Rf2f(\theta_0) = R_f^2 and f′(θ)=−2(K(θ0)−C(θ))⋅C′(θ)f'(\theta) = -2(K(\theta_0) - C(\theta))\cdot C'(\theta), which is 00 at θ0\theta_0 because K(θ0)−C(θ0)=−Rfn0K(\theta_0) - C(\theta_0) = -R_f n_0 is normal to C′C'. Next, C′′=D′T+Dα′nC'' = D'T + D\alpha' n, so

f′′(θ0)=2∣C′∣2−2(K(θ0)−C(θ0))⋅C′′=2D2+2RfDα′=2D2(1−Rfρ)<0.f''(\theta_0) = 2|C'|^2 - 2(K(\theta_0) - C(\theta_0))\cdot C'' = 2D^2 + 2R_f D\alpha' = 2D^2\Bigl(1 - \frac{R_f}{\rho}\Bigr) < 0.

So ff has a strict local maximum Rf2R_f^2 at θ0\theta_0, and ∣K(θ0)−C(θ)∣<Rf|K(\theta_0) - C(\theta)| < R_f for θ≠θ0\theta \ne \theta_0 close to θ0\theta_0. □\square

Theorem (flat-faced follower). Let e(θ)=R(−θ)(0,1)e(\theta) = R(-\theta)(0, 1) and h=Rb+sh = R_b + s. In the frame of the cam the face is the line q⋅e=hq\cdot e = h. Line L14 computes Q=he+s′e′Q = h e + s' e', the envelope of these lines, and line L15 computes its radius of curvature ρ=Rb+s+s′′\rho = R_b + s + s''. If ρ>0\rho > 0 for every θ\theta, then the whole profile lies in the half-plane q⋅e(θ0)≤h(θ0)q\cdot e(\theta_0) \le h(\theta_0) for every θ0\theta_0, and touches the face at Q(θ0)Q(\theta_0), at the distance s′(θ0)s'(\theta_0) from the follower axis.

Proof. In the fixed frame the face is the line y=Rb+sy = R_b + s. A cam point qq is at R(θ)qR(\theta) q in the fixed frame, and its height is R(θ)q⋅(0,1)=q⋅eR(\theta) q \cdot (0, 1) = q \cdot e. This gives the line. Here e′=R(−θ)(1,0)e' = R(-\theta)(1, 0) and e′′=−ee'' = -e. The envelope of the lines q⋅e=hq\cdot e = h satisfies also q⋅e′=h′q\cdot e' = h', and since ee and e′e' are orthonormal, q=he+h′e′=R(−θ)(s′,Rb+s)q = he + h'e' = R(-\theta)(s', R_b + s), which is line L14. The fixed-frame point (s′,Rb+s)(s', R_b + s) is on the face at the distance s′s' from the axis. Then Q′=h′e+he′+h′′e′+h′e′′=(h+h′′)e′=ρe′Q' = h'e + he' + h''e' + h'e'' = (h + h'')e' = \rho e', and the tangent e′e' turns at the unit rate, so ρ\rho is the radius of curvature. For the half-plane, let g(θ)=(Q(θ)−Q(θ0))⋅e(θ0)g(\theta) = (Q(\theta) - Q(\theta_0))\cdot e(\theta_0). Then

g′(θ)=ρ(θ) e′(θ)⋅e(θ0)=−ρ(θ)sin⁡(θ−θ0),g'(\theta) = \rho(\theta)\, e'(\theta)\cdot e(\theta_0) = -\rho(\theta)\sin(\theta - \theta_0),

which is negative on (θ0,θ0+π)(\theta_0, \theta_0 + \pi) and positive on (θ0+π,θ0+2π)(\theta_0 + \pi, \theta_0 + 2\pi). As g(θ0)=g(θ0+2π)=0g(\theta_0) = g(\theta_0 + 2\pi) = 0, g≤0g \le 0, so Q(θ)⋅e(θ0)≤Q(θ0)⋅e(θ0)=h(θ0)Q(\theta)\cdot e(\theta_0) \le Q(\theta_0)\cdot e(\theta_0) = h(\theta_0). ■\blacksquare

The algorithm. Lines L3 to L11 apply Lemmas 1 to 4 at each angle 2πk/N2\pi k/N, and lines L12 to L16 apply the last theorem. So every output point is a point of the true profile, with no error from the sampling at the sample angles. When the check of line L11 finds no sample with 0<ρ≤Rf0 < \rho \le R_f and every ρ\rho is positive, the conditions of the no-interference theorem hold at the samples. Between samples, the check is only as fine as the step 2π/N2\pi/N.

Complexity

Line L1 takes Θ(m)\Theta(m) time. Line L4 finds the segment by binary search on the start angles in O(log⁡m)O(\log m) time, and lines L5 to L11 take O(1)O(1) time, with one square root, one arc tangent and a few products. So the time is Θ(m+Nlog⁡m)\Theta(m + N\log m). The samples come in increasing order of θ\theta, so a pointer that moves forward through the segments replaces the search, and the time drops to Θ(m+N)\Theta(m + N). The output has Θ(N)\Theta(N) points, and the start angles and heights of line L1 take Θ(m)\Theta(m) more space, so the extra space is Θ(m+N)\Theta(m + N).

The number NN follows from the machining tolerance. Between two samples the profile is replaced by a chord, and a chord of length ℓ\ell on an arc of radius rr is at most ℓ2/(8r)\ell^2/(8r) from the arc. For the example, the cam has a perimeter of 320.2320.2 mm and a smallest radius of 29.4229.42 mm. With N=3600N = 3600 the longest chord is 0.10470.1047 mm, so the bound is 0.10472/(8⋅29.42)=4.7×10−50.1047^2/(8 \cdot 29.42) = 4.7 \times 10^{-5} mm, and the largest distance from a chord to the true profile is 3.5×10−53.5 \times 10^{-5} mm.

Properties

  • Exact at the samples. Each output point is a point of the true profile up to rounding. Only the curve between samples is an approximation.
  • Independent samples. Each angle is computed alone, so the loop runs in parallel and a single angle can be evaluated on demand.
  • Needs s′′s'' but not s′′′s'''. The profile needs ss and s′s', and the checks need s′′s''. A jump in s′′s'', as with the harmonic law next to a dwell, is a jump in the radius of curvature, so the cam has a visible change of curvature there.
  • Deterministic and closed form. There is no iteration, so there is no convergence test and no tolerance to choose.

Variants and improvements

  • Oscillating followers. A follower arm that turns about a fixed pivot needs the same inversion with the arm angle in place of ss. The formulas change, and the pressure angle is measured against the direction of motion of the roller center, which is square to the arm.
  • The cutter path. A milling cutter of radius RcR_c that cuts the cam must follow the offset of the profile by RcR_c. If Rc=RfR_c = R_f, the cutter center follows the pitch curve itself. For other cutters, offset the pitch curve by Rc−RfR_c - R_f with curve offsetting.
  • General follower shapes. For a follower of any convex outline, the largest cam that no follower position overlaps is the complement of the union of the follower positions in the cam frame, which is the swept volume of the follower in two dimensions. The contact points are the points of the follower outline where the relative velocity is square to the normal.
  • Fitted spline cams. Instead of fixed laws, fit ss with a spline that meets the end conditions and limits on s′s', s′′s'' and s′′′s''', then run the same loop on the spline.
  • Three-dimensional cams. Barrel and globoidal cams use the same inversion in space, with an envelope of surfaces in place of curves.

When to use it

Use it whenever the motion of the follower is known and the cam outline must be made, which is the normal order of cam design. Run the checks of lines L9, L10 and L15 first, at a coarse NN, and change RbR_b, ε\varepsilon or the motion laws until the pressure angle and the radius of curvature are acceptable. Then run it at the fine NN that the machining tolerance needs.

Pitfalls

  • The direction of rotation. The profile for a cam that turns clockwise is the mirror image. Using R(θ)R(\theta) in place of R(−θ)R(-\theta) gives the profile of a cam that turns the wrong way. The sign of a useful offset ε\varepsilon also changes with the direction.
  • Derivatives in time or in angle. Lines L5 to L15 use derivatives with respect to θ\theta, in units of length per radian. The velocity in time is ωs′\omega s', not s′s'. Mixing them, or using degrees, gives a wrong pressure angle and a wrong radius.
  • Undercut. If 0<ρ≤Rf0 < \rho \le R_f, the inner offset forms a cusp and a loop, and a cutter of the roller size removes the loop. The cam then has a sharp corner and the follower does not follow the program. Trimming the loop, as on the offset trimming page, does not cure this. Increase RbR_b or use a smaller roller.
  • The flat face needs a positive radius. If Rb+s+s′′≤0R_b + s + s'' \le 0 somewhere, the envelope folds back, and no flat-faced follower can follow the program. A large negative s′′s'' at a high lift causes this. The face must also be wide enough for the full range of s′s'.
  • The offset limit. The offset needs ∣ε∣<Rp|\varepsilon| < R_p, and the formulas assume u=d0+s>0u = d_0 + s > 0.
  • Too few samples near sharp curvature. Equal angle steps give long chords where the cam is large and few points where ρ\rho is small. Choose NN from the smallest radius, or sample by arc length.

Implementations

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.

cam_profile_synthesis.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/cam-profile-synthesis/. The authors are listed in prov/59Q72X.jsonl.

"""Cam profile synthesis for translating followers by the inversion (envelope) method.

The cam turns counterclockwise by the angle theta. In the fixed frame the follower
moves along the line x = eps, and its roller center is at (eps, d0 + s(theta)). In
the frame of the cam, a fixed point p appears at R(-theta) p, so the roller centers
trace the pitch curve C(theta) = R(-theta) (eps, d0 + s), and the cam profile is the
envelope of the roller circles. A flat-faced follower has its face on the line
y = Rb + s, and the profile is the envelope of those lines.
"""

from __future__ import annotations

import bisect
import math
from dataclasses import dataclass
from typing import Callable, List, Sequence, Tuple

Vec = Tuple[float, float]
Law = Callable[[float], Tuple[float, float, float, float]]

TWO_PI = 2.0 * math.pi


def dwell(x):
    """The dwell: f = 0 and all derivatives zero. Cost O(1)."""
    z = x - x
    return z, z, z, z


def harmonic(x):
    """Simple harmonic rise f = (1 - cos(pi x)) / 2 and its first three derivatives. Cost O(1)."""
    c, s, p = math.cos(math.pi * x), math.sin(math.pi * x), math.pi
    return (1 - c) / 2, p / 2 * s, p * p / 2 * c, -p ** 3 / 2 * s


def cycloidal(x):
    """Cycloidal rise f = x - sin(2 pi x) / (2 pi) and its first three derivatives. Cost O(1)."""
    t = 2 * math.pi * x
    return x - math.sin(t) / (2 * math.pi), 1 - math.cos(t), 2 * math.pi * math.sin(t), 4 * math.pi ** 2 * math.cos(t)


def poly345(x):
    """The 3-4-5 polynomial f = 10x^3 - 15x^4 + 6x^5. Exact for Fraction input. Cost O(1)."""
    return (10 * x ** 3 - 15 * x ** 4 + 6 * x ** 5, 30 * x ** 2 * (1 - x) ** 2,
            60 * x * (1 - x) * (1 - 2 * x), 60 - 360 * x + 360 * x * x)


def poly4567(x):
    """The 4-5-6-7 polynomial f = 35x^4 - 84x^5 + 70x^6 - 20x^7. Exact for Fraction input. Cost O(1)."""
    return (35 * x ** 4 - 84 * x ** 5 + 70 * x ** 6 - 20 * x ** 7, 140 * x ** 3 * (1 - x) ** 3,
            420 * x ** 2 * (1 - x) ** 2 * (1 - 2 * x), 840 * x * (1 - x) * (1 - 5 * x + 5 * x * x))


LAWS = {"dwell": dwell, "harmonic": harmonic, "cycloidal": cycloidal, "poly345": poly345, "poly4567": poly4567}


@dataclass(frozen=True)
class Segment:
    """One segment of the cam program: a law, the cam angle beta > 0 and the lift (negative for a return)."""

    law: str
    beta: float
    lift: float


class CamProgram:
    """A full cycle of segments whose angles sum to 2 pi and whose lifts sum to 0.

    Construction costs O(m) for m segments; svaj costs O(log m).
    """

    def __init__(self, segments: Sequence[Segment], tol: float = 1e-9):
        if not segments or any(g.beta <= 0 or g.law not in LAWS for g in segments):
            raise ValueError("each segment needs a known law and a positive angle")
        if abs(sum(g.beta for g in segments) - TWO_PI) > tol:  # @line L1
            raise ValueError("the segment angles must sum to 2 pi")
        if abs(sum(g.lift for g in segments)) > tol * (1 + sum(abs(g.lift) for g in segments)):
            raise ValueError("the lifts must return the follower to its start")
        self.segments = list(segments)
        self.starts: List[float] = []
        self.heights: List[float] = []
        theta, h = 0.0, 0.0
        for g in segments:
            self.starts.append(theta)
            self.heights.append(h)
            theta += g.beta
            h += g.lift

    def segment_at(self, theta: float) -> int:
        """Index i of the segment with start_i <= theta < start_{i+1}, theta taken mod 2 pi."""
        return max(0, bisect.bisect_right(self.starts, theta % TWO_PI) - 1)

    def eval_segment(self, i: int, x: float) -> Tuple[float, float, float, float]:
        """s, ds/dtheta, d2s/dtheta2 and d3s/dtheta3 of segment i at the local parameter x in [0, 1]."""
        g = self.segments[i]
        f, f1, f2, f3 = LAWS[g.law](x)
        b = g.beta
        return self.heights[i] + g.lift * f, g.lift * f1 / b, g.lift * f2 / (b * b), g.lift * f3 / (b ** 3)  # @line L5

    def svaj(self, theta: float) -> Tuple[float, float, float, float]:
        """Displacement and its first three derivatives with respect to the cam angle."""
        t = theta % TWO_PI
        i = self.segment_at(t)  # @line L4
        return self.eval_segment(i, (t - self.starts[i]) / self.segments[i].beta)


def rot_minus(theta: float, p: Vec) -> Vec:
    """R(-theta) p: a point fixed in the ground, seen from the cam turned by theta."""
    c, s = math.cos(theta), math.sin(theta)
    return (c * p[0] + s * p[1], -s * p[0] + c * p[1])


@dataclass(frozen=True)
class RollerSample:
    theta: float
    s: float
    pitch: Vec
    contact: Vec
    pressure_angle: float
    rho: float
    undercut: bool


def roller_sample(prog: CamProgram, theta: float, rb: float, rf: float, eps: float) -> RollerSample:
    """Pitch point, cam point, pressure angle and pitch radius of curvature at one cam angle.

    Precondition: rb > 0, rf >= 0, |eps| < rb + rf. Cost O(log m).
    rho is the signed radius of curvature of the pitch curve (positive where it is convex);
    the sample is flagged as undercut when 0 < rho <= rf.
    """
    rp = rb + rf  # @line L2
    if not (rb > 0 and rf >= 0 and abs(eps) < rp):
        raise ValueError("bad cam size")
    d0 = math.sqrt(rp * rp - eps * eps)
    s, s1, s2, _ = prog.svaj(theta)
    u, w = d0 + s, s1 - eps  # @line L6
    d = math.hypot(u, w)
    pitch = rot_minus(theta, (eps, u))  # @line L7
    contact = rot_minus(theta, (eps + rf * w / d, u - rf * u / d))  # @line L8
    phi = math.atan2(w, u)  # @line L9
    den = u * u + w * (w + s1) - u * s2
    rho = d ** 3 / den if den != 0 else math.inf  # @line L10
    return RollerSample(theta, s, pitch, contact, phi, rho, 0 < rho <= rf)  # @line L11


def roller_profile(prog: CamProgram, rb: float, rf: float, eps: float, n: int) -> List[RollerSample]:
    """Cam profile for a translating roller follower with offset eps, at n equal cam angles.

    Precondition: rb > 0, rf >= 0, |eps| < rb + rf, n >= 1. Cost O(m + n log m).
    """
    if n < 1:
        raise ValueError("n must be positive")
    return [roller_sample(prog, TWO_PI * k / n, rb, rf, eps) for k in range(n)]  # @line L3


@dataclass(frozen=True)
class FlatSample:
    theta: float
    s: float
    contact: Vec
    rho: float
    face_offset: float


def flat_sample(prog: CamProgram, theta: float, rb: float) -> FlatSample:
    """Cam point, radius of curvature and face offset of a flat-faced follower at one cam angle.

    Precondition: rb > 0. Cost O(log m).
    """
    if not rb > 0:
        raise ValueError("bad cam size")
    s, s1, s2, _ = prog.svaj(theta)  # @line L13
    q = rot_minus(theta, (s1, rb + s))  # @line L14
    rho = rb + s + s2  # @line L15
    return FlatSample(theta, s, q, rho, s1)  # @line L16


def flat_faced_profile(prog: CamProgram, rb: float, n: int) -> List[FlatSample]:
    """Cam profile for a translating flat-faced follower with its face square to its axis.

    Precondition: rb > 0, n >= 1. Cost O(m + n log m). The profile is valid when every rho > 0.
    """
    if n < 1:
        raise ValueError("n must be positive")
    return [flat_sample(prog, TWO_PI * k / n, rb) for k in range(n)]  # @line L12
test_cam_profile_synthesis.py 257 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/cam-profile-synthesis/. The authors are listed in prov/59Q72X.jsonl.

import math
import random
import unittest
from fractions import Fraction as F

from cam_profile_synthesis import (
    TWO_PI,
    CamProgram,
    Segment,
    flat_faced_profile,
    flat_sample,
    poly345,
    poly4567,
    roller_profile,
    roller_sample,
    rot_minus,
)

SMOOTH = ["cycloidal", "poly345", "poly4567"]
ALL = SMOOTH + ["harmonic"]


def random_program(rng, laws, max_lift=15.0):
    """Rise, optional dwell, return, optional dwell, each motion at least about 50 degrees."""
    lift = rng.uniform(3.0, max_lift)
    parts = [("rise", rng.uniform(1.0, 2.0)), ("dwell", rng.uniform(0.0, 1.5)),
             ("return", rng.uniform(1.0, 2.0)), ("dwell", rng.uniform(0.0, 1.5))]
    parts = [p for p in parts if p[0] != "dwell" or p[1] > 0.3]
    total = sum(w for _, w in parts)
    segs = []
    for kind, w in parts:
        beta = TWO_PI * w / total
        if kind == "dwell":
            segs.append(Segment("dwell", beta, 0.0))
        else:
            segs.append(Segment(rng.choice(laws), beta, lift if kind == "rise" else -lift))
    # make the angles sum to 2 pi in floating point
    last = segs[-1]
    segs[-1] = Segment(last.law, TWO_PI - sum(g.beta for g in segs[:-1]), last.lift)
    return CamProgram(segs)


def poly_eval(c, x):
    return sum(ci * x ** i for i, ci in enumerate(c))


def poly_der(c):
    return [i * ci for i, ci in enumerate(c)][1:]


def dist(p, q):
    return math.hypot(p[0] - q[0], p[1] - q[1])


def signed_circumradius(a, b, c):
    """Radius of the circle through three points, positive when they turn clockwise."""
    cross = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0])
    return -dist(a, b) * dist(b, c) * dist(a, c) / (2.0 * cross)


class TestLaws(unittest.TestCase):
    def test_polynomial_laws_exact(self):
        rng = random.Random(1)
        for law, coef in ((poly345, [0, 0, 0, 10, -15, 6]), (poly4567, [0, 0, 0, 0, 35, -84, 70, -20])):
            ders = [coef]
            for _ in range(3):
                ders.append(poly_der(ders[-1]))
            for _ in range(200):
                x = F(rng.randint(0, 1000), 1000)
                self.assertEqual(law(x), tuple(poly_eval(d, x) for d in ders))
        self.assertEqual(poly345(F(0)), (0, 0, 0, 60))
        self.assertEqual(poly345(F(1)), (1, 0, 0, 60))
        self.assertEqual(poly4567(F(0)), (0, 0, 0, 0))
        self.assertEqual(poly4567(F(1)), (1, 0, 0, 0))

    def test_derivatives_against_finite_differences(self):
        rng = random.Random(2)
        cases = 0
        while cases < 600:
            prog = random_program(rng, ALL)
            theta = rng.uniform(0, TWO_PI)
            ends = prog.starts + [TWO_PI]
            if min(abs(theta - e) for e in ends) < 1e-3:
                continue
            i = prog.segment_at(theta)
            g = prog.segments[i]
            h = 1e-5
            lo, mid, hi = prog.svaj(theta - h), prog.svaj(theta), prog.svaj(theta + h)
            for k in range(3):
                fd = (hi[k] - lo[k]) / (2 * h)
                scale = abs(g.lift) / g.beta ** (k + 1) + 1.0
                self.assertLess(abs(fd - mid[k + 1]), 1e-6 * scale, (g.law, k))
            fd2 = (hi[0] - 2 * mid[0] + lo[0]) / (h * h)
            self.assertLess(abs(fd2 - mid[2]), 1e-3 * (abs(g.lift) / g.beta ** 2 + 1.0))
            cases += 1

    def test_continuity_at_segment_ends(self):
        rng = random.Random(3)
        for _ in range(500):
            prog = random_program(rng, SMOOTH)
            m = len(prog.segments)
            for i in range(m):
                left = prog.eval_segment(i, 1.0)
                right = prog.eval_segment((i + 1) % m, 0.0)
                scale = 1 + sum(abs(g.lift) / g.beta ** 2 for g in prog.segments)
                for k in range(3):
                    self.assertLess(abs(left[k] - right[k]), 1e-9 * scale, (i, k))

    def test_harmonic_acceleration_jump_at_dwell(self):
        rng = random.Random(4)
        for _ in range(500):
            b1, b2, b3 = rng.uniform(0.5, 2.0), rng.uniform(0.3, 1.5), rng.uniform(0.5, 2.0)
            lift = rng.uniform(1, 20)
            prog = CamProgram([Segment("harmonic", b1, lift), Segment("dwell", b2, 0.0),
                               Segment("harmonic", b3, -lift), Segment("dwell", TWO_PI - b1 - b2 - b3, 0.0)])
            left, right = prog.eval_segment(0, 1.0), prog.eval_segment(1, 0.0)
            self.assertAlmostEqual(left[0], right[0], places=9)
            self.assertAlmostEqual(left[1], right[1], places=9)
            jump = right[2] - left[2]
            self.assertAlmostEqual(jump, math.pi ** 2 * lift / (2 * b1 * b1), places=7)
            start = prog.eval_segment(0, 0.0)
            self.assertAlmostEqual(start[2], math.pi ** 2 * lift / (2 * b1 * b1), places=7)

    def test_rejects_open_programs(self):
        with self.assertRaises(ValueError):
            CamProgram([Segment("cycloidal", math.pi, 10.0), Segment("dwell", math.pi, 0.0)])
        with self.assertRaises(ValueError):
            CamProgram([Segment("cycloidal", 1.0, 10.0), Segment("cycloidal", 1.0, -10.0)])


class TestRollerProfile(unittest.TestCase):
    def test_base_circle(self):
        prog = CamProgram([Segment("dwell", TWO_PI, 0.0)])
        for smp in roller_profile(prog, 30.0, 8.0, 5.0, 64):
            self.assertAlmostEqual(math.hypot(*smp.contact), 30.0, places=9)
            self.assertAlmostEqual(math.hypot(*smp.pitch), 38.0, places=9)

    def test_contact_at_roller_distance_from_pitch_curve(self):
        """Brute force: the nearest point of a dense pitch curve to each cam point is at distance rf."""
        rng = random.Random(5)
        used = 0
        for _ in range(6):
            prog = random_program(rng, SMOOTH)
            rb, rf, eps = rng.uniform(40, 60), rng.uniform(5, 12), rng.uniform(-8, 8)
            n = 180
            prof = roller_profile(prog, rb, rf, eps, n)
            if min(smp.rho for smp in prof) <= rf:
                continue
            dense = roller_profile(prog, rb, rf, eps, 4 * n)
            for smp in prof:
                self.assertAlmostEqual(dist(smp.contact, smp.pitch), rf, places=9)
                near = min(dist(smp.contact, d.pitch) for d in dense)
                self.assertAlmostEqual(near, rf, places=7)
            used += 1
        self.assertGreaterEqual(used, 4)

    def test_contact_is_on_pitch_normal(self):
        rng = random.Random(6)
        for _ in range(500):
            prog = random_program(rng, ALL)
            rb, rf, eps = rng.uniform(30, 60), rng.uniform(3, 12), rng.uniform(-8, 8)
            theta = rng.uniform(0, TWO_PI)
            if min(abs(theta - e) for e in prog.starts + [TWO_PI]) < 1e-4:
                continue
            a = roller_sample(prog, theta - 1e-6, rb, rf, eps)
            b = roller_sample(prog, theta + 1e-6, rb, rf, eps)
            c = roller_sample(prog, theta, rb, rf, eps)
            tangent = (b.pitch[0] - a.pitch[0], b.pitch[1] - a.pitch[1])
            radial = (c.contact[0] - c.pitch[0], c.contact[1] - c.pitch[1])
            cosang = (tangent[0] * radial[0] + tangent[1] * radial[1]) / (math.hypot(*tangent) * rf)
            self.assertLess(abs(cosang), 1e-5)
            # pressure angle: angle of the pitch tangent, turned back to the fixed frame, from the x axis
            back = rot_minus(-theta, tangent)
            self.assertLess(abs(math.atan2(back[1], back[0]) - c.pressure_angle), 1e-6)

    def test_radius_of_curvature_against_three_points(self):
        rng = random.Random(7)
        for _ in range(500):
            prog = random_program(rng, ALL)
            rb, rf, eps = rng.uniform(20, 60), rng.uniform(3, 12), rng.uniform(-8, 8)
            theta = rng.uniform(0, TWO_PI)
            if min(abs(theta - e) for e in prog.starts + [TWO_PI]) < 1e-2:
                continue
            d = 1e-4
            pts = [roller_sample(prog, theta + k * d, rb, rf, eps).pitch for k in (-1, 0, 1)]
            rho = roller_sample(prog, theta, rb, rf, eps).rho
            ref = signed_circumradius(*pts)
            self.assertLess(abs(1 / ref - 1 / rho), 1e-4 / abs(rho) + 1e-6)

    def test_undercut_flag_matches_interference(self):
        """A small cam with a large roller and a fast rise: flagged samples cut into the roller."""
        prog = CamProgram([Segment("cycloidal", math.radians(40), 20.0), Segment("dwell", math.radians(140), 0.0),
                           Segment("cycloidal", math.radians(40), -20.0), Segment("dwell", math.radians(140), 0.0)])
        rb, rf = 10.0, 9.0
        prof = roller_profile(prog, rb, rf, 0.0, 720)
        flagged = [smp for smp in prof if smp.undercut]
        self.assertTrue(flagged)
        worst = min(min(dist(smp.contact, d.pitch) for d in prof) for smp in flagged)
        self.assertLess(worst, rf - 1e-3)
        # a large base circle removes the undercut
        big = roller_profile(prog, 60.0, 9.0, 0.0, 720)
        self.assertFalse(any(smp.undercut for smp in big))


class TestFlatFaced(unittest.TestCase):
    def test_eccentric_circle(self):
        e, rb = 7.0, 25.0
        prog = CamProgram([Segment("harmonic", math.pi, 2 * e), Segment("harmonic", math.pi, -2 * e)])
        for smp in flat_faced_profile(prog, rb, 360):
            self.assertAlmostEqual(dist(smp.contact, (0.0, -e)), rb + e, places=9)
            self.assertAlmostEqual(smp.rho, rb + e, places=9)

    def test_face_supports_cam(self):
        rng = random.Random(8)
        used = 0
        for _ in range(8):
            prog = random_program(rng, ALL)
            rb = rng.uniform(30, 60)
            prof = flat_faced_profile(prog, rb, 720)
            if min(smp.rho for smp in prof) <= 0:
                continue
            for smp in prof[::12]:
                e = rot_minus(smp.theta, (0.0, 1.0))
                h = rb + smp.s
                top = max(q.contact[0] * e[0] + q.contact[1] * e[1] for q in prof)
                self.assertAlmostEqual(smp.contact[0] * e[0] + smp.contact[1] * e[1], h, places=9)
                self.assertLessEqual(top, h + 1e-9)
            used += 1
        self.assertGreaterEqual(used, 5)

    def test_tangency_and_curvature(self):
        rng = random.Random(9)
        done = 0
        while done < 500:
            prog = random_program(rng, ALL)
            rb = rng.uniform(30, 60)
            theta = rng.uniform(0, TWO_PI)
            if min(abs(theta - e) for e in prog.starts + [TWO_PI]) < 1e-2:
                continue
            d = 1e-4
            pts = [flat_sample(prog, theta + k * d, rb).contact for k in (-1, 0, 1)]
            s, s1, s2, _ = prog.svaj(theta)
            e = rot_minus(theta, (0.0, 1.0))
            tang = (pts[2][0] - pts[0][0], pts[2][1] - pts[0][1])
            self.assertLess(abs(tang[0] * e[0] + tang[1] * e[1]), 1e-6 * (1 + math.hypot(*tang)))
            rho = flat_sample(prog, theta, rb).rho
            self.assertAlmostEqual(rho, rb + s + s2, places=9)
            if abs(rho) > 1.0:
                self.assertLess(abs(signed_circumradius(*pts) - rho), 1e-3 * abs(rho))
            done += 1


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

History

The layout of a cam by inversion, in which the follower is drawn at each angle around a fixed cam and the cam outline is drawn to touch every position, is the classic graphical method of the mechanism textbooks. The closed forms for the pitch curve, the profile, the pressure angle and the radius of curvature are the analytic form of the same construction. Norton gives the pressure angle and the radius of curvature for translating followers in Section 8.6 of Design of Machinery, and his handbook also treats the manufacture of cams. Uicker, Pennock and Shigley derive the profile equations for flat-faced and roller followers.

References

  1. Robert L. Norton, Design of Machinery, 6th edition, McGraw-Hill, 2019, Section 8.6 (p. 460, sizing the cam, with the pressure angle of translating roller followers on p. 461, the overturning moment of flat-faced followers on p. 465, the radius of curvature of roller followers on p. 466 and of flat-faced followers on p. 470) and Section 8.7 (p. 475, practical design considerations)
  2. Robert L. Norton, Cam Design and Manufacturing Handbook, 2nd edition, Industrial Press, 2009, the chapters on cam size, pressure angle and radius of curvature, and on cam manufacturing (general locator)
  3. John J. Uicker, Gordon R. Pennock and Joseph E. Shigley, Theory of Machines and Mechanisms, 5th edition, Oxford University Press, 2017, the chapter on cam design, the layout of cam profiles by inversion and the analytic profile equations (general locator)

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 proofH1 sketch
  • a full proof of time.average
  • a full proof of time.best
  • a full proof of time.worst
  • a full proof of space.extra
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
  • History with a source
  • a scene preset for the example