One Input Angle Can Give a Four-Bar Linkage Two Assemblies

Download and extract the reader ZIP archive (a compressed collection of files). Links labelled โ€œreader ZIP; extract โ€ฆโ€ download this archive; after extraction, open the named file. It includes the offline article, full-size Portable Network Graphics (PNG) images, editable Scalable Vector Graphics (SVG) diagrams, complete source code, tests and worksheets.

Draw a two-centimetre input link at 60ยฐ. That fixes its endpoint, but it does not always fix the rest of a closed linkage. In this experiment two different positions of one joint satisfy exactly the same four bar lengths. A solver that returns only the first position has silently chosen an assembly.

A four-bar linkage is a closed chain of four ideal rigid links joined end to end. An ideal pin joint is a hinge that permits relative rotation while keeping the joined endpoints together. The ground link is the link held fixed. We solve positions in one plane using paper geometry and code; no linkage was manufactured or driven.

Set the geometry before choosing a solution

Use paper, a ruler, a compass, a pencil and Python 3.9 or later. A compass here is the drawing tool for circles, not a magnetic sensor. The code and behavior tests use only Python’s standard library. CPython, Python’s reference implementation, was used for the recorded host runs. Lengths are in centimetres (cm); the input angle ฮธ (theta) is measured in degrees counterclockwise from the positive horizontal axis.

  • Fix A=(0,0) and D=(4,0). The ground link AD is 4 cm.
  • Make the input AB=2 cm, the coupler BC=3 cm and the output CD=2.5 cm. The coupler is the moving link between B and C; it does not attach directly to ground.
  • At ฮธ=60ยฐ, place B=(2cosฮธ,2sinฮธ)=(1,โˆš3) cm. Cosine and sine give the horizontal and vertical components of a unit direction; multiply them by AB to locate B.
  • Draw a circle centred at B with radius 3 cm and another centred at D with radius 2.5 cm. Every intersection is a candidate C because it is the required distance from both centres.
Two complete calculated four-bar assemblies share input angle sixty degrees and lengths two, three, two-point-five and four centimetres. The negative branch crosses ground without a joint.
Original calculated geometry at 60ยฐ. Only the four labelled circles in each panel are joints. The separated crossing of BC and AD on the negative branch is not an extra pin. Scale bars describe the model coordinate scale; screen or print enlargement changes physical size. Full-size Portable Network Graphics (PNG) image ยท Editable Scalable Vector Graphics (SVG) source โ€” reader ZIP; extract assets/two-fourbar-assemblies.svg.

Calculate both intersections and name their branches

Let d be the centre distance |Dโˆ’B|, r=BC=3 and s=CD=2.5. Define the unit direction e=(Dโˆ’B)/d, pointing from B to D, and the perpendicular direction n=(โˆ’e_y,e_x), turned counterclockwise through 90ยฐ. For dโ‰ 0, subtracting the two circle equations gives the distance a from B to the common chord’s midpoint along e:

a=(rยฒโˆ’sยฒ+dยฒ)/(2d), hยฒ=rยฒโˆ’aยฒ, Cยฑ=B+a eยฑh n. The chord joins the two circle intersections; its half-length h is a perpendicular distance. The program evaluates hยฒ with an equivalent factored expression, ((r+sโˆ’d)(r+s+d)(dโˆ’|rโˆ’s|)(d+|rโˆ’s|))/(4dยฒ), after checking whether intersections can exist.

The axial calculation evaluates rยฒโˆ’sยฒ as (rโˆ’s)(r+s), avoiding the subtraction of nearly equal large squares before dividing by a small centre distance.

A branch is one signed family of positions. Define its sign using the planar cross product, the signed scalar cross(Dโˆ’B,Cโˆ’B)=(Dโ‚“โˆ’Bโ‚“)(Cแตงโˆ’Bแตง)โˆ’(Dแตงโˆ’Bแตง)(Cโ‚“โˆ’Bโ‚“). Positive means the + branch, negative the โˆ’ branch. The sign is relative to the oriented line Bโ†’D, not simply whether C is above the horizontal axis. It has units cmยฒ and is used as a geometric label, not a torque.

