CCD and FABRIK

You want a character's hand to land on a doorknob. Forward kinematics only lets you dial in angles and watch where the hand ends up — the wrong tool when you know the goal and need the angles. That inverse problem is inverse kinematics (IK), and the textbook answer is to build the Jacobian and invert it. But the Jacobian is a matrix that goes singular when the limb straightens, is fiddly to pseudo-invert, and can shudder near those singularities. Games wanted something a programmer could type in an afternoon and run sixty times a second on a whole crowd.

Two solvers answered that call, and both throw the matrix away entirely. CCD (Cyclic Coordinate Descent) nudges the chain one joint at a time using nothing but a dot product; FABRIK (Forward And Backward Reaching Inverse Kinematics) forgets angles altogether and just slides joint positions around while keeping the bones the right length. This page teaches both, works a step of each by hand, and lets you drag a target around and watch a chain reach for it.

The set-up: a chain reaching for a point

A limb is a chain of joints p_0, p_1, \dots, p_n connected by bones of fixed lengths d_i = \lVert p_{i+1} - p_i \rVert. Joint p_0 is the root (bolted to the shoulder / hip); joint p_n is the end-effector (the hand). We are handed a target point t and asked to find a pose that puts p_n on t without stretching any bone. There are usually infinitely many such poses (a limb can bend many ways to touch the same spot), so a good solver is one that finds a natural-looking one, fast.

CCD: one joint at a time, back to front

Cyclic Coordinate Descent sweeps the chain from the end-effector back toward the root. At each joint p_i it asks a tiny question: which single rotation of this joint sends the end-effector as directly as possible at the target? The answer is beautifully simple — rotate p_i so that the vector from the joint to the current end-effector,

u \;=\; p_n - p_i,

lines up with the vector from the joint to the target,

v \;=\; t - p_i.

The rotation angle is exactly the angle between them, \theta = \operatorname{atan2}\!\big(u \times v,\; u \cdot v\big) (a 2-D cross product on top, a dot product on the bottom). Apply that rotation to the joint and everything downstream of it, move inward to p_{i-1}, and repeat. One pass from p_{n-1} down to p_0 is a sweep; keep sweeping until the end-effector is close enough.

No matrices, no trig tables beyond one \operatorname{atan2} per joint — which is why CCD fits in a dozen lines. Its cost is convergence: because each joint greedily aims the tip, the joints nearest the end-effector do most of the work, and a chain can take many sweeps to settle, sometimes into a curled, unnatural shape.

Worked example: one CCD step on a 3-joint chain

Take joints p_0=(0,0), p_1=(3,1), p_2=(4,3) and end-effector p_3=(4,5), reaching for t=(6,4). CCD starts at the joint nearest the tip, p_2.

Aim vectors at p_2: u = p_3 - p_2 = (0,2) and v = t - p_2 = (2,1). The rotation needed is \theta = \operatorname{atan2}(0\cdot 1 - 2\cdot 2,\; 0\cdot 2 + 2\cdot 1) = \operatorname{atan2}(-4, 2) \approx -63.4^\circ. Swing the last bone (length 2) onto the aim line and the tip lands at

p_3' \;=\; p_2 + 2\,\frac{v}{\lVert v\rVert} \;=\; (4,3) + \frac{2}{\sqrt5}(2,1) \;\approx\; (5.79,\, 3.89).

The old tip (4,5) was a distance \sqrt{(6-4)^2+(4-5)^2}=\sqrt5\approx 2.24 from the target; the new tip (5.79,3.89) is only \approx 0.24 away — one joint, one dot product, and the error dropped nine-fold. Now move inward: at p_1=(3,1) recompute u = p_3' - p_1 and v = t - p_1 and rotate again, then finish at the root. Each inner joint trims the remaining error a little more, and the next full sweep trims it again.

FABRIK: forget angles, drag the beads

FABRIK (Aristidou & Lasenby, 2011) treats the chain like beads on a stiff string and never mentions an angle. One iteration is two passes.

Each re-placement is a single linear interpolation along the bone direction — no trig, no matrix, just \operatorname{lerp}. FABRIK typically needs far fewer iterations than CCD and produces smooth, natural-looking poses because the correction is shared along the whole chain rather than dumped on the tip. If the target is farther away than the fully-extended chain can reach (\lVert t - p_0\rVert > \sum_i d_i), FABRIK skips the passes and simply lays the chain out straight, pointing at the target.

Worked example: one FABRIK back-and-forth pass

Two bones of length d_0=d_1=2, root at p_0=(0,0), current pose p_1=(2,0), p_2=(4,0) (arm straight along the x-axis), reaching for t=(2,2).

Backward pass. Put the tip on the target: p_2 \leftarrow (2,2). Re-place p_1 a bone-length back toward the old p_1: the direction from the new p_2=(2,2) to p_1=(2,0) is straight down, so p_1 \leftarrow (2,2)+2\cdot(0,-1) = (2,0). The root would need to sit a bone-length from (2,0) toward the old root — that lands it at (0,0) here, but in general it drifts.

Forward pass. Re-anchor the root: p_0 \leftarrow (0,0). Re-place p_1 a bone-length out toward its backward-pass position (2,0): direction (1,0), so p_1 \leftarrow (2,0). Re-place p_2 a bone-length out toward (2,2): direction from (2,0) to (2,2) is up, giving p_2 \leftarrow (2,2) — already on the target. Notice both bones stayed exactly length 2 throughout: that is the whole trick. A more twisted target needs several such passes, but each is just a chain of lerps.

Reach for it: an interactive chain

Below is a four-bone chain anchored at the root. Drag the two sliders to move the target and watch the chain solve, one FABRIK step per update, to place its end-effector on the mark — bending smoothly and keeping every bone the same length. Push the target beyond the chain's reach and the arm straightens out and points at it, the best it can do without stretching.

A stadium full of characters can each need an IK pass every frame — feet planted on uneven ground, hands on rails, heads tracking the ball. The Jacobian pseudo-inverse would mean building and inverting a matrix per limb per frame, which does not scale to hundreds of skeletons at 60 fps. CCD and FABRIK cost only a handful of dot products or lerps per joint, run in a fixed few iterations, and need no allocation — so a whole crowd of two-bone leg chains is almost free. This is exactly why FABRIK, though only published in 2011, spread through game engines so quickly: it is fast, stable, and about thirty lines of code.

Because CCD lets each joint greedily aim the end-effector at the target, the joints nearest the tip tend to move the most — they have the shortest lever and the biggest immediate effect, so the solver over-rotates them and leaves the base of the limb barely bent. The result is a characteristic kink near the hand: an elbow-and-wrist that fold sharply while the shoulder stays lazy, which reads as unnatural. Damping each joint's rotation, capping angles with joint limits, or weighting the sweep helps, but out of the box CCD looks robotic. FABRIK distributes the correction along the entire chain by construction, so its poses come out smoother and more limb-like. When you want a natural arm or leg with the least fuss, reach for FABRIK; keep CCD for when its simplicity or its per-joint angle limits are what you need.