Algorithm Search⌘K

Techniquecore

Freudenstein's equation

Also called Freudenstein equation of the four-bar.

Relates the input and output angles of a four-bar by K1 cos(psi) - K2 cos(phi) + K3 = cos(phi - psi), linear in link ratios, for analysis and function generation.

Freudenstein's equation is the relation between the input angle φ\varphi and the output angle ψ\psi of a four-bar linkage that remains after the coupler angle is eliminated from the vector loop closure equation:

K1cos⁡ψ−K2cos⁡φ+K3=cos⁡(φ−ψ),K1=da,K2=dc,K3=a2−b2+c2+d22ac.K_1\cos\psi - K_2\cos\varphi + K_3 = \cos(\varphi - \psi), \qquad K_1 = \frac{d}{a}, \quad K_2 = \frac{d}{c}, \quad K_3 = \frac{a^2 - b^2 + c^2 + d^2}{2ac}.

For a given linkage it is an equation in the angles, and its half-angle form gives the two assemblies. For given angles it is linear in K1,K2,K3K_1, K_2, K_3, so three pairs of angles give a 3×33 \times 3 linear system whose solution is a four-bar that passes the three pairs exactly. That second use is three-point function generation. Freudenstein published the equation in 1954 and used it for approximate function generation in 1955.

The notation is that of the four-bar page: ground dd from O2=(0,0)O_2 = (0, 0) to O4=(d,0)O_4 = (d, 0), input aa, coupler bb, output cc, and φ=θ2\varphi = \theta_2, ψ=θ4\psi = \theta_4, both counterclockwise from the ground line. The constants above are for this convention, which is the one of Norton. Texts differ in the names and signs of the constants, for example when an angle is measured from the other end of the ground link, so check the convention of a source before you use its constants.

In plain words

A four-bar has an input link and an output link joined by a coupler. If you know the angle of the input link, the angle of the output link is fixed (up to two choices). Freudenstein's equation writes that link between the two angles with three numbers that depend only on the link lengths.

The useful part is the other way round. Suppose you want the output to follow some rule of the input, for example the logarithm. Choose three input angles and the output angles that the rule asks for. Each pair gives one simple equation in the three numbers, so three pairs give three equations that you can solve with school algebra. From the three numbers you get the link lengths. The linkage then meets the rule exactly at those three pairs, and close to it in between.

When it applies

  • The mechanism is a planar four-bar with four pin joints, and the task relates only the input and output angles. This is function generation, one of the three tasks of kinematic synthesis. Path and motion generation need the coupler, which the equation does not see.
  • The angles are absolute: measured from the ground line. In a function generator you choose the start angles φ0,ψ0\varphi_0, \psi_0 and the ranges Δφ,Δψ\Delta\varphi, \Delta\psi, and then map xx and y=f(x)y = f(x) linearly to the angles.
  • You want exact agreement at a few points. Three pairs give a linear system. With φ0\varphi_0 and ψ0\psi_0 also unknown, up to five pairs can be met, but the system is no longer linear.
  • For analysis, the same equation with known lengths gives ψ\psi from φ\varphi, as the vector loop closure page shows.

The template

The holes are the precision pairs (φj,ψj)(\varphi_j, \psi_j) and the ground length dd, which sets the scale.

  1. THREE-POINT-SYNTHESIS((φ1, ψ1), (φ2, ψ2), (φ3, ψ3), d)
  2. 1for j ← 1 to 3: row j of M ← (cos ψj, −cos φj, 1); rj ← cos(φj − ψj)
  3. 2solve M (K1, K2, K3) = r by Gaussian elimination
  4. 3if M is singular or K1 = 0 or K2 = 0 then return "no unique four-bar"
  5. 4a ← d/K1; c ← d/K2
  6. 5b² ← a² + c² + d² − 2ac K3
  7. 6return (a, b², c); it is a real four-bar when b² > 0

