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 and the output angle of a four-bar linkage that remains after the coupler angle is eliminated from the vector loop closure equation:
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 , so three pairs of angles give a 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 from to , input , coupler , output , and , , 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 and the ranges , and then map and linearly to the angles.
- You want exact agreement at a few points. Three pairs give a linear system. With and 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 from , as the vector loop closure page shows.
The template
The holes are the precision pairs and the ground length , which sets the scale.
THREE-POINT-SYNTHESIS((φ1, ψ1), (φ2, ψ2), (φ3, ψ3), d)- 1
for j ← 1 to 3: row j of M ← (cos ψj, −cos φj, 1); rj ← cos(φj − ψj) - 2
solve M (K1, K2, K3) = r by Gaussian elimination - 3
if M is singular or K1 = 0 or K2 = 0 then return "no unique four-bar" - 4
a ← d/K1; c ← d/K2 - 5
b² ← a² + c² + d² − 2ac K3 - 6
return (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 system, and lines L4 and L5 invert the definitions of the constants. A negative or is a signed length: that link points the other way, which is length at the angle . If no real coupler exists for these pairs. When and are rational, as for the points of the unit circle with rational , every step is exact in rational arithmetic.
Derivation from the loop
The loop is , with the coupler angle. Put the coupler alone: . Take the squared modulus of both sides:
since . Divide by and move terms:
which is the equation with the stated . The step is reversible: if satisfies the equation, then has length , so it equals for one and the loop closes. So the equation holds exactly when the linkage can be assembled with input and output .
Why the synthesis is correct
Suppose line L2 finds with , and in line L5. Lines L4 and L5 give lengths whose constants are exactly , and , because L5 is the definition of solved for . Each pair satisfies row 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 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 pairs the system is overdetermined, and a least-squares solution costs .
Classic examples
An exact example with integer pins. Take the input angles with , which are , , , and the output angles with , which are , , , and . Then is , , and is , , . The system
has the solution , , . So , , and , . The pins at the three pairs are:
| pair | ||||
|---|---|---|---|---|
| 1 | 5 | |||
| 2 | 5 | |||
| 3 | 5 |
The linkage is a Grashof double-rocker by the Grashof condition: and the coupler is the shortest link. Its input rocks between about and , 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 for , with from to and from to , and . The Chebyshev spacing of three points, , gives , , and the pairs , , . The solution is and , , . Measured on a grid of 2001 values of along the open branch, the largest structural error, the difference between the output angle and the ideal one, is at . With equally spaced points it is . The end errors of the Chebyshev design ( and ) are not equal to the inner peaks (, and , with one more zero of the error near ), so this spacing reduces the error here but it is not the minimax design.
Position analysis. For a given linkage, write the equation as and substitute . 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 pairs, solve the normal equations of the 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 and unknown, four or five pairs can be met exactly, and the equations become polynomial in .
- Derivative conditions. Instead of three separate pairs, ask that the linkage match and its first derivatives at one point (infinitesimally close precision points). Differentiating the equation in gives linear equations in the same .
- 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 from the other end of the ground, or calls the input , 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 and equal , make singular. A tiny or gives very long links. Choose the ranges , 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.
# 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
- Check the three rows of the exact example by hand, and find the open and crossed values of for the linkage at .
- Derive the constants of the equation when is measured clockwise from the line instead of counterclockwise from .
- Design a three-point generator for , , with , and measure its structural error on a grid.
- Show that the matrix of line L1 is singular when two pairs have the same and the same . When is the system then still solvable?
- Write the linear system for the case of one exact pair and the first and second derivatives of at that pair.
References
- 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
- 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
- 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)
- 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag Z9SNZM Edit this page History Report an error Markdown