Skip to content
SDB
04Mathematics

Forward and inverse kinematics, without the fog

Two questions every articulated mechanism asks: given the joint angles, where is the tip? Given a tip pose, which angles get you there? The math is the same whether the arm is on a desk, a factory floor, or a simulation.

Subhendu Datta Bhowmik10 min read

Every motor on a typical robot arm is a revolute joint: it rotates about a fixed axis. The tool or gripper at the far end is the last link in that chain. Kinematics answers two inverse questions about that chain. Once you see them clearly, the rest of the machinery — matrices, Jacobians, solvers — is bookkeeping.

The two questions

Forward kinematics (FK). Given the joint angles qq, where is the end-effector in the base frame? The answer is a pose: position (x,y,z)(x,y,z) and orientation RR. The map is unique. One set of angles produces one pose. You multiply transforms.

Inverse kinematics (IK). Given a desired tip pose pp^*, which joint angles put the tip there? That map may have many solutions, one, or none — out of reach, or past joint limits.

Those two questions apply to any serial chain: a desk arm, a welding robot, a crane, even a 2D cartoon of sticks on paper. The dimension and the joint count change; the questions do not.

Warm-up: a 2-joint planar arm

Six-degree-of-freedom formulas look dense because they are 4×44\times 4 matrices. On a flat table with two hinges, the same FK is high-school trigonometry. Do this once on paper; everything later is the same idea in 3D.

Put the shoulder at the origin. Link 1 has length L1L_1, link 2 has L2L_2. Joint 1 rotates by θ1\theta_1, joint 2 by θ2\theta_2 relative to link 1. The tip is:

x=L1cosθ1+L2cos(θ1+θ2)y=L1sinθ1+L2sin(θ1+θ2)\begin{aligned} 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) \end{aligned}

Why add? The second link starts where the first ends. The first term is the elbow; the second is elbow to tip.

Worked numbers with L1=65mmL_1 = 65\,\mathrm{mm}, L2=116mmL_2 = 116\,\mathrm{mm}, θ1=30\theta_1 = 30^\circ, θ2=45\theta_2 = 45^\circ:

  • cos30=0.8660\cos 30^\circ = 0.8660, sin30=0.5000\sin 30^\circ = 0.5000
  • θ1+θ2=75\theta_1+\theta_2 = 75^\circ, cos75=0.2588\cos 75^\circ = 0.2588, sin75=0.9659\sin 75^\circ = 0.9659
  • x=650.8660+1160.2588=86.31mmx = 65\cdot 0.8660 + 116\cdot 0.2588 = 86.31\,\mathrm{mm}
  • y=650.5000+1160.9659=144.54mmy = 65\cdot 0.5000 + 116\cdot 0.9659 = 144.54\,\mathrm{mm}

Drag the sliders below to see that formula live. The printed (x,y)(x,y) should match the drawing, and the 4×44\times 4 readout is the same FK answer packed as a homogeneous transform.

Live FK · 2-joint planar arm

x = 86.31 mm, y = 144.55 mmreach = 168.4 mm (max 181)

The same answer as a matrix

T₀ᴱᴱ  ≈  (2-joint planar FK)
[    0.259   -0.966    0.000   86.315 ]
[    0.966    0.259    0.000  144.547 ]
[    0.000    0.000    1.000    0.000 ]
[    0.000    0.000    0.000    1.000 ]

Check: first link ends at (56.29, 32.50)
Drag the angle sliders. The printed (x, y) should match the drawing.

IK for this arm has a closed form from the law of cosines. Let r2=x2+y2r^2 = x^2 + y^2:

cosθ2=x2+y2L12L222L1L2,θ2=±arccos()\cos\theta_2 = \frac{x^2 + y^2 - L_1^2 - L_2^2}{2 L_1 L_2}, \qquad \theta_2 = \pm \arccos(\cdot)

The ±\pm is elbow-up versus elbow-down — two ways to put the tip at the same (x,y)(x,y). If cosθ2>1|\cos\theta_2| > 1, the point is outside the reachable ring and IK fails honestly.

Plug in the numbers above and you recover θ2±45\theta_2 \approx \pm 45^\circ; then θ1\theta_1 follows from atan2\mathrm{atan2}. That is already inverse kinematics: pose in, angles out.