Line L1 writes one row per pair, line L2 is Gaussian elimination on a 3×33 \times 3 system, and lines L4 and L5 invert the definitions of the constants. A negative aa or cc is a signed length: that link points the other way, which is length ∣a∣|a| at the angle φ+π\varphi + \pi. If b2≤0b^2 \le 0 no real coupler exists for these pairs. When cos⁡φj\cos\varphi_j and cos⁡ψj\cos\psi_j are rational, as for the points ((1−t2)/(1+t2),2t/(1+t2))((1 - t^2)/(1 + t^2), 2t/(1 + t^2)) of the unit circle with rational tt, every step is exact in rational arithmetic.

Derivation from the loop

The loop is aeiφ+beiθ3−ceiψ−d=0a e^{i\varphi} + b e^{i\theta_3} - c e^{i\psi} - d = 0, with θ3\theta_3 the coupler angle. Put the coupler alone: beiθ3=ceiψ+d−aeiφb e^{i\theta_3} = c e^{i\psi} + d - a e^{i\varphi}. Take the squared modulus of both sides:

b2=a2+c2+d2+2cdcos⁡ψ−2adcos⁡φ−2accos⁡(φ−ψ),b^2 = a^2 + c^2 + d^2 + 2cd\cos\psi - 2ad\cos\varphi - 2ac\cos(\varphi - \psi),

since Re⁡(ceiψ⋅aeiφ‾)=accos⁡(φ−ψ)\operatorname{Re}(c e^{i\psi} \cdot \overline{a e^{i\varphi}}) = ac\cos(\varphi - \psi). Divide by 2ac2ac and move terms:

cos⁡(φ−ψ)=dacos⁡ψ−dccos⁡φ+a2−b2+c2+d22ac,\cos(\varphi - \psi) = \frac{d}{a}\cos\psi - \frac{d}{c}\cos\varphi + \frac{a^2 - b^2 + c^2 + d^2}{2ac},

which is the equation with the stated K1,K2,K3K_1, K_2, K_3. The step is reversible: if (φ,ψ)(\varphi, \psi) satisfies the equation, then ceiψ+d−aeiφc e^{i\psi} + d - a e^{i\varphi} has length bb, so it equals beiθ3b e^{i\theta_3} for one θ3\theta_3 and the loop closes. So the equation holds exactly when the linkage can be assembled with input φ\varphi and output ψ\psi. ■\blacksquare

Why the synthesis is correct

Suppose line L2 finds KK with K1,K2≠0K_1, K_2 \ne 0, and b2>0b^2 > 0 in line L5. Lines L4 and L5 give lengths whose constants are exactly K1=d/aK_1 = d/a, K2=d/cK_2 = d/c and K3=(a2−b2+c2+d2)/(2ac)K_3 = (a^2 - b^2 + c^2 + d^2)/(2ac), because L5 is the definition of K3K_3 solved for b2b^2. Each pair satisfies row jj of the system, which is the equation for these lengths. By the reverse step of the derivation the linkage can be assembled at each pair. The tests check this with exact rational arithmetic on random rational pairs: the identity and ∣B−A∣2=b2|B - A|^2 = b^2 hold exactly at all three pairs.

What the proof does not give: the three assemblies can be on different branches, or on different circuits of a non-Grashof linkage. Then the linkage passes the pairs only if it is taken apart and put together again. Check the branch at each pair, as the pitfalls say.

Cost

One synthesis is a fixed number of operations. With m>3m > 3 pairs the system is overdetermined, and a least-squares solution costs O(m)O(m).

Classic examples

An exact example with integer pins. Take the input angles with tan⁡(φj/2)=1/3,1/2,1\tan(\varphi_j/2) = 1/3, 1/2, 1, which are 36.87°36.87°, 53.13°53.13°, 90°90°, and the output angles with tan⁡(ψj/2)=1/2,2/3,3/2\tan(\psi_j/2) = 1/2, 2/3, 3/2, which are 53.13°53.13°, 67.38°67.38°, 112.62°112.62°, and d=9d = 9. Then (cos⁡φj,sin⁡φj)(\cos\varphi_j, \sin\varphi_j) is (4/5,3/5)(4/5, 3/5), (3/5,4/5)(3/5, 4/5), (0,1)(0, 1) and (cos⁡ψj,sin⁡ψj)(\cos\psi_j, \sin\psi_j) is (3/5,4/5)(3/5, 4/5), (5/13,12/13)(5/13, 12/13), (−5/13,12/13)(-5/13, 12/13). The system