ฮธ=60ยฐ result Cโ‚“ (cm) Cแตง (cm) cross(Dโˆ’B,Cโˆ’B) (cmยฒ)
+ branch 3.900566909 2.498021829 +7.321842323
โˆ’ branch 1.786933091 โˆ’1.162899332 โˆ’7.321842323

For each C the model also reports two closure residuals: calculated |Cโˆ’B| minus 3 cm, and calculated |Cโˆ’D| minus 2.5 cm. They are about 4.4ร—10โปยนโถ cm or zero in the recorded run. These tiny values describe floating-point arithmetic error in the calculation, not physical precision or manufacturing tolerance.

Find the boundary without inventing an impossible assembly

Two distinct circle intersections require |rโˆ’s|<d<r+s. At either equality the circles are tangent, touching at one point. If d>r+s the circles are separate; if d<|rโˆ’s| one lies strictly inside the other. Neither case has a real intersection. Equal centres and equal radii instead give coincident circles, sharing every point: infinitely many possibilities, not a single chosen point.

In the prescribed linkage, dยฒ=(4โˆ’2cosฮธ)ยฒ+(2sinฮธ)ยฒ=20โˆ’16cosฮธ. Since d never drops below 2 cm, the inner boundary |3โˆ’2.5|=0.5 cm is never reached. The relevant outer boundary is d=3+2.5=5.5 cm. Therefore cosฮธ=(20โˆ’30.25)/16=โˆ’0.640625, giving ฮธโ‰ˆ129.838439977ยฐ in the displayed 0ยฐโ€ฆ180ยฐ range. At this input the two signed positions meet at one tangent. At ฮธ=180ยฐ, d=6 cm>5.5 cm, so the ideal assembly does not exist.

Calculated signed perpendicular branch offsets versus input angle from zero to one hundred eighty degrees. Both curves meet at about one hundred twenty-nine-point-eight degrees; the remaining region has no real assembly.
Original code-derived position graph. The vertical coordinate is signed perpendicular distance from line BD, not C’s vertical page coordinate. Both branches approach zero at tangency. No point is plotted in the grey impossible region. Full-size PNG ยท Editable SVG โ€” reader ZIP; extract assets/fourbar-branch-boundary.svg.

The graph displays only 0ยฐโ€ฆ180ยฐ. The trigonometric geometry repeats every 360ยฐ; this is not a claim that the input can rotate through every angle while a physical linkage remains assembled. On a real mechanism the boundary may prevent further input motion. Our positional model does not calculate the effort or deformation that would result.

Run the paper and software controls

  1. Draw the fixed points and both circles at ฮธ=60ยฐ. Mark both C positions before connecting Aโ€“Bโ€“Cโ€“Dโ€“A. Label each with the cross-product sign. Do not put a pin symbol where links merely cross.
  2. Extract the reader into one directory and run the commands below. A command-line interface (CLI) is a program controlled by typed commands. The file uses JavaScript Object Notation (JSON), a text format of named fields and lists; model lengths are parameters, and every numeric angle supplied in this experiment is explicitly constructed.
  3. Confirm classification two and two opposite signs for the baseline. Check both residuals on both positions, rather than checking only one bar.
  4. Use the constructed zero-angle control: it still has two positions. Approach the boundary with 120ยฐ,125ยฐ,129ยฐ,129.8ยฐ and 129.83ยฐ, retaining the same sign as you compare successive positions. The branch separation shrinks; a single input angle still does not select the starting branch.
  5. At the calculated critical angle expect one numerical tangent. At180ยฐ expect none and an empty points list. Restore60ยฐ and confirm the two original positions return.
  6. Run the blank observation template: its unknown angle yields unknown and points:null. This differs from a constructed impossible angle, whose known geometry yields none and points:[]. Never turn an unknown angle into 0ยฐ.