Drag the green target (or use the x,yx,y sliders). The arm solves IK live. The grey dashed arm is the other elbow solution. Drag outside the rings and IK fails (cosθ2>1|\cos\theta_2| > 1).

Live IK · drag the target

p*
ElbowPresets
reachable |cos θ₂| ≤ 1θ₁* = 30.4°, θ₂* = 44.6°|e| = 0.00 mm

The cosine formula, live

p* = (86.0, 145.0) mm
cos θ₂ = (x² + y² − L₁² − L₂²) / (2 L₁ L₂)
       = (86.0² + 145.0² − 4225 − 13456) / 15080
       = 10740.0 / 15080 = 0.7122   →  |cos| ≤ 1, two elbows
active elbow sign = +1 (up)   θ₂ = ±arccos(·)
θ₁ = atan2(y, x) − atan2(L₂ sinθ₂, L₁ + L₂ cosθ₂)
FK check of this q*:  tip = (86.00, 145.00)   |e| = 0.00 mm
other elbow: θ₁ = 88.2°, θ₂ = -44.6°  (grey dashed)
Grey rings = reachable workspace. Dashed arm = the other elbow solution.

A longer 3D arm rarely has an equally simple cosine formula for every joint. The meaning does not change. You still ask “which angles put the tip here?” You answer with a matrix chain for FK and, when needed, a numerical solver for IK.

What a 4×4 homogeneous transform does

Section two already did forward kinematics in 2D: given θ1,θ2\theta_1,\theta_2, add the sticks. A homogeneous transform is not a third kind of kinematics. It is the same idea rewritten so it still works when the chain leaves the page — pan, lift, roll, full 3D.

A rigid link has its own “here”: the shoulder’s here, the elbow’s here, the tip’s here. Those heres differ in two ways only:

  • Where that piece sits — a translation
  • Which way it faces — a rotation

A 4×4 homogeneous transform packs both into one object. Think of it as a sticky note on a link:

If you are standing at the previous joint, take this many millimetres in this direction, then spin this many degrees — now you are standing at me.

Why 4×4, not 3×3? A 3×3 can spin a point but cannot slide it. A 3-vector can slide but cannot spin. One multiply then means “move from this joint to the next.” Walking the whole arm is applying those notes in order — which in algebra is multiplying them.

T=[Rt01]=[R11R12R13txR21R22R23tyR31R32R33tz0001]T = \begin{bmatrix} R & t \\ 0^\top & 1 \end{bmatrix} = \begin{bmatrix} R_{11} & R_{12} & R_{13} & t_x \\ R_{21} & R_{22} & R_{23} & t_y \\ R_{31} & R_{32} & R_{33} & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix}

The top-left 3×33\times 3 (RR) is orientation. The right column tt is the origin. The bottom row is always (0,0,0,1)(0,0,0,1) so slide and spin stay in one multiply.

Apply TT to a point written as a 4-vector:

[p1]=T[p1]p=Rp+t\begin{bmatrix} p' \\ 1 \end{bmatrix} = T \begin{bmatrix} p \\ 1 \end{bmatrix} \quad\Rightarrow\quad p' = R p + t

Compose frames by multiplying. If TABT_A^B is “BB as seen from AA” and TBCT_B^C is “CC as seen from BB,” then:

TAC=TABTBCT_A^C = T_A^B \, T_B^C

Order matters. Parent-then-child is the physical chain: base, then joint 1, then joint 2, and so on. Six motors does not mean a 6×6 pose matrix. Each joint still has its own 4×44\times 4; the product is still 4×44\times 4, because the tip still has one position and one orientation in 3D space.

If you skip thisWhat goes wrong later
Treat A1A2A3A_1 A_2 A_3\ldots as mysterious symbolsYou miss that FK is only sticking notes together from base to tip
Add poses instead of multiplying themAngles do not add like lengths in 3D
Mix order (A2A1A_2 A_1 vs A1A2A_1 A_2)The tip flies to the wrong place
Cannot read (x,y,z)(x,y,z) out of TTYou cannot check height, reach, or alignment

One joint’s matrix, then the chain

