World position of the chain's base. Not modified.
World position the tip should reach. Not modified.
Length of the root→joint bone, in world units; finite, >= 0.
Length of the joint→end bone, in world units; finite, >= 0.
World position the middle joint should bend towards. Not modified.
Optionalout: TwoBoneIKSolution
Solution to write into; allocated when omitted.
Solves a two-bone chain so its tip reaches
target, bending towardspoleHint.The chain is
root → joint → end, with|root − joint| = upperLengthand|joint − end| = lowerLengthalways — bones never stretch, which is what makes the unreachable case a clamp rather than a scale.where
a = upperLength,b = lowerLength,forwardis the unit vector from the root to the target, andpoleis the unit vector towardspoleHintwith itsforwardcomponent removed.θis measured fromforward, andsin θis taken non-negative, so the joint always lands on the pole side of the root–target line: that is what stops a knee from flipping between frames.Unreachable targets clamp (decision, WP-8.3)
Both failures clamp the distance and keep the direction, and both report
reachable: false:d > a + b): the chain straightens and points at the target,end = root + (a + b)·forward. The tip stops short along the line to the target — the closest a rigid chain can get.d < |a − b|, only possible with unequal bones): the chain folds as far as it goes,end = root + |a − b|·forward, again the closest reachable point.Clamping rather than throwing is deliberate: a target sliding out of range is an ordinary runtime event (a reaching character, a dragged handle), and the clamped pose is continuous with the reachable ones, so the limb settles at full extension instead of popping.
Degenerate inputs
forward— the world axis least aligned with it, made perpendicular. The pose is valid and repeatable, just not authored; pass a meaningful hint to control it.+Xasforward(documented, deterministic). With equal bones this is exactly reachable — the chain folds flat and the joint lands atroot + a·pole, so the pole hint still chooses the fold direction.