Two-bone arm IK whose mid joint bends only about its own flexion hinge, with
the chain root's free swivel spent on the rig's range of motion.
The elbow rotates by θ about hinge alone, so its abduction and twist
decompose to zero, which is what an elbow's immobile axes require, and the
bend plane is the hinge's own plane. Splitting the far segment into the part
along the hinge and the part it swings gives the root-to-effector span
|m(θ)|² = k + α·cos θ + β·sin θ
so the span equals the target distance where R·cos(θ − φ) = distance² − k,
with R = hypot(α, β) and φ = atan2(β, α): an arccos whose two roots are
the chain's two bend branches. A target outside the reachable span takes the
fully extended or fully folded root, so the effector stops on the reachable
shell along the line to the target. A root outside the mid joint's own
range stops at the nearer limit in the same way, the effector resting on
the legal shell along that line and the result reporting the shortfall;
of two branches the one stopping nearer the target is swept, because a
candidate past the hinge's limit would be clamped by the caller afterwards
and land somewhere no candidate was scored at.
The root joint first aims m(θ) at the target, then any extra rotation
about m(θ) leaves the effector where it is. The function sweeps that swivel
in SWIVEL_STEP increments on each branch, ordering candidates by the least
overshoot (legal, zero, ahead of any other exactly; two positive ones
tied within the decomposition's rounding, 1e-9 degree), then the
least deviation, both from
score. Every local minimum of a sweep is then refined between its
neighbouring steps by golden-section search under the same ordering, and
the best of the sweeps and the refinements is returned. A pass whose two
probes tie closes the bracket onto both, so a request mirrored left to
right, whose probes are the same two exchanged, refines to the mirrored
swivel. So the chosen pose
follows a moving target continuously rather than in swivel steps, a legal
interval narrower than one step is still found from the dip it leaves in
the sweep, and between two basins the truly better one wins rather than the
one a sample happened to fall nearer the bottom of. The caller owns the
decomposition and the rig's ROM, so the geometry here holds no rig policy.
A caller that can certify swivels its score refuses (excluded) spares
their scoring, and the pose is still the full sweep's. A step is skipped
when every swivel within two steps of it is refused, and a step whose
bracket, a step either way, is refused is not refined; every other step is
scored and compared with its true neighbours, since a step that is not
skipped and could be refined has both neighbours scored. When the pruned
sweep finds a legal candidate, the full sweep's answer is that candidate:
a refused swivel, a step or a refinement inside a refused bracket, is
never legal, so it can never be ahead of a legal candidate (legality is
compared exactly); every legal candidate of the full sweep is a scored
step or the refinement of a step that is scored with the same neighbours,
so it is the same candidate in both; and the ordering among legal
candidates, met in the same order, is the same. When the pruned sweep
finds none, the full sweep decides, so a chain that cannot reach legally
still returns its least overshoot.
A cold fit with closed candidates and no tie or minimum scores them
alone and returns the best when it is legal and met accepts it: where a
requested term is met only at isolated swivels, those are the whole
admissible set and no search can add to it.
A cold fit with a pole and no tie or minimum searches locally from
it (hingedSwivelPole) and returns a legal result without the sweep, so
it follows the bend hint rather than jumping to a far, marginally better swivel.
A cold fit whose caller certifies that no candidate can pass met
(unmet) skips the pole start, whose result met would refuse.
A caller continuing a fit of a nearby target (near) skips the sweep: a
closed candidate less than a step from the seed answers when legal and
met (hingedSwivelNear), and otherwise the
seed's branch, its swivel refined within one step either way by the same
golden-section search under the same ordering, to the seed's tolerance
(IAutoMovieSwivelNear). Every result names its branch and swivel, the
seed a nearby fit continues from. If dividing a positive subnormal tolerance
by the initial bracket width underflows, the difference of logarithms keeps
the mathematically finite refinement count finite; ordinary ratios retain
their original expression.
With certified global score minima and no second key, the first scored
coarse candidate ends a cold search only if its actual two keys equal both
minima exactly. No later candidate can be strictly ahead, so the original
candidate and complete-tie seed are preserved; later coarse candidates
cannot use this shortcut because earlier refinements precede them.
Returns null for a degenerate chain: a mid or end offset shorter than
1e-6, a target within 1e-6 of the chain root, a hinge shorter than
1e-6, or R below 1e-9, a hinge parallel to the far segment that cannot
change the span (armChainFault reports that rig).
Two-bone arm IK whose mid joint bends only about its own flexion hinge, with the chain root's free swivel spent on the rig's range of motion.
The elbow rotates by
θabouthingealone, so its abduction and twist decompose to zero, which is what an elbow's immobile axes require, and the bend plane is the hinge's own plane. Splitting the far segment into the part along the hinge and the part it swings gives the root-to-effector spanso the span equals the target distance where
R·cos(θ − φ) = distance² − k, withR = hypot(α, β)andφ = atan2(β, α): an arccos whose two roots are the chain's two bend branches. A target outside the reachable span takes the fully extended or fully folded root, so the effector stops on the reachable shell along the line to the target. A root outside the mid joint's ownrangestops at the nearer limit in the same way, the effector resting on the legal shell along that line and the result reporting theshortfall; of two branches the one stopping nearer the target is swept, because a candidate past the hinge's limit would be clamped by the caller afterwards and land somewhere no candidate was scored at.The root joint first aims
m(θ)at the target, then any extra rotation aboutm(θ)leaves the effector where it is. The function sweeps that swivel inSWIVEL_STEPincrements on each branch, ordering candidates by the leastovershoot(legal, zero, ahead of any other exactly; two positive ones tied within the decomposition's rounding, 1e-9 degree), then the leastdeviation, both fromscore. Every local minimum of a sweep is then refined between its neighbouring steps by golden-section search under the same ordering, and the best of the sweeps and the refinements is returned. A pass whose two probes tie closes the bracket onto both, so a request mirrored left to right, whose probes are the same two exchanged, refines to the mirrored swivel. So the chosen pose follows a moving target continuously rather than in swivel steps, a legal interval narrower than one step is still found from the dip it leaves in the sweep, and between two basins the truly better one wins rather than the one a sample happened to fall nearer the bottom of. The caller owns the decomposition and the rig's ROM, so the geometry here holds no rig policy.A caller that can certify swivels its score refuses (
excluded) spares their scoring, and the pose is still the full sweep's. A step is skipped when every swivel within two steps of it is refused, and a step whose bracket, a step either way, is refused is not refined; every other step is scored and compared with its true neighbours, since a step that is not skipped and could be refined has both neighbours scored. When the pruned sweep finds a legal candidate, the full sweep's answer is that candidate: a refused swivel, a step or a refinement inside a refused bracket, is never legal, so it can never be ahead of a legal candidate (legality is compared exactly); every legal candidate of the full sweep is a scored step or the refinement of a step that is scored with the same neighbours, so it is the same candidate in both; and the ordering among legal candidates, met in the same order, is the same. When the pruned sweep finds none, the full sweep decides, so a chain that cannot reach legally still returns its least overshoot.A cold fit with
closedcandidates and notieorminimumscores them alone and returns the best when it is legal andmetaccepts it: where a requested term is met only at isolated swivels, those are the whole admissible set and no search can add to it.A cold fit with a
poleand notieorminimumsearches locally from it (hingedSwivelPole) and returns a legal result without the sweep, so it follows the bend hint rather than jumping to a far, marginally better swivel.A cold fit whose caller certifies that no candidate can pass
met(unmet) skips the pole start, whose resultmetwould refuse.A caller continuing a fit of a nearby target (
near) skips the sweep: aclosedcandidate less than a step from the seed answers when legal and met (hingedSwivelNear), and otherwise the seed's branch, its swivel refined within one step either way by the same golden-section search under the same ordering, to the seed'stolerance(IAutoMovieSwivelNear). Every result names its branch and swivel, the seed a nearby fit continues from. If dividing a positive subnormal tolerance by the initial bracket width underflows, the difference of logarithms keeps the mathematically finite refinement count finite; ordinary ratios retain their original expression. With certified global score minima and no second key, the first scored coarse candidate ends a cold search only if its actual two keys equal both minima exactly. No later candidate can be strictly ahead, so the original candidate and complete-tie seed are preserved; later coarse candidates cannot use this shortcut because earlier refinements precede them.Returns
nullfor a degenerate chain: a mid or end offset shorter than1e-6, a target within1e-6of the chain root, a hinge shorter than1e-6, orRbelow1e-9, a hinge parallel to the far segment that cannot change the span (armChainFault reports that rig).