Each revolute joint ii contributes one matrix Ai(qi)A_i(q_i). In the Denavit–Hartenberg (DH) convention, that note is four tiny moves — fixed link geometry times the live motor angle:

Ai(qi)=Rotz(qi)Transz(di)Rotx(αi)Transx(ai)A_i(q_i) = \mathrm{Rot}_z(q_i)\, \mathrm{Trans}_z(d_i)\, \mathrm{Rot}_x(\alpha_i)\, \mathrm{Trans}_x(a_i)
PieceWhat it doesChanges when you move the motor?
Transx(ai)\mathrm{Trans}_x(a_i)Walk along the link lengthNo
Rotx(αi)\mathrm{Rot}_x(\alpha_i)Twist so the next hinge points the right wayNo
Transz(di)\mathrm{Trans}_z(d_i)Slide along the hinge axisNo
Rotz(qi)\mathrm{Rot}_z(q_i)The motor turningYes — this is qiq_i

Rule of thumb: if the letter has a joint index ii and depends on one angle, it is an AA. If it has a from–to pair and is a product, it is a TT.

Walk from the base (frame 0) out to the end-effector by multiplying one AiA_i at a time:

T01=A1(q1)T02=T01A2(q2)=A1A2T0EE=A1A2An\begin{aligned} T_0^{1} &= A_1(q_1) \\ T_0^{2} &= T_0^{1}\, A_2(q_2) = A_1 A_2 \\ &\vdots \\ T_0^{\mathrm{EE}} &= A_1 A_2 \cdots A_n \end{aligned}

That product is the tip pose. You do not invert anything to read it. Copy the right-hand column for position pEE=tp_{\mathrm{EE}} = t, and the top-left 3×33\times 3 for orientation REER_{\mathrm{EE}}.

Why not one giant formula for (x,y,z)(x,y,z) like the 2-joint warm-up? You can, after multiplying all AiA_i. It becomes a mess of nested sines. Keeping small crates is shorter, matches how robot descriptions (URDF and friends) store the chain, and is what kinematics libraries do.

What FK is for in practice

Once you can compute pEE(q)p_{\mathrm{EE}}(q) from measured or recorded joints, you can ask ordinary engineering questions without solving IK:

  1. Height. Is the tip near the object height at the grasp frame?
  2. Target alignment. Is the tip over the intended drop or weld point?
  3. Reachability. Is pEE\|p_{\mathrm{EE}}\| within the sum of the long links?
  4. Clearance. After a pick, did zz rise above the table — or did the tip drag sideways?

Those checks use joints you already have. Finding new joints that would reach a chosen pp^* is the inverse problem.

FK is unique. IK is the awkward reverse. Many angle combinations can share one tip pose. Sometimes none work.

In one sentence: find qq^* such that FK lands near the chosen point pp^*, without breaking motor limits.

q=argminq  pEE(q)p2s.t.qminqqmaxq^* = \arg\min_q \; \| p_{\mathrm{EE}}(q) - p^* \|_2 \quad\text{s.t.}\quad q_{\min} \le q \le q_{\max}

Jaw open/close (or any DOF that does not move the tool frame) is usually a separate map, not part of this position puzzle.

IK can fail honestly: target beyond maximum reach, behind the pedestal, or past a joint limit. That is a layout or task problem, not a bug in the formula. A good solver must say “no” rather than invent a pose that would snap a servo.

Numerical IK: nudge, measure, repeat

For more than a couple of planar joints, you usually do not magically invert FK. You nudge the motors a little, ask FK where you landed, repeat until the tip is close enough to pp^*. That loop is numerical IK.

The error is the leftover miss:

e=ppEE(q)e = p^* - p_{\mathrm{EE}}(q)

The Jacobian J(q)J(q) is a table of “what if I twitch one motor?” Each column is one servo: a tiny turn of that motor moves the tip in this Cartesian direction. For position-only IK on nn motors, JJ is 3×n3\times n. It grows with joint count; the pose matrix T0EET_0^{\mathrm{EE}} does not.

On the 2-joint warm-up the same table is small enough to write out:

J=[L1sinθ1L2sin(θ1+θ2)L2sin(θ1+θ2)L1cosθ1+L2cos(θ1+θ2)L2cos(θ1+θ2)]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}