(3/5−4/515/13−3/51−5/1301)(K1K2K3)=(24/2563/6512/13)\begin{pmatrix} 3/5 & -4/5 & 1 \\ 5/13 & -3/5 & 1 \\ -5/13 & 0 & 1 \end{pmatrix} \begin{pmatrix} K_1 \\ K_2 \\ K_3 \end{pmatrix} = \begin{pmatrix} 24/25 \\ 63/65 \\ 12/13 \end{pmatrix}

has the solution K1=3/5K_1 = 3/5, K2=9/13K_2 = 9/13, K3=15/13K_3 = 15/13. So a=15a = 15, c=13c = 13, and b2=225+169+81−2⋅15⋅13⋅15/13=25b^2 = 225 + 169 + 81 - 2 \cdot 15 \cdot 13 \cdot 15/13 = 25, b=5b = 5. The pins at the three pairs are:

pair A=aeiφA = a e^{i\varphi} B=d+ceiψB = d + c e^{i\psi} B−AB - A ∣B−A∣\lvert B - A\rvert
1 (12,9)(12, 9) (84/5,52/5)(84/5, 52/5) (24/5,7/5)(24/5, 7/5) 5
2 (9,12)(9, 12) (14,12)(14, 12) (5,0)(5, 0) 5
3 (0,15)(0, 15) (4,12)(4, 12) (4,−3)(4, -3) 5

The linkage (a,b,c,d)=(15,5,13,9)(a, b, c, d) = (15, 5, 13, 9) is a Grashof double-rocker by the Grashof condition: 5+15≤13+95 + 15 \le 13 + 9 and the coupler is the shortest link. Its input rocks between about 26.3°26.3° and 93.8°93.8°, and all three pairs lie on the open branch of that interval, so it moves through them without being taken apart.

A logarithm generator. Let y=log⁡10xy = \log_{10} x for 1≤x≤21 \le x \le 2, with φ\varphi from 90°90° to 150°150° and ψ\psi from 15°15° to 75°75°, and d=1d = 1. The Chebyshev spacing of three points, xj=1.5−0.5cos⁡((2j−1)π/6)x_j = 1.5 - 0.5\cos((2j - 1)\pi/6), gives x=1.06699x = 1.06699, 1.51.5, 1.933011.93301 and the pairs (94.019°,20.613°)(94.019°, 20.613°), (120°,50.098°)(120°, 50.098°), (145.981°,72.051°)(145.981°, 72.051°). The solution is K=(1.02934,0.84016,−0.73676)K = (1.02934, 0.84016, -0.73676) and a=0.97149a = 0.97149, b=2.25042b = 2.25042, c=1.19026c = 1.19026. Measured on a grid of 2001 values of xx along the open branch, the largest structural error, the difference between the output angle and the ideal one, is 0.061°0.061° at x=1x = 1. With equally spaced points 1.25,1.5,1.751.25, 1.5, 1.75 it is 0.167°0.167°. The end errors of the Chebyshev design (0.061°0.061° and 0.046°0.046°) are not equal to the inner peaks (0.015°0.015°, 0.008°0.008° and 0.038°0.038°, with one more zero of the error near x=1.276x = 1.276), so this spacing reduces the error here but it is not the minimax design.

Position analysis. For a given linkage, write the equation as Pcos⁡ψ+Qsin⁡ψ+R=0P\cos\psi + Q\sin\psi + R = 0 and substitute t=tan⁡(ψ/2)t = \tan(\psi/2). The result is the quadratic whose two roots are the open and crossed assemblies, as proved on the vector loop closure page.

Synthesis with more conditions. Kinematic synthesis needs more than three pairs when the range must be met more closely. Least squares on the equation residual is linear, and optimization-based linkage synthesis minimizes the true structural error instead.

