Inverse Kinematics: Interactive

Forward kinematics finds the tool position from known joint angles. Inverse kinematics finds the joint angles from a known tool position. Drag the target. The two-link arm calculates the solution live.

2-LINK IK SOLVER
θ1+000° θ2+000° x+0.00 y+0.00 reachREACHABLE elbowDOWN
Drag anywhere to set the target
L1 = 0.9 · L2 = 0.7 · idle demo runs when you're not dragging

How it solves

For a target $(x, y)$ with link lengths $L_1, L_2$, let $r = \sqrt{x^2 + y^2}$. The law of cosines gives the elbow angle:

$$ \cos\theta_2 = \frac{x^2 + y^2 - L_1^2 - L_2^2}{2\,L_1 L_2} $$

The sign $\pm$ in $\theta_2 = \pm\arccos(\dots)$ gives the two solutions: elbow-down and elbow-up. The flip-elbow button changes between them. The shoulder angle is then:

$$ \theta_1 = \operatorname{atan2}(y, x) - \operatorname{atan2}\!\big(L_2 \sin\theta_2,\; L_1 + L_2\cos\theta_2\big) $$

When $r > L_1 + L_2$, the arm cannot get to the point. The arm extends straight to the target. The readout shows LIMIT, and a dashed line shows the gap. The course notes contain the full derivation.