You want a small joint change Δq\Delta q such that JΔqeJ\,\Delta q \approx e. When JJ is wide (more knobs than directions), many Δq\Delta q could work. A common compromise is damped least-squares:

Δq=J+e,J+=J(JJ+λ2I)1\Delta q = J^{+} e, \qquad J^{+} = J^\top \bigl(J J^\top + \lambda^2 I\bigr)^{-1}

λ\lambda is a small cushion. If λ=0\lambda = 0 and the arm is stretched (a singularity), Δq\Delta q can explode. Think of λ\lambda as “do not panic when the cheat sheet is unclear.”

Each iteration:

  1. Start from current qq
  2. FK: where is the tip?
  3. Form the miss ee
  4. Compute Δq=J+e\Delta q = J^{+} e
  5. Set qq+Δqq \leftarrow q + \Delta q, clip to joint limits
  6. Stop when e\|e\| is tiny, or give up after too many tries

Watch that loop on the same 2-joint arm. Drag the target, then Step once to apply one Δq=J+e\Delta q = J^{+} e, or Solve until the miss is under 2mm2\,\mathrm{mm}. This is the same recipe a 6-DOF solver uses; here JJ is 2×22\times 2 so every number stays readable.

Live numerical IK · Jacobian DLS

p*
iter 0|e| = 84.76 mmθ₁ = 15.0°, θ₂ = 25.0°idle — Step or Solve

Iteration log

q starts at (15°, 25°). Each step: e = p* − FK(q),  Δq = J⁺ e.
Drag the target, then Step once or Solve. Red dashed line is the miss arrow e.

The starting guess matters. From a folded posture the solver may pick the other elbow configuration or get stuck. When the real arm is in the loop, seed from measured joints; when replaying without feedback, seed from the previous solution.

After qq^* exists, motion control interpolates from today’s joints to that goal. That interpolation is neither FK nor IK — it is the sequel to IK. Learning policies that copy joint trajectories from demonstration skip the online IK path entirely; they still benefit from FK as a check that the demonstrated joints made geometric sense.

Symbol cheat-sheet

SymbolMeaning
qq, qiq_iJoint vector / ii-th motor angle (use radians in the formulas)
Ai(qi)A_i(q_i)One joint’s 4×44\times 4 sticky note
T0EET_0^{\mathrm{EE}}Full FK product: tip pose in the base frame
RR, ttOrientation and translation inside a homogeneous transform
pEEp_{\mathrm{EE}}, pp^*Tip position from FK; desired tip position for IK
eeCartesian miss ppEEp^* - p_{\mathrm{EE}}
JJ, J+J^{+}Jacobian and (damped) pseudoinverse
LmaxL_{\max}Rough reach bound — sum of the long link lengths

Takeaways

  1. FK multiplies joint transforms and reads the tip. Unique, cheap, always available once you have qq.
  2. IK searches for angles that realise a pose. Multiple, one, or zero answers — and failure is information.
  3. The 4×44\times 4 is a packing crate for “slide + spin.” Six joints still yield one 4×44\times 4 tip pose; the Jacobian is what grows with joint count.
  4. Start with the 2-joint arm on paper. Every longer chain is the same two questions with more sticky notes.

Angles in, pose out. Pose in, angles out. Everything else is how carefully you ask those two questions in three dimensions.

Filed under

  • Kinematics
  • Robotics
  • Linear algebra
  • Homogeneous transforms

Keep reading

Mathematics16 min read

The shape of an argument: a field guide to statistics

Twenty-seven methods, one question behind each: does this pattern mean something, or could it just be noise? Grouped by what they are for, with the reasoning and a worked example behind every one.

Read essay →
Mathematics9 min read

The calculus behind neural networks

How a network turns a wrong guess into a better one — one derivative at a time. The chain rule, activation derivatives, the softmax–cross-entropy shortcut, and a worked example you can trace by hand.

Read essay →
Mathematics3 min read

Queueing theory explains your outage

One equation from 1961 predicts why your service falls over at 80% utilisation and not at 100%. It is the most useful mathematics I have ever applied to a production system.

Read essay →