Variations

  • More than three pairs. With m>3m > 3 pairs, solve the normal equations of the m×3m \times 3 system. This minimizes the residual of the equation, which is not the angle error, so the result is only a good start for a local search.
  • Free start angles. With φ0\varphi_0 and ψ0\psi_0 unknown, four or five pairs can be met exactly, and the equations become polynomial in cos⁡φ0,sin⁡φ0,cos⁡ψ0,sin⁡ψ0\cos\varphi_0, \sin\varphi_0, \cos\psi_0, \sin\psi_0.
  • Derivative conditions. Instead of three separate pairs, ask that the linkage match ff and its first derivatives at one point (infinitesimally close precision points). Differentiating the equation in φ\varphi gives linear equations in the same K1,K2,K3K_1, K_2, K_3.
  • The slider-crank. The same elimination for a slider-crank mechanism relates the crank angle to the slider position, and gives a linear system for crank-angle to slider-position generators.

Pitfalls

  • The wrong sign convention. If the source measures ψ\psi from the other end of the ground, or calls the input ψ\psi, the constants change sign or swap. Constants from one source in the equation of another give a linkage that fails all three pairs. Derive the constants from the loop of your own figure, as above.
  • Branch defect. Line L6 proves only that each pair can be assembled. Check that all pairs are on one branch and one circuit, for example with the branch sign of the vector loop closure page, before you accept the design.
  • Order defect and poor transmission. The linkage may pass the pairs in the wrong order, or only with a small transmission angle. Check both over the full range, not only at the pairs.
  • Singular or useless systems. Repeated pairs, or two pairs with equal cos⁡ψj\cos\psi_j and equal cos⁡φj\cos\varphi_j, make MM singular. A tiny K1K_1 or K2K_2 gives very long links. Choose the ranges Δφ\Delta\varphi, Δψ\Delta\psi and the start angles again.

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.

freudenstein_equation.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/freudenstein-equation/. The authors are listed in prov/Z9SNZM.jsonl.

"""Three-point function generation with Freudenstein's equation.

Four-bar notation (Norton): ground d from O2 = (0, 0) to O4 = (d, 0), input a,
coupler b, output c. phi is the input angle theta2 and psi the output angle
theta4, both counterclockwise from the ground line. The equation is

    K1 cos(psi) - K2 cos(phi) + K3 = cos(phi - psi),
    K1 = d/a,  K2 = d/c,  K3 = (a^2 - b^2 + c^2 + d^2) / (2 a c).

It is linear in K1, K2, K3, so three pairs (phi_j, psi_j) give a 3 x 3 linear
system. A precision point is passed as (cos phi, sin phi, cos psi, sin psi).
With Fraction values (rational points on the unit circle) every step is exact.
A negative a or c is a signed length: the link points the other way, which is
the same as length |a| at the angle phi + pi.
"""

import math
from fractions import Fraction


def solve_linear(m, rhs, tol=1e-12):
    """Solve m x = rhs by Gaussian elimination with partial pivoting.

    m is a list of n rows of n numbers (int, Fraction or float). Returns the
    list x, or None when the matrix is singular: an exact zero pivot for exact
    numbers, a pivot below tol times the largest entry for floats. O(n^3).
    """
    n = len(m)
    a = [list(row) + [r] for row, r in zip(m, rhs)]
    exact = all(isinstance(v, (int, Fraction)) for row in a for v in row)
    big = max((abs(v) for row in m for v in row), default=0)
    for col in range(n):
        piv = max(range(col, n), key=lambda r: abs(a[r][col]))
        if a[piv][col] == 0 or (not exact and abs(a[piv][col]) <= tol * big):
            return None
        a[col], a[piv] = a[piv], a[col]
        for r in range(col + 1, n):
            f = a[r][col] / a[col][col]
            if f:
                for k in range(col, n + 1):
                    a[r][k] -= f * a[col][k]
    x = [0] * n
    for r in range(n - 1, -1, -1):
        s = a[r][n] - sum(a[r][k] * x[k] for k in range(r + 1, n))
        x[r] = s / a[r][r]
    return x