python3 -B -m unittest -v test_fourbar_lab
python3 -B fourbar_lab.py data/constructed-angles.json
python3 -B fourbar_lab.py data/blank-observations.json
python3 -B fourbar_lab.py data/malformed-angle.json
python3 -B fourbar_lab.py data/constructed-angles.json
python3 -B generate_figures.py

The recorded host run passed 30 behavior tests. Tests cover both closure distances, both signs, external/internal tangency, separation/nesting, coincident circles, branch tracking near the boundary, reflection/periodicity, malformed/nonfinite inputs, units, duplicate records, blank unknowns and the actual CLI. This is software execution of a declared geometric model; no target firmware, motion hardware or manufactured linkage was tested.

Arithmetic, numerical tolerance and complete code

The model uses Python’s binary64 floating-point numbers: finite-precision binary approximations, not exact symbolic geometry. It accepts lengths from 10โปโถ to 10โถ cm, coordinate magnitudes and angle magnitudes up to 10โถ, at most 512 records and 1,000,000 input bytes. The reusable circle routine rejects nonzero centre separations below 10โปโน cm. Its default absolute numerical tangency tolerance is 10โปโน cm of transverse height h; within the closed intersection interval it reports a single numerical tangent when h is that small. This is an algorithmic classification threshold, not a clearance allowance.

Before returning any position, the code checks both closure residuals against the larger of the selected tolerance and 64 units in the last place (ULPs) at the coordinate/length scale, with a 1 cm minimum scale for this numerical budget. A ULP is the spacing between adjacent floating-point numbers at that scale. If either residual exceeds the budget, calculation fails explicitly; it does not report an inaccurate assembly. This numerical guard is not a physical-accuracy claim.

The outer and inner impossibility tests are strict and run first. Even a supplied d that exceeds r+s by 10โปยนยฒ cm returns none; the code never changes a negative geometric possibility into zero height. Near a boundary, rounding an input angle may change a classification. Report the actual input and residuals rather than claiming certainty about an exactly tangent physical mechanism. The one result represents numerical coalescence under the stated tolerance.

Full fourbar_lab.py source
#!/usr/bin/env python3
"""Ideal planar four-bar position model, centimetres and constructed angles."""
import argparse
import json
import math
from pathlib import Path
import re
import sys

ABS_TOL_CM = 1e-9
MAX_BYTES = 1_000_000
ID = re.compile(r"[A-Za-z0-9_-]{1,40}\Z")


def number(value, name, positive=False):
    if isinstance(value, bool) or not isinstance(value, (int, float)):
        raise ValueError(name + " must be a finite number")
    try:
        result = float(value)
    except (OverflowError, ValueError):
        raise ValueError(name + " is not a supported finite number")
    if not math.isfinite(result) or abs(result) > 1e6:
        raise ValueError(name + " must be finite with magnitude at most 1000000")
    if positive and result < 1e-6:
        raise ValueError(name + " length must be between 0.000001 and 1000000 cm")
    return result


def center(value):
    if not isinstance(value, (list, tuple)) or len(value) != 2:
        raise ValueError("center must contain two coordinates in cm")
    return tuple(number(v, "coordinate") for v in value)


