The arm has a base yaw joint that swings the whole chain to face the target's compass bearing, plus four pitch joints (shoulder, elbow, wrist, wrist-tip) that reach for the target inside that vertical plane. Once the yaw is aligned, the problem reduces to a 2D chain trying to touch a point — solved every frame with Cyclic Coordinate Descent (CCD): walk the joints from the gripper back to the base, and at each joint rotate it by exactly the angle that swings the current end-effector position onto the target.
for iter in 1..N:
for i from last_joint down to first_joint:
toEffector = normalize(effector − joint[i].pos)
toTarget = normalize(target − joint[i].pos)
joint[i].angle += signedAngle(toEffector, toTarget)
joint[i].angle = clamp(joint[i].angle, limitMin[i], limitMax[i])
recompute forward kinematics
Each pass tends to shrink the gap between gripper and target; with enough iterations the chain converges onto the target whenever it lies inside the arm's reach. Clamping every joint's angle to its mechanical range after each rotation is what keeps the pose physically plausible — real servos and hydraulic joints cannot spin past their stops, so a target behind or below a limit simply can't be fully reached, and the arm settles as close as its geometry allows.
- Link length — scales every segment together, changing the arm's total reach (shown as the pale dashed reach sphere).
- IK iterations / frame — how many CCD passes run each frame before the result is capped by motor speed; too few and a fast-moving target lags or misses subtle poses.
- Motor speed — the maximum angular velocity applied to any single joint, so the arm swings into place like a real actuator instead of teleporting.
- Joint limits — toggle the mechanical stops on/off; with limits off the arm can bend into unrealistic poses but always reaches any target within its total length.
- Pick & place demo — drives the gripper through a scripted pick → lift → place → home cycle, exercising the same solver with automated targets instead of the mouse.
Real-world relevance: CCD (and its cousin FABRIK) is exactly how many industrial arms, robotic surgery tools and game-engine character rigs compute joint angles from a desired hand or gripper position — it is cheap, numerically stable, and needs no matrix inversion, unlike Jacobian-based IK.