def three_point_synthesis(points, d):
    """The four-bar whose input and output angles pass the three precision points.

    points: three tuples (cos phi, sin phi, cos psi, sin psi). d: the ground
    length. Returns (a, b_squared, c, (K1, K2, K3)), or None when the system is
    singular or a K is zero. b_squared <= 0 means that no real coupler exists.
    Exact for Fraction input. O(1).
    """
    rows, rhs = [], []
    for cphi, sphi, cpsi, spsi in points:
        rows.append([cpsi, -cphi, 1])  # @line L1
        rhs.append(cphi * cpsi + sphi * spsi)
    k = solve_linear(rows, rhs)  # @line L2
    if k is None or k[0] == 0 or k[1] == 0:  # @line L3
        return None
    k1, k2, k3 = k
    a, c = d / k1, d / k2  # @line L4
    b_squared = a * a + c * c + d * d - 2 * a * c * k3  # @line L5
    return a, b_squared, c, (k1, k2, k3)  # @line L6


def unit_point(phi, psi):
    """(cos phi, sin phi, cos psi, sin psi) for float angles in radians."""
    return math.cos(phi), math.sin(phi), math.cos(psi), math.sin(psi)


def rational_unit(t):
    """The exact point ((1 - t^2)/(1 + t^2), 2t/(1 + t^2)) of the unit circle, t = tan(angle/2)."""
    t = Fraction(t)
    return (1 - t * t) / (1 + t * t), 2 * t / (1 + t * t)


def function_generator(f, x0, x1, xs, phi0, dphi, psi0, dpsi, d=1.0):
    """Three-point synthesis of a four-bar for y = f(x) on [x0, x1].

    The input angle is phi = phi0 + dphi (x - x0)/(x1 - x0) and the output angle
    is psi = psi0 + dpsi (f(x) - f(x0))/(f(x1) - f(x0)), in radians. xs holds the
    three precision points. Returns the result of three_point_synthesis.
    """
    y0, y1 = f(x0), f(x1)
    pts = []
    for x in xs:
        phi = phi0 + dphi * (x - x0) / (x1 - x0)
        psi = psi0 + dpsi * (f(x) - y0) / (y1 - y0)
        pts.append(unit_point(phi, psi))
    return three_point_synthesis(pts, d)
test_freudenstein_equation.py 177 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/freudenstein-equation/. The authors are listed in prov/Z9SNZM.jsonl.

import math
import random
import unittest
from fractions import Fraction

from freudenstein_equation import (
    function_generator,
    rational_unit,
    solve_linear,
    three_point_synthesis,
    unit_point,
)


def det3(m):
    return (m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1])
            - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0])
            + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]))


def cramer3(m, r):
    """Oracle: Cramer's rule for a 3 x 3 system."""
    dm = det3(m)
    if dm == 0:
        return None
    out = []
    for k in range(3):
        mk = [row[:k] + [r[i]] + row[k + 1:] for i, row in enumerate(m)]
        out.append(det3(mk) / dm)
    return out


def circle_points(a, b, c, d, phi):
    """Oracle for positions: the points B at distance |b| from A and |c| from O4 = (d, 0)."""
    ax, ay = a * math.cos(phi), a * math.sin(phi)
    dx, dy = d - ax, -ay
    dist = math.hypot(dx, dy)
    rb, rc = abs(b), abs(c)
    if dist == 0 or dist > rb + rc or dist < abs(rb - rc):
        return []
    along = (rb * rb - rc * rc + dist * dist) / (2 * dist)
    h = math.sqrt(max(rb * rb - along * along, 0.0))
    mx, my = ax + along * dx / dist, ay + along * dy / dist
    return [(mx - h * dy / dist, my + h * dx / dist), (mx + h * dy / dist, my - h * dx / dist)]


def random_rational(rng, lo=-3, hi=3):
    return Fraction(rng.randint(lo * 6, hi * 6), rng.randint(1, 6))


class TestLinearSolver(unittest.TestCase):
    def test_against_cramer(self):
        rng = random.Random(1955)
        singular = 0
        for _ in range(600):
            m = [[Fraction(rng.randint(-3, 3)) for _ in range(3)] for _ in range(3)]
            r = [Fraction(rng.randint(-5, 5)) for _ in range(3)]
            want = cramer3(m, r)
            got = solve_linear(m, r)
            self.assertEqual(got, want)
            singular += want is None
        self.assertGreater(singular, 10)