def circle_intersections(B, D, r, s, tol_cm=ABS_TOL_CM):
    """Both intersections; strict outside/nested tests never clamp to tangent.

    Inside the closed intersection interval, a transverse height <=tol_cm
    is reported as one numerical tangent with its closure residuals.
    Coincident means exactly equal input centers and radii (infinitely many).
    """
    B, D = center(B), center(D)
    r, s = number(r, "radius B", True), number(s, "radius D", True)
    tol_cm = number(tol_cm, "tolerance")
    if not 1e-12 <= tol_cm <= 1e-6:
        raise ValueError("tolerance must be 1e-12..1e-6 cm")
    dx, dy = D[0]-B[0], D[1]-B[1]
    d = math.hypot(dx, dy)
    out = {"center_distance_cm": d, "tolerance_cm": tol_cm, "points": []}
    if d == 0:
        out["classification"] = "coincident" if r == s else "none"
        return out
    if d < 1e-9:
        raise ValueError("nonzero center separation below supported 1e-9 cm")
    if d > r+s or d < abs(r-s):
        out["classification"] = "none"
        return out
    ex, ey = dx/d, dy/d
    a = ((r-s)*(r+s)+d*d)/(2*d)
    # Both factors are nonnegative after the strict interval tests.
    h2 = ((r+s-d)*(r+s+d)*(d-abs(r-s))*(d+abs(r-s)))/(4*d*d)
    if h2 < 0 or not math.isfinite(h2):
        raise ValueError("numerical intersection failed; no invented closure")
    h = math.sqrt(h2)
    base = (B[0]+a*ex, B[1]+a*ey)
    signs = [(0, "tangent")] if h <= tol_cm else [(1, "+"), (-1, "-")]
    out["classification"] = "one" if len(signs) == 1 else "two"
    out["transverse_height_cm"] = h
    for sign, branch in signs:
        C = (base[0]-sign*h*ey, base[1]+sign*h*ex)
        cross = dx*(C[1]-B[1])-dy*(C[0]-B[0])
        residual_B, residual_D = math.dist(B,C)-r, math.dist(D,C)-s
        scale = max(1.0, r, s, d, *(abs(v) for v in B+D+C))
        closure_budget = max(tol_cm, 64*math.ulp(scale))
        if (not all(math.isfinite(v) for v in C+(cross,residual_B,residual_D))
                or max(abs(residual_B),abs(residual_D)) > closure_budget):
            raise ValueError("numerically inaccurate closure; no position returned")
        out["points"].append({"branch": branch, "C": list(C),
            "cross_cm2": cross, "residual_B_cm": residual_B,
            "residual_D_cm": residual_D})
    return out


def assembly(theta_deg, ground=4, input_length=2, coupler=3, output=2.5):
    theta = number(theta_deg, "theta_deg")
    g = number(ground, "ground", True)
    a = number(input_length, "input", True)
    b = number(coupler, "coupler", True)
    c = number(output, "output", True)
    angle = math.radians(math.remainder(theta, 360))
    B, D = (a*math.cos(angle), a*math.sin(angle)), (g, 0.0)
    result = circle_intersections(B,D,b,c)
    result.update(theta_deg=theta, units="cm", A=[0.0,0.0], B=list(B), D=list(D),
                  lengths={"ground":g,"input":a,"coupler":b,"output":c})
    return result


def critical_angle_deg():
    """External tangency input angle of the prescribed 4/2/3/2.5 cm model."""
    return math.degrees(math.acos((20-30.25)/16))


def fields(record, expected):
    if not isinstance(record,dict) or set(record) != set(expected):
        raise ValueError("missing/extra fields")


def analyze(document):
    fields(document,("kind","units","lengths","records"))
    if document["kind"] not in ("constructed","observation_blank") or document["units"] != "cm":
        raise ValueError("use constructed/observation_blank and units cm")
    lengths = document["lengths"]
    fields(lengths,("ground","input","coupler","output"))
    lengths = {k:number(v,k,True) for k,v in lengths.items()}
    records = document["records"]
    if not isinstance(records,list) or not 1 <= len(records) <= 512:
        raise ValueError("need 1..512 records")
    output, seen = [], set()
    for record in records:
        fields(record,("record_id","theta_deg"))
        rid = record["record_id"]
        if not isinstance(rid,str) or not ID.fullmatch(rid) or rid in seen:
            raise ValueError("invalid/duplicate record_id")
        seen.add(rid)
        theta = record["theta_deg"]
        if document["kind"] == "observation_blank" and theta is not None:
            raise ValueError("blank observations cannot contain invented angles")
        if theta is None:
            result = {"theta_deg":None,"classification":"unknown","points":None}
        else:
            result = assembly(theta,lengths["ground"],lengths["input"],lengths["coupler"],lengths["output"])
        output.append(dict(record_id=rid, **result))
    return {"kind":document["kind"],"units":"cm","arithmetic":"Python binary64 floating point",
            "tolerance_cm":ABS_TOL_CM,"records":output}


