Reach for your coffee cup. You don't think "rotate the shoulder 40 degrees, bend the elbow 70". You look at the cup, and your brain works out the joint angles for you. A robot arm has to do the same thing, except nobody does it for it. It can only command its motors to turn to certain angles, but the task is always about a place in the world: pick up that part, weld this seam, draw a line here.
The geometry that connects the two is called kinematics. It runs in two directions:
- Forward kinematics (FK): "I know the joint angles. Where is the hand?"
- Inverse kinematics (IK): "I want the hand there. Which joint angles get it there?"
The first direction is easy and always has exactly one answer. The second is the one robots actually need, and it can have two answers, or none at all. Below is a small robot arm you can play with before we touch any maths.
Pick Forward kinematics and drag the sliders, or pick Inverse kinematics and move over the paper. Open the figure on its own page →
The setup: links, joints and two kinds of space
The arm in the figure is a SCARA robot, the type that does fast pick-and-place work in electronics factories. It has two links (stiff pieces, here $L_1 = 1.0$ m and $L_2 = 0.8$ m) and two joints that rotate flat over the table: the shoulder angle $\theta_1$ and the elbow angle $\theta_2$. Instead of a gripper, its end effector (the "hand") is a pen, so you can see where it goes.
Every robot lives in two spaces at once:
| Joint space | Task space | |
|---|---|---|
| What it describes | The motor angles | Where the hand is in the world |
| For this arm | $(\theta_1, \theta_2)$ | $(x, y)$ on the paper |
| Who cares | The motors | The task (and you) |
Forward kinematics maps joint space to task space, $x = f(\theta)$. Inverse kinematics goes back, $\theta = f^{-1}(x)$.
Forward kinematics: angles in, position out
Treat each link as an arrow. The first arrow starts at the shoulder, has length $L_1$ and points at angle $\theta_1$, so the elbow sits at:
$$x_e = L_1 \cos\theta_1, \qquad y_e = L_1 \sin\theta_1$$The second arrow starts at the elbow. The subtle part: $\theta_2$ is measured relative to the first link, not to the table, so link 2 points at $\theta_1 + \theta_2$. Add the two arrows and you have the pen:
Forward kinematics of a two-link planar arm
$$x = L_1 \cos\theta_1 + L_2 \cos(\theta_1 + \theta_2)$$ $$y = L_1 \sin\theta_1 + L_2 \sin(\theta_1 + \theta_2)$$Worked example. $\theta_1 = 30^\circ$, $\theta_2 = 45^\circ$, so link 2 points at $75^\circ$:
$$x = 1.0 \cos 30^\circ + 0.8 \cos 75^\circ = 0.866 + 0.207 = 1.073 \text{ m}$$ $$y = 1.0 \sin 30^\circ + 0.8 \sin 75^\circ = 0.500 + 0.773 = 1.273 \text{ m}$$That's the pose the figure starts in. Whatever angles you pick, there is exactly one answer, and you get it with two lines of trigonometry. That is why forward kinematics is the easy direction.
Inverse kinematics: position in, angles out
Now flip the question. The pen must go to $(x, y)$. The trick is to solve the elbow first, because the elbow angle alone decides how far the pen is from the shoulder.
Step 1: the distance fixes the elbow
The shoulder, the elbow and the pen form a triangle with sides $L_1$, $L_2$ and $d = \sqrt{x^2 + y^2}$. The law of cosines connects them:
$$\cos\theta_2 = \frac{x^2 + y^2 - L_1^2 - L_2^2}{2 L_1 L_2}$$If the right-hand side is bigger than 1 or smaller than −1, the point is out of reach: farther than $L_1 + L_2$ or closer than $|L_1 - L_2|$. Otherwise there are two angles with that cosine, $+\theta_2$ and $-\theta_2$. These are the two arm shapes, elbow down and elbow up:
$$\theta_2 = \operatorname{atan2}\left(\pm\sqrt{1 - \cos^2\theta_2},\ \cos\theta_2\right)$$Step 2: aim the shoulder
Point the shoulder at the target, then back off by the angle the bent forearm adds:
$$\theta_1 = \operatorname{atan2}(y, x) - \operatorname{atan2}\left(L_2 \sin\theta_2,\ L_1 + L_2 \cos\theta_2\right)$$
Use atan2, not atan. It looks at the signs of both arguments and returns the angle in the correct quadrant.
Worked example: inverting the result above. Target $(1.073, 1.273)$ m:
- $\cos\theta_2 = (1.151 + 1.620 - 1.000 - 0.640) / 1.600 = 0.707$, so $\theta_2 = \pm 45^\circ$.
- $\operatorname{atan2}(1.273, 1.073) = 49.9^\circ$ and the forearm correction is $19.9^\circ$.
- Elbow down ($\theta_2 = +45^\circ$): $\theta_1 = 49.9^\circ - 19.9^\circ = 30.0^\circ$, the pose we started from.
- Elbow up ($\theta_2 = -45^\circ$): $\theta_1 = 49.9^\circ + 19.9^\circ = 69.7^\circ$, a second, equally valid answer.
Press Flip elbow in the figure to watch this happen: the pen stays on the same point while the arm changes shape. A real controller chooses between the two using joint limits, obstacles, or whichever is closer to the current pose.
Why inverse kinematics is the hard direction
The two-link arm already shows every problem that makes IK difficult on real robots:
- Multiple solutions. Two for this arm. A typical six-axis industrial arm can have up to eight for a single pose.
- No solution. Targets outside the workspace (the arc on the paper) can't be reached, and the software has to notice before it moves.
- Singularities. When the arm is fully stretched ($\theta_2 = 0^\circ$) or folded back ($\theta_2 = 180^\circ$), it loses the ability to move in one direction. Near those poses tiny hand motions demand huge joint motions.
- Nonlinearity. The FK equations mix sines and cosines. Two links can be inverted with a triangle; six links in 3D usually can't be inverted by hand.
When there is no formula: numerical IK
For complex arms, IK is solved iteratively: guess the angles, run forward kinematics, measure the error, nudge the joints, repeat. The tool for the nudge is the Jacobian $J$, the matrix that maps small joint changes to small hand changes:
$$\Delta x = J(\theta)\, \Delta\theta, \qquad J = \begin{bmatrix} -L_1 \sin\theta_1 - L_2 \sin(\theta_1+\theta_2) & -L_2 \sin(\theta_1+\theta_2) \\ L_1 \cos\theta_1 + L_2 \cos(\theta_1+\theta_2) & L_2 \cos(\theta_1+\theta_2) \end{bmatrix}$$Its determinant is $\det J = L_1 L_2 \sin\theta_2$, which is zero exactly at the singularities above. Inverting $J$ there blows up, so practical solvers use damped least squares, which stays bounded:
$$\Delta\theta = J^\top \left(J J^\top + \lambda^2 I\right)^{-1} e, \qquad e = x_\text{target} - f(\theta)$$The code
Everything above in about 30 lines of Python: closed-form FK and IK, plus the numerical solver.
import numpy as np
L1, L2 = 1.0, 0.8
def fk(t1, t2):
x = L1 * np.cos(t1) + L2 * np.cos(t1 + t2)
y = L1 * np.sin(t1) + L2 * np.sin(t1 + t2)
return np.array([x, y])
def ik(x, y, elbow_up=False):
c2 = (x**2 + y**2 - L1**2 - L2**2) / (2 * L1 * L2)
if abs(c2) > 1:
return None # out of reach
s2 = -np.sqrt(1 - c2**2) if elbow_up else np.sqrt(1 - c2**2)
t2 = np.arctan2(s2, c2)
t1 = np.arctan2(y, x) - np.arctan2(L2 * s2, L1 + L2 * c2)
return t1, t2
def ik_numeric(target, q, lam=0.05, iters=100):
for _ in range(iters):
e = np.asarray(target) - fk(*q)
if np.linalg.norm(e) < 1e-4:
break
s1, s12 = np.sin(q[0]), np.sin(q[0] + q[1])
c1, c12 = np.cos(q[0]), np.cos(q[0] + q[1])
J = np.array([[-L1 * s1 - L2 * s12, -L2 * s12],
[ L1 * c1 + L2 * c12, L2 * c12]])
q = q + J.T @ np.linalg.solve(J @ J.T + lam**2 * np.eye(2), e)
return q
print(fk(np.radians(30), np.radians(45))) # [1.073 1.273]
print(np.degrees(ik(1.073, 1.273))) # [30.0 45.0]
print(np.degrees(ik(1.073, 1.273, elbow_up=True))) # [69.7 -45.0]
print(np.degrees(ik_numeric([1.073, 1.273], np.array([0.5, 0.5])))) # [30.0 45.0]
Beyond two links
Real arms work in 3D with six or seven joints, but the idea is the same. Each joint gets a 4×4 homogeneous transform (a rotation plus a translation), and forward kinematics is just the product of the chain:
$$T_\text{base}^\text{tool} = T_1(\theta_1)\, T_2(\theta_2) \cdots T_n(\theta_n)$$The Denavit–Hartenberg convention describes each link with four numbers so that every $T_i$ has the same form. Inverse kinematics for these arms is either a closed-form solution worked out for that specific geometry, or the numerical method above.
Wheeled robots have kinematics too, just in velocities. For a differential-drive car with wheel speeds $v_L$, $v_R$ and wheel spacing $W$:
$$v = \frac{v_R + v_L}{2}, \quad \omega = \frac{v_R - v_L}{W} \qquad\text{and back:}\qquad v_{L,R} = v \mp \frac{\omega W}{2}$$With $W = 0.145$ m (a small hobby car), wheel speeds of 0.20 and 0.30 m/s give $v = 0.25$ m/s and $\omega = 0.69$ rad/s: a circle of radius 0.36 m. That's forward kinematics. Asking for $v = 0.2$ m/s and $\omega = 1$ rad/s gives wheel speeds of 0.128 and 0.273 m/s: inverse kinematics.
Summary
| Forward kinematics | Inverse kinematics | |
|---|---|---|
| Input | Joint angles | Desired hand position |
| Output | Hand position | Joint angles |
| Number of answers | Exactly one | Two, many, or none |
| How | Add up the links (trigonometry or a chain of transforms) | Geometry for simple arms, Jacobian iterations for complex ones |
| Used for | Simulation, drawing the robot, knowing where it is | Planning motions, pick-and-place, following a path |
The 40-second version
Further reading
- Kevin Lynch and Frank Park, Modern Robotics: Mechanics, Planning, and Control: free PDF and lectures from the authors, with a strong chapter on numerical IK.
- John J. Craig, Introduction to Robotics: Mechanics and Control: the classic treatment of DH parameters and closed-form IK.
- Bruno Siciliano et al., Robotics: Modelling, Planning and Control: Jacobians, singularities and redundancy in depth.
The interactive figure was built with anatomy, an open-source skill for drawing isometric technical figures with Claude Code.