class TestThreePointExact(unittest.TestCase):
    def test_worked_example(self):
        # phi: t = 1/3, 1/2, 1 (36.87, 53.13, 90 degrees); psi: t = 1/2, 2/3, 3/2 (53.13, 67.38, 112.62 degrees)
        pts = [rational_unit(p) + rational_unit(q)
               for p, q in zip((Fraction(1, 3), Fraction(1, 2), 1), (Fraction(1, 2), Fraction(2, 3), Fraction(3, 2)))]
        a, b2, c, k = three_point_synthesis(pts, Fraction(9))
        self.assertEqual(k, (Fraction(3, 5), Fraction(9, 13), Fraction(15, 13)))
        self.assertEqual((a, b2, c), (15, 25, 13))
        pins = []
        for cphi, sphi, cpsi, spsi in pts:
            pa = (a * cphi, a * sphi)
            pb = (9 + c * cpsi, c * spsi)
            self.assertEqual((pb[0] - pa[0]) ** 2 + (pb[1] - pa[1]) ** 2, 25)
            pins.append((pa, pb))
        self.assertEqual(pins[0], ((12, 9), (Fraction(84, 5), Fraction(52, 5))))
        self.assertEqual(pins[1], ((9, 12), (14, 12)))
        self.assertEqual(pins[2], ((0, 15), (4, 12)))

    def test_random_exact_points(self):
        rng = random.Random(1878)
        checked = 0
        for _ in range(700):
            ts = [random_rational(rng) for _ in range(6)]
            pts = [rational_unit(ts[j]) + rational_unit(ts[j + 3]) for j in range(3)]
            d = Fraction(rng.randint(1, 20), rng.randint(1, 5))
            res = three_point_synthesis(pts, d)
            if res is None:
                continue
            a, b2, c, (k1, k2, k3) = res
            for cphi, sphi, cpsi, spsi in pts:
                # the equation holds exactly
                self.assertEqual(k1 * cpsi - k2 * cphi + k3, cphi * cpsi + sphi * spsi)
                # and the loop closes exactly: |B - A|^2 = b^2 with signed lengths a and c
                pa = (a * cphi, a * sphi)
                pb = (d + c * cpsi, c * spsi)
                self.assertEqual((pb[0] - pa[0]) ** 2 + (pb[1] - pa[1]) ** 2, b2)
            checked += 1
        self.assertGreater(checked, 500)

    def test_repeated_point_is_singular(self):
        p = rational_unit(Fraction(1, 2)) + rational_unit(Fraction(1, 3))
        q = rational_unit(1) + rational_unit(2)
        self.assertIsNone(three_point_synthesis([p, p, q], Fraction(1)))