def no_duplicates(pairs):
    result = {}
    for k,v in pairs:
        if k in result:
            raise ValueError("duplicate JSON key: "+k)
        result[k] = v
    return result


def loads_strict(text):
    return json.loads(text,object_pairs_hook=no_duplicates,
        parse_constant=lambda x: (_ for _ in ()).throw(ValueError("nonfinite JSON: "+x)))


def read_document(path):
    with Path(path).open("rb") as stream:
        raw = stream.read(MAX_BYTES+1)
    if len(raw) > MAX_BYTES:
        raise ValueError("input exceeds 1000000 bytes")
    return loads_strict(raw.decode("utf-8"))


def main(argv=None):
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("input",help="strict JSON constructed angles or blank template")
    args = parser.parse_args(argv)
    try:
        result = analyze(read_document(args.input))
    except (ValueError,OSError,UnicodeError) as error:
        print("error: "+str(error),file=sys.stderr)
        return 2
    print(json.dumps(result,indent=2,allow_nan=False))
    return 0


if __name__ == "__main__":
    sys.exit(main())

Inject a fault, then restore the baseline

Make a copy of the constructed input. Change units from "cm" to "mm": the model rejects the unsupported unit instead of silently treating the lengths as centimetres. Change a positive length to zero, an angle to the string "NaN" (not a number), or repeat a record identifier: it must exit 2 with an error and no ordinary result. Decimal angle values in JSON are numbers here, unlike a text label. Restore the untouched constructed input after each fault and rerun 60ยฐ.

A missing observation is not a mechanism fault, and a drawn crossing is not a new constraint. To track an ideal branch, retain its declared sign and the starting assembly while staying away from tangency; simply sorting C points by page height is not a general branch rule. At tangency the sign reaches zero and the two branches meet, so this model alone cannot establish which physical continuation will occur. A sampling history also cannot establish unmodelled forces or collisions.

Challenge: why does the input fail at 180ยฐ?

Before running, calculate B and the centre distance. Could changing a branch sign rescue the geometry?

Answer: B=(โˆ’2,0) cm and D=(4,0) cm, so d=6 cm. The remaining two links span at most3+2.5=5.5 cm between B and D. Neither sign can close the0.5 cm shortfall. Both choices depend on the same circle intersection; selecting a sign cannot create one.

References and reproducible files

Carnegie Mellon University, Yi Zhang with Susan Finger and Stephannie Behrens, Introduction to Mechanisms, Chapter5, supplies the four-bar, fixed-frame and coupler terminology. The specific dimensions, circle equations, branch convention, graphs and code here are original and derived in the article. No university diagrams or manuals are bundled.

The related idler-gear direction experiment concerns ideal rotational ratios. Here the distinct outcome is positional ambiguity in a closed chain: the same input can satisfy two assemblies. The gear experiment is not evidence for four-bar force or clearance behavior.

Use the complete model โ€” reader ZIP; extract fourbar_lab.py, behavior tests โ€” reader ZIP; extract test_fourbar_lab.py, figure generator โ€” reader ZIP; extract generate_figures.py, constructed angles โ€” reader ZIP; extract data/constructed-angles.json, blank observations โ€” reader ZIP; extract data/blank-observations.json, calculated graph data โ€” reader ZIP; extract data/branch-figure-data.csv and source index โ€” reader ZIP; extract source-index.html. The generator creates both SVGs with the standard library; optional python3 -B generate_figures.py --png uses resvg_py to render PNGs. The explanatory text remains searchable Hypertext Markup Language (HTML), separate from the figures.

๐Ÿ“กBroadcast the signal โ€” amplify the connection.

Leave a Reply