an.kinematics#

A deterministic 2D constraint solver: bodies joined at points, driven at a few of them, settled by gravity (an#499, ADR 0008).

Four nouns and one verb. A Body is a rigid rectangle posed by (x, y, rotation, scale); a Point on it is a fraction of its extent. A joint relates two bodies (or a body and WORLD): Pin, Hinge (a pin with an angle range), Weld, Distance (equal a rod, at_most a string, at_least a spacer), Slide (a groove) and Contact (one-sided: a foot on the ground, a lamp on a table). A driver is a target on a body’s channels (a nail: met exactly where the joints allow), a Force (a push, or a soft pull toward a point), or gravity. solve() does one frame, solve_frames() a run of them with the caller’s targets and joined/unjoined joints per frame, and both return a typed result that names what could not be held instead of raising.

>>> torso = Body("torso", width=40.0, height=80.0)
>>> upper = Body("upper", x=20.0, y=-30.0, width=50.0, height=10.0, origin=(0.0, 0.5))
>>> fore = Body("fore", x=70.0, y=-30.0, width=40.0, height=8.0, origin=(0.0, 0.5))
>>> handle = Body("handle", x=80.0, y=10.0, width=4.0, height=4.0, fixed=True)
>>> arm = [Pin(Point("upper", 0.0, 0.5), Point("torso", 1.0, 0.125)),
...        Hinge(Point("fore", 0.0, 0.5), Point("upper", 1.0, 0.5), limits=(-2.6, 0.0)),
...        Pin(Point("fore", 1.0, 0.5), Point("handle", 0.5, 0.5))]
>>> solve([torso, upper, fore, handle], arm, targets={"torso": {"x": 0.0, "y": 0.0}}).ok
True

Nothing here imports the scene IR or the stage, and nothing names an animation: bodies are numbers, joints are rows (# extraction candidate: this becomes its own package when a second consumer exists). The compile pass that reads joints from a scene is P2 (an#512).

The method, and why (measured in misc/docs/research/puppeteering_2026-10.md §4, which compared analytic two-bone, CCD, FABRIK, PBD and XPBD on the same tasks, and re-measured on this module by misc/docs/research/puppeteering_2026-10/measure_kinematics.py, results in kinematics_measurements.json beside it; CPython 3.12, x86-64, one core). Extended position-based dynamics on 2D rigid bodies (XPBD, Macklin et al. 2016; rigid bodies and joints, Müller et al. 2020): Gauss–Seidel over the joints in a fixed order, each a projection with the generalized inverse mass 1/m + (r × n)² / I about the body’s centre (or about its pose point while that is held), hinge limits as angular projections, a fixed count of substeps and iterations. It is the one family of the five that does chains, strings, rods, contacts, gravity and unjoining in one loop, and its compliance is a stiffness that does not depend on the iteration count. Its weakness, slow propagation down long chains, is covered for the common case by the analytic two-link solve used as the initial guess for every chain between two held ends (an arm with a hand is a two-link chain whose second link is the forearm and the hand held at their current angles), which also makes the elbow’s bend side an explicit choice (the side its range allows, else the side it already has).

  • Convergence per iteration (the arm above, pose mode, worst residual): from the closed-form start, 2e-14 px after one pass; from a cold start, 5.8 / 3.3 / 0.80 / 0.10 / 0.0014 px after 1 / 2 / 4 / 8 / 16 passes, 5e-14 after 64. A frame that leaves a joint failing is retried with four times the passes, so the default eight reach the sixteen-pass figure when needed.

  • Singularities: a target at exactly full reach (a straight arm) is met with zero residual and a straight elbow; 1 px or 5 px beyond reach the grip alone is refused (dropped, its gap in unsatisfied), the shoulder and elbow hold exactly, and the arm points straight at the target; a target on the shoulder itself (inside the nearest reach, where the direction is undefined) is refused the same way, the arm left where it was rather than guessed. (The torso is nailed in rotation here; free to turn, it turns toward the target first.) A chain between two rigidly held ends whose ends are outside its reach is refused before any pass.

  • A straight chain pushed along its length (a rope bridge of 3 to 20 planks pinned at 0.8 of its length, laid straight): no correction has a sideways part, so nothing moves; the retry’s start, nudged by 1e-3 rad, buckles it, and every joint holds (tests).

  • Stability at frame-exact steps (a 12-link chain dropped horizontal, 10 s at 24 fps, under gravity): at 4 substeps (the default) no frame fails a joint and the tip hangs within 0.03° of vertical; at 1 or 2 substeps the whip under-converges (worst 3.2 / 0.9 px with the retry, 17 / 3.4 px without), reported per frame and never given up (a tree cannot conflict). Nothing diverges at any setting.

  • Compliance: a soft rod (compliance=1e-4) under a 100-unit weight stretches 11.85 units after one second at 1, 2, 8 and 32 iterations alike, to the digit; it settles to the static 9.8.

  • Cost per frame, dynamic, defaults: 14 ms for five ten-part marionettes (50 bodies, 65 joints, 25 strings), no frame failing; 0.9 ms for the two-link reach in pose mode. A 50-link rope or chain costs 34-48 ms (the retry runs on its failing frames) and under-converges on 40-47 of 48 frames (Gauss–Seidel’s n² propagation): reported, never cut. Long ropes want more substeps, or the FABRIK seam the research names.

  • Determinism: Python floats and math inside the loop, numpy at the boundary; bitwise-equal poses across runs and across processes on one platform (tests/test_kinematics.py). Not across platforms: a dynamic run amplifies a last-ulp libm difference (1e-13 on one frame’s input is 0.014 units 96 frames later), so a cache key is built on the inputs (inputs_digest(), with SOLVER_VERSION), never the output.

A retry that stops converging is a conflict (an#568). In dynamic mode an arm swinging back from a refused grip toward one inside its length but past its elbow’s range halved its failure on the first retry, then sat at ~1.2 px for any number of passes: it was reported as slow and never given up. The retry now repeats while each round still makes progress (up to DFLT_CONVERGE_CAP × iterations) and a stall is resolved as a conflict. On 300 random out-and-back reaches, no frame is left failing in either mode (126 were, up to 6 px); a 50-link rope with its end out of reach costs ~90 rather than ~40 ms a frame, with 7 rather than 22 frames failing.

A held loop that can hold is never a conflict (an#706). Gauss–Seidel’s rate falls with a chain’s length, so “the retry halves the failure” read a long rope’s grip in reach as a conflict: a 70-link rope held at both ends, swinging under its own weight, cut its failure to ~0.65 at 4x the passes, had its grip given up, led back and taken again three times (on macOS arm64’s floats, not Linux’s). The rule is geometric: a chain between two rigid ends, of bare links (pins only) and within reach (exact: the annulus a revolute chain sweeps), can hold, so it is kept converging up to the cap whatever its rate or a conflict elsewhere in the frame, and given up only if the cap leaves it more than DFLT_HELD_JUMP apart (a jump no frame makes at once). A fourth condition, holding as the frame starts, is not part of what can hold: it keeps a grip taken back from afar on the old rule, so it is led back (an#645) rather than snapped across the gap, and keeps the cap’s cost off those frames. On that run the frames cost a little less on average (388 rather than 415 projections, ~40 ms of CPU) and the grip is led 12 frames instead of 30, held from its take-back to the end. A frame that needs the whole cap pays 2724 projections, each one pass over every link, so its cost grows with the chain: ~280 ms at 70 links, 2.5-2.8 s measured at 200 links (on a loaded machine).

Not in this version: friction (a contact is frictionless: a lamp on a table sliding sideways stays where it is until the edge passes), blending a snap (a rejoined joint closes its gap in one frame, reported in FramesResult.snaps), and the stochastic driver seed is reserved for.

Functions

mass(body)

The body's mass: density × scaled area; inf for a fixed body.

inertia(body)

Rotational inertia about the body's pose point (parallel-axis from the extent's centre); inf for a fixed body.

point_world(body, point)

The point's position in the body's frame of reference (the world, for a body posed in it); a WORLD point is returned as is.

reach(l1, l2)

The (nearest, farthest) distance from the root a two-link chain of lengths l1 and l2 can put its tip.

two_bone(root, target, lengths, *[, bend])

Absolute angles (theta1, theta2) of two links of lengths (l1, l2) hinged at root so that the tip meets target; None when the target is out of reach().

arc_chain(root, target, lengths, *[, bend])

Absolute angles of links of lengths, end to end from root, laid on one circular arc whose ends are root and target: the slack pose of a chain held at both ends nearer than its length (an#646), which no two-link form gives a long chain.

solve(bodies, joints, *[, targets, forces, ...])

One frame: the poses of all bodies that satisfy the joined joints with the targets held, forces and gravity acting.

solve_frames(bodies, joints, *, frames, dt)

frames solves in a row, each starting from the last: the caller's time dimension.

resolve_rests(bodies, joints)

joints with every rest=None hinge and weld given the relative angle the bodies have now, so a run of frames measures its limits from one pose rather than from each frame's.

quantize(poses, *[, position_quantum, ...])

poses (any shape whose last axis is POSE_CHANNELS) rounded to the quanta a document stores: positions and scale to position_quantum, rotation to angle_quantum.

digest(poses, **quanta)

A hex digest of the quantized poses' bytes, with the solver version: for comparing solved poses on one platform (a golden test).

inputs_digest(bodies, joints, *[, targets, ...])

A hex digest of everything a solve reads, with SOLVER_VERSION: the cache key for a solve (or a run of them: pass the per-frame targets as a list, and frames, dt and the rest as options).

Classes

Body(name[, x, y, rotation, scale, width, ...])

A rigid rectangle posed in one frame.

Point(body, u, v)

A point on a body, as a fraction of the body's extent.

Pin(a, b[, compliance, joined])

Two points coincide; free rotation about them.

Hinge(a, b[, limits, rest, compliance, joined])

A pin with a range for the angle of b's body relative to a's.

Weld(a, b[, rest, compliance, joined])

A pin plus a fixed relative angle (rest, or the starting one).

Distance(a, b, length[, mode, compliance, ...])

The two points keep length apart: exactly, at most, or at least.

Slide(point, start, end[, compliance, joined])

point stays on the segment start–end (both on one other body, or the world), within its ends.

Contact(point, start, end[, compliance, joined])

point stays on the free side of the segment start–end, or on it; nothing holds it there (it may lift off), and nothing holds it beyond the segment's ends (it may fall off an edge).

Force(point[, vector, toward, strength])

A driver that is not a target: a constant vector (force per unit mass, applied at point, so an off-centre push also turns the body), or a pull of point toward a position with strength (a compliant zero-length rope: compliance = 1 / strength), or both.

SolveResult(bodies, poses, residuals, ...[, ...])

What one frame's solve found.

FramesResult(bodies, poses, unsatisfied, ...)

A run of frames: poses is (frames, bodies, 4); unsatisfied and limit_violations are per frame; snaps lists every joint that is enforced again after a frame it was not (the caller rejoined it, or a conflict had dropped it) as (frame, joint index, distance), the gap it closes (in one frame, unless the caller's rejoin is blended: RejoinBlends; in dynamic mode a large gap yanks the bodies it joins); final is the last frame's bodies, ready to continue the run; dropped the joints each frame gave up in a conflict.

Exceptions

KinematicsError

A solve that cannot be set up: an unknown body, gravity without time, a joint on the world alone, a body with no extent.

class an.kinematics.Body(name, x=0.0, y=0.0, rotation=0.0, scale=1.0, width=1.0, height=1.0, origin=(0.5, 0.5), fixed=False, density=1.0, vx=0.0, vy=0.0, omega=0.0)[source]#

Bases: object

A rigid rectangle posed in one frame.

fixed bodies have infinite mass: joints move everything else around them. vx, vy (the velocity of the extent’s centre) and omega are what a dynamic solve carries from one frame to the next (zero at rest). density sets the mass per unit area, spread evenly over the extent, so a limb whose pose point is at its end still swings about it.

>>> b = Body("box", width=4.0, height=2.0)
>>> round(mass(b), 3), round(inertia(b), 3)
(8.0, 13.333)
posed(*, x=None, y=None, rotation=None, vx=None, vy=None, omega=None)[source]#

This body with the given pose channels (and velocities) replaced.

>>> Body("b").posed(x=3.0).x
3.0
Return type:

Body

class an.kinematics.Contact(point, start, end, compliance=0.0, joined=True)[source]#

Bases: object

point stays on the free side of the segment start–end, or on it; nothing holds it there (it may lift off), and nothing holds it beyond the segment’s ends (it may fall off an edge).

>>> Contact(Point("lamp", 0.5, 1.0), Point("table", 0.0, 0.0), Point("table", 1.0, 0.0)).joined
True
class an.kinematics.Distance(a, b, length, mode='equal', compliance=0.0, joined=True)[source]#

Bases: object

The two points keep length apart: exactly, at most, or at least.

>>> Distance(Point("hand", 0.5, 0.5), Point("world", 0.0, -200.0), length=150.0, mode="at_most").mode
'at_most'
class an.kinematics.Force(point, vector=None, toward=None, strength=1.0)[source]#

Bases: object

A driver that is not a target: a constant vector (force per unit mass, applied at point, so an off-centre push also turns the body), or a pull of point toward a position with strength (a compliant zero-length rope: compliance = 1 / strength), or both.

>>> Force(Point("kite", 0.5, 0.0), vector=(30.0, 0.0)).toward is None
True
class an.kinematics.FramesResult(bodies, poses, unsatisfied, limit_violations, snaps, final=(), dropped=())[source]#

Bases: object

A run of frames: poses is (frames, bodies, 4); unsatisfied and limit_violations are per frame; snaps lists every joint that is enforced again after a frame it was not (the caller rejoined it, or a conflict had dropped it) as (frame, joint index, distance), the gap it closes (in one frame, unless the caller’s rejoin is blended: RejoinBlends; in dynamic mode a large gap yanks the bodies it joins); final is the last frame’s bodies, ready to continue the run; dropped the joints each frame gave up in a conflict.

class an.kinematics.Hinge(a, b, limits=None, rest=None, compliance=0.0, joined=True)[source]#

Bases: object

A pin with a range for the angle of b’s body relative to a’s.

limits is (lo, hi) in radians about rest, within [-pi, pi]; rest is the relative angle (b.rotation - a.rotation) the range is measured from, taken from the bodies’ poses at the start of the solve when None. With no limits it is a pin.

>>> Hinge(Point("fore", 0.0, 0.5), Point("upper", 1.0, 0.5), limits=(-2.6, 0.0)).limits
(-2.6, 0.0)
exception an.kinematics.KinematicsError[source]#

Bases: ValueError

A solve that cannot be set up: an unknown body, gravity without time, a joint on the world alone, a body with no extent.

class an.kinematics.Pin(a, b, compliance=0.0, joined=True)[source]#

Bases: object

Two points coincide; free rotation about them.

>>> Pin(Point("arm", 0.0, 0.5), Point("torso", 1.0, 0.2)).joined
True
class an.kinematics.Point(body, u, v)[source]#

Bases: object

A point on a body, as a fraction of the body’s extent.

On WORLD the fraction is an absolute position instead.

>>> Point("hand", 0.5, 1.0).body
'hand'
class an.kinematics.Slide(point, start, end, compliance=0.0, joined=True)[source]#

Bases: object

point stays on the segment start–end (both on one other body, or the world), within its ends.

>>> Slide(Point("bead", 0.5, 0.5), Point("world", 0.0, 0.0), Point("world", 100.0, 0.0)).joined
True
class an.kinematics.SolveResult(bodies, poses, residuals, unsatisfied, limit_violations, dropped=(), out_of_reach=())[source]#

Bases: object

What one frame’s solve found.

bodies are the input bodies with their poses and velocities updated, ready to be the next frame’s input; poses is the same as an array, one row per body in input order, columns POSE_CHANNELS. residuals has one entry per joint in input order: how far apart a joined joint’s points still are (0 for an unjoined joint, or one that holds; a compliant joint’s stretch); unsatisfied lists the rigid joints’ (joint index, residual) pairs above tolerance, and limit_violations the rigid hinges and welds outside their angle range as (joint index, radians). dropped lists the joints given up in a conflict (module docstring), in the order they were.

property ok: bool#

Every joined joint holds and every range is kept.

>>> solve([Body("b")], []).ok
True
out_of_reach: tuple[int, ...] = ()#

The joints in dropped given up before any pass because the geometry rules them out (a grip beyond the chain’s reach), not in a conflict.

pose(name)[source]#

The body called name as solved.

>>> b = Body("b", x=1.0)
>>> solve([b], []).pose("b").x
1.0
Return type:

Body

class an.kinematics.Weld(a, b, rest=None, compliance=0.0, joined=True)[source]#

Bases: object

A pin plus a fixed relative angle (rest, or the starting one).

>>> Weld(Point("hat", 0.5, 1.0), Point("head", 0.5, 0.0)).rest is None
True
an.kinematics.arc_chain(root, target, lengths, *, bend=1)[source]#

Absolute angles of links of lengths, end to end from root, laid on one circular arc whose ends are root and target: the slack pose of a chain held at both ends nearer than its length (an#646), which no two-link form gives a long chain. None when the chain cannot sag (target at or past its length, or on the root) or no arc fits.

bend is the side, as for two_bone(): +1 sags counter-clockwise of the root-to-target line.

>>> angles = arc_chain((0.0, 0.0), (35.0, 0.0), [1.0] * 50)
>>> tip = (sum(math.cos(a) for a in angles), sum(math.sin(a) for a in angles))
>>> math.isclose(tip[0], 35.0, abs_tol=1e-9), math.isclose(tip[1], 0.0, abs_tol=1e-9)
(True, True)
>>> arc_chain((0.0, 0.0), (60.0, 0.0), [1.0] * 50) is None
True
Return type:

list[float] | None

an.kinematics.digest(poses, **quanta)[source]#

A hex digest of the quantized poses’ bytes, with the solver version: for comparing solved poses on one platform (a golden test). A cache key is built on the inputs instead (inputs_digest()).

>>> digest(np.zeros((2, 4))) == digest(np.zeros((2, 4)) + 1e-9)
True
Return type:

str

an.kinematics.inertia(body)[source]#

Rotational inertia about the body’s pose point (parallel-axis from the extent’s centre); inf for a fixed body.

>>> round(inertia(Body("b", width=4.0, height=2.0, origin=(0.0, 0.5))), 3)
45.333
Return type:

float

an.kinematics.inputs_digest(bodies, joints, *, targets=None, forces=(), gravity=None, **options)[source]#

A hex digest of everything a solve reads, with SOLVER_VERSION: the cache key for a solve (or a run of them: pass the per-frame targets as a list, and frames, dt and the rest as options). Floats are hashed exactly (float.hex); mappings by sorted key.

>>> a = inputs_digest([Body("b", x=1.0)], [], dt=1 / 24)
>>> a == inputs_digest([Body("b", x=1.0)], [], dt=1 / 24), a == inputs_digest([Body("b", x=1.0 + 1e-15)], [], dt=1 / 24)
(True, False)
Return type:

str

an.kinematics.mass(body)[source]#

The body’s mass: density × scaled area; inf for a fixed body.

>>> mass(Body("b", width=3.0, height=2.0, scale=2.0))
24.0
>>> mass(Body("b", fixed=True))
inf
Return type:

float

an.kinematics.point_world(body, point)[source]#

The point’s position in the body’s frame of reference (the world, for a body posed in it); a WORLD point is returned as is.

>>> b = Body("b", x=1.0, y=1.0, rotation=math.pi / 2, width=2.0, height=2.0)
>>> tuple(round(c, 9) for c in point_world(b, Point("b", 1.0, 0.5)))
(1.0, 2.0)
Return type:

tuple[float, float]

an.kinematics.quantize(poses, *, position_quantum=1e-06, angle_quantum=1e-07)[source]#

poses (any shape whose last axis is POSE_CHANNELS) rounded to the quanta a document stores: positions and scale to position_quantum, rotation to angle_quantum.

>>> q = quantize(np.array([[1.00000049, 2.0, 0.123456789, 1.0]]))
>>> float(q[0, 0]), bool(abs(q[0, 2] - 0.1234568) < 1e-15)
(1.0, True)
Return type:

ndarray

an.kinematics.reach(l1, l2)[source]#

The (nearest, farthest) distance from the root a two-link chain of lengths l1 and l2 can put its tip.

>>> reach(3.0, 4.0)
(1.0, 7.0)
Return type:

tuple[float, float]

an.kinematics.resolve_rests(bodies, joints)[source]#

joints with every rest=None hinge and weld given the relative angle the bodies have now, so a run of frames measures its limits from one pose rather than from each frame’s.

>>> a = Body("a", rotation=0.1); b = Body("b", rotation=0.4)
>>> [round(j.rest, 3) for j in resolve_rests([a, b], [Hinge(Point("a", 0.5, 0.5), Point("b", 0.5, 0.5), limits=(-1.0, 1.0))])]
[0.3]
Return type:

list[Pin | Hinge | Weld | Distance | Slide | Contact]

an.kinematics.solve(bodies, joints, *, targets=None, forces=(), gravity=None, dt=None, iterations=8, substeps=4, damping=0.02, tolerance=0.25, angle_tolerance=0.001, seed_chains=True, retry=4, drop_conflicts=True, seed=0, converge_cap=64)[source]#

One frame: the poses of all bodies that satisfy the joined joints with the targets held, forces and gravity acting.

dt=None is pose mode: no inertia, no gravity, no pushes (a gravity or a Force.vector is refused there: they need time; a Force.toward pull works in both modes). With a dt the bodies step through substeps of dt / substeps, carrying their velocities in and out, and a target is reached over those substeps. targets hold channels exactly (a body held in x and y is immovable to the joints for the frame, one held in rotation unturnable); a target beyond a chain’s reach shows up in unsatisfied rather than stretching anything. Hinge and weld rests left None are the relative angles the bodies have on input. A frame that leaves a joint failing is solved again with retry times the iterations (1: never), again while each round still cuts what is left, up to converge_cap times the iterations; drop_conflicts then gives up the joints in conflict (a first retry that did not halve the failure, or a later one that stalled; a held loop the geometry shows can hold is judged by the cap, never by its rate), last declared first (module docstring); False keeps them all and reports what fails. seed is reserved for stochastic drivers and does nothing in this version: the solve has no randomness.

A shoulder driven to a point, an upper arm pinned to it, a forearm hinged to that, the hand pinned to a handle (the two-link case): the hand lands on the handle and the elbow bends the way its range allows.

>>> torso = Body("torso", width=40.0, height=80.0)
>>> upper = Body("upper", x=20.0, y=-30.0, width=50.0, height=10.0, origin=(0.0, 0.5))
>>> fore = Body("fore", x=70.0, y=-30.0, width=40.0, height=8.0, origin=(0.0, 0.5))
>>> handle = Body("handle", x=80.0, y=10.0, width=4.0, height=4.0, fixed=True)
>>> joints = [Pin(Point("upper", 0.0, 0.5), Point("torso", 1.0, 0.125)),
...           Hinge(Point("fore", 0.0, 0.5), Point("upper", 1.0, 0.5), limits=(-2.6, 0.0)),
...           Pin(Point("fore", 1.0, 0.5), Point("handle", 0.5, 0.5))]
>>> r = solve([torso, upper, fore, handle], joints, targets={"torso": {"x": 0.0, "y": 0.0}})
>>> r.ok, tuple(round(v, 3) for v in r.residuals)
(True, (0.0, 0.0, 0.0))

Out of reach, the grip is reported, and the arm stays on its shoulder:

>>> far = handle.posed(x=300.0)
>>> r = solve([torso, upper, fore, far], joints, targets={"torso": {"x": 0.0, "y": 0.0}})
>>> [j for j, _ in r.unsatisfied], r.dropped, [round(v, 6) for v in r.residuals[:2]]
([2], (2,), [0.0, 0.0])
Return type:

SolveResult

an.kinematics.solve_frames(bodies, joints, *, frames, dt, targets_at=None, joints_at=None, forces=(), gravity=None, regrip_speed=600.0, regrip_strength=1000000.0, rejoin_blend_frames=4, rejoin_blend_px=2.0, **options)[source]#

frames solves in a row, each starting from the last: the caller’s time dimension. targets_at(k) (or targets_at[k]) gives frame k’s targets; joints_at(k) its joints (the same list with joined flags flipped is how a joint is unjoined and rejoined). Hinge and weld rests are fixed from the starting poses. A pin rejoined within rejoin_blend_px (scene units) closes over rejoin_blend_frames frames, or the frames left before the last (RejoinBlends; 1 snaps it shut). options go to solve().

A part unjoined falls, and is caught where it is when rejoined:

>>> peg = Body("peg", width=2.0, height=2.0, fixed=True)
>>> part = Body("part", y=10.0, width=4.0, height=20.0, origin=(0.5, 0.0))
>>> joined = [Pin(Point("part", 0.5, 0.0), Point("peg", 0.5, 0.5))]
>>> loose = [Pin(Point("part", 0.5, 0.0), Point("peg", 0.5, 0.5), joined=False)]
>>> r = solve_frames([peg, part], joined, frames=12, dt=1 / 24, gravity=(0.0, 980.0),
...                  joints_at=lambda k: loose if 2 <= k < 8 else joined)
>>> bool(r.poses[1, 1, 1] < r.poses[7, 1, 1]), r.snaps[0][:2], r.snaps[0][2] > 2.0
(True, (8, 0), True)
>>> r.unsatisfied[-1]
()
Return type:

FramesResult

an.kinematics.two_bone(root, target, lengths, *, bend=1)[source]#

Absolute angles (theta1, theta2) of two links of lengths (l1, l2) hinged at root so that the tip meets target; None when the target is out of reach().

bend is +1 for a middle joint that deviates counter-clockwise from the root-to-target line (which, on a y-down screen, reads as clockwise), -1 for the other side. Each side is a different pose of the same chain; which one is right is the author’s (or a hinge range’s) choice.

>>> t1, t2 = two_bone((0.0, 0.0), (1.0, 1.0), (1.0, 1.0), bend=1)
>>> round(math.degrees(t1)), round(math.degrees(t2))
(90, 0)
>>> t1, t2 = two_bone((0.0, 0.0), (1.0, 1.0), (1.0, 1.0), bend=-1)
>>> round(math.degrees(t1)), round(math.degrees(t2))
(0, 90)
Return type:

tuple[float, float] | None

Modules

bodies

Bodies and the points on them: the things a joint joins and a driver moves.

chains

Closed-form pieces for chains: the two-link reach and its reachable range, and the arc a longer chain held at both ends sags on (arc_chain()).

joints

Joints: declared relations between two bodies, or a body and the world.

solver

The solve: bodies joined at points, driven at a few, settled by gravity.