class TestThreePointFloat(unittest.TestCase):
    def test_linkage_passes_the_points(self):
        rng = random.Random(77)
        checked = 0
        for _ in range(800):
            phis = [rng.uniform(0, 2 * math.pi) for _ in range(3)]
            psis = [rng.uniform(0, 2 * math.pi) for _ in range(3)]
            d = rng.uniform(0.5, 5.0)
            res = three_point_synthesis([unit_point(p, q) for p, q in zip(phis, psis)], d)
            if res is None:
                continue
            a, b2, c, _ = res
            if b2 <= 0 or max(abs(a), abs(c), b2) > 1e4:
                continue
            b = math.sqrt(b2)
            scale = abs(a) + b + abs(c) + d
            for phi, psi in zip(phis, psis):
                want = (d + c * math.cos(psi), c * math.sin(psi))
                pts = circle_points(a, b, c, d, phi)
                self.assertTrue(pts, (a, b, c, d, phi))
                gap = min(math.hypot(x - want[0], y - want[1]) for x, y in pts)
                self.assertLess(gap, 1e-6 * scale)
            checked += 1
        self.assertGreater(checked, 500)

    def test_log_function_generator(self):
        f, x0, x1 = math.log10, 1.0, 2.0
        phi0, dphi, psi0, dpsi = map(math.radians, (90, 60, 15, 60))
        cheb = [1.5 - 0.5 * math.cos((2 * j - 1) * math.pi / 6) for j in (1, 2, 3)]
        errors = {}
        for name, xs in (("chebyshev", cheb), ("equal", [1.25, 1.5, 1.75])):
            a, b2, c, _ = function_generator(f, x0, x1, xs, phi0, dphi, psi0, dpsi, 1.0)
            b = math.sqrt(b2)
            if name == "chebyshev":
                self.assertAlmostEqual(a, 0.97149, places=4)
                self.assertAlmostEqual(b, 2.25042, places=4)
                self.assertAlmostEqual(c, 1.19026, places=4)
            # follow the output pin B continuously from the first precision point
            x_start = xs[0]
            phi = phi0 + dphi * (x_start - x0)
            psi = psi0 + dpsi * (f(x_start) - f(x0)) / (f(x1) - f(x0))
            last = (1.0 + c * math.cos(psi), c * math.sin(psi))
            worst = 0.0
            grid = sorted(set([x0 + i * (x1 - x0) / 2000 for i in range(2001)] + xs))
            k0 = grid.index(x_start)
            for path in (grid[k0:], grid[k0::-1]):
                pin = last
                for x in path:
                    phi = phi0 + dphi * (x - x0)
                    pts = circle_points(a, b, c, 1.0, phi)
                    self.assertTrue(pts)
                    pin = min(pts, key=lambda p: math.hypot(p[0] - pin[0], p[1] - pin[1]))
                    got = math.atan2(pin[1], pin[0] - 1.0)
                    ideal = psi0 + dpsi * (f(x) - f(x0)) / (f(x1) - f(x0))
                    err = abs(math.remainder(got - ideal, 2 * math.pi))
                    if any(abs(x - p) < 1e-12 for p in xs):
                        self.assertLess(err, 1e-9)
                    worst = max(worst, err)
            errors[name] = math.degrees(worst)
        self.assertAlmostEqual(errors["chebyshev"], 0.0608, places=3)
        self.assertAlmostEqual(errors["equal"], 0.1670, places=3)


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

Exercises

  1. Check the three rows of the exact example by hand, and find the open and crossed values of ψ\psi for the linkage (15,5,13,9)(15, 5, 13, 9) at φ=60°\varphi = 60°.
  2. Derive the constants of the equation when ψ\psi is measured clockwise from the line O4O2O_4 O_2 instead of counterclockwise from O2O4O_2 O_4.
  3. Design a three-point generator for y=x2y = x^2, 0≤x≤10 \le x \le 1, with Δφ=Δψ=90°\Delta\varphi = \Delta\psi = 90°, and measure its structural error on a grid.
  4. Show that the matrix of line L1 is singular when two pairs have the same cos⁡φ\cos\varphi and the same cos⁡ψ\cos\psi. When is the system then still solvable?
  5. Write the linear system for the case of one exact pair and the first and second derivatives of ψ(φ)\psi(\varphi) at that pair.

References

  1. Ferdinand Freudenstein, An analytical approach to the design of four-link mechanisms, Transactions of the ASME 76(3), 1954, 483 to 492, the displacement equation of the four-bar in link ratios and its use for design
  2. Ferdinand Freudenstein, Approximate synthesis of four-bar linkages, Transactions of the ASME 77(8), 1955, 853 to 861, function generation with precision points and the structural error
  3. Robert L. Norton, Design of Machinery, 6th edition, McGraw-Hill, 2019, Section 4.5 (p. 187, the equation from the vector loop), Section 5.13 (p. 267, analytical synthesis of a fourbar function generator)
  4. Arthur G. Erdman, George N. Sandor and Sridhar Kota, Mechanism Design, Analysis and Synthesis, Volume 1, 4th edition, Prentice Hall, 2001, the chapter on analytical synthesis of function generators
  5. J. Michael McCarthy and Gim Song Soh, Geometric Design of Linkages, 2nd edition, Springer, 2011, Chapter 2 (pp. 15 to 53), the output angle of the planar 4R linkage

Where this leads

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