Skip to content
Tactiverge

Forward and inverse kinematics of a two-link arm

Work out where a simple robot arm's hand will be from its joint angles, and then reverse the problem to find joint angles that reach a target.

40 min · Self-paced · Free

Two directions of the same problem

Kinematics is the study of motion without worrying about the forces that cause it. For a robot arm, it is the geometry connecting two descriptions of the same arm:

  • Joint space: the angles of each joint.
  • Task space: the position of the hand (end effector) in the world.

Going from joint angles to hand position is called forward kinematics. It answers, "If I set the joints like this, where does the hand end up?" Going the other way, from a desired hand position to the joint angles that achieve it, is inverse kinematics. It answers, "I want my hand there — how should I set my joints?" Robots need both, and as you will see, they are very different in difficulty.

The setup

We will study the simplest interesting arm: two links moving in a flat plane, like an arm lying on a table.

  • Link 1 has length L₁ and is attached to the base at the origin by a revolute joint with angle θ₁, measured anticlockwise from the x-axis.
  • Link 2 has length L₂ and is attached to the end of link 1 by a second revolute joint with angle θ₂, measured relative to link 1. So θ₂ = 0 means the arm is straight.

That last detail matters. Because θ₂ is measured relative to link 1, the absolute direction of link 2 in the world is θ₁ + θ₂. When you raise your shoulder, your forearm rises too, even if your elbow does not move.

Forward kinematics

Using the last lesson's tools, the elbow (end of link 1) is at:

elbow_x = L₁ · cos θ₁
elbow_y = L₁ · sin θ₁

Link 2 is a vector of length L₂ pointing at angle θ₁ + θ₂. Add it tip to tail:

x = L₁ · cos θ₁ + L₂ · cos(θ₁ + θ₂)
y = L₁ · sin θ₁ + L₂ · sin(θ₁ + θ₂)

That is the complete forward kinematics of a two-link planar arm. Every term has a physical meaning: the first term is link 1's contribution; the second is link 2's.

Worked example

Take L₁ = 10 cm, L₂ = 8 cm, θ₁ = 30° and θ₂ = 45°. Link 2 therefore points at 30° + 45° = 75°.

x = 10 · cos 30° + 8 · cos 75°
  = 10 · 0.8660  + 8 · 0.2588
  = 8.660 + 2.071
  ≈ 10.73 cm

y = 10 · sin 30° + 8 · sin 75°
  = 10 · 0.5000  + 8 · 0.9659
  = 5.000 + 7.727
  ≈ 12.73 cm

The hand is at about (10.73, 12.73). Its distance from the base is √(10.73² + 12.73²) ≈ 16.65 cm — less than the full reach of 18 cm, which makes sense because the elbow is bent.

Forward kinematics is always straightforward: plug in the angles and compute. There is exactly one answer.

Exploring the arm

Before tackling the inverse problem, build some intuition with the explorer below. Try these experiments:

  1. Set the second joint to 0 and sweep the first. The hand traces a circle of radius L₁ + L₂.
  2. Fold the second joint as far as it goes. How close to the base can the hand get?
  3. Pick a target point inside the reach. Can you find two different arm shapes that put the hand there?

Explorer 01 — Robotic kinematics

From joint angles to a position, and back again

REACH 35.0 CMHOLE 5.0J1J2(15.1, 26.4)

Fig. — 2-link planar arm · units cm · y up

Mode

Joint angles (relative)

35 °
60 °
More controls

Arm geometry

Links
20.0 cm
15.0 cm
End x
15.1 cm
End y
26.4 cm
Distance r
30.4 cm
workspace 5.0–35.0 cm
|sin θ2|
0.87
well-conditioned
Tip angle φ
95.0°

State

Forward kinematics. Joint angles: joint 1 35°, joint 2 60°. End effector at x 15.1 cm, y 26.4 cm, 30.4 cm from the base. Elbow well-conditioned (|sin θ2| = 0.87).

Forward kinematics. Joint angles: joint 1 35°, joint 2 60°. End effector at x 15.1 cm, y 26.4 cm, 30.4 cm from the base. Elbow well-conditioned (|sin θ2| = 0.87).

How to read this

The base sits at the centre (grid squares are 10 cm). Each thick bar is a link; circles are joints J1, J2. The shaded ring is the workspace: every point the tip can reach with unlimited joint travel. Its outer edge is L1 + L2; the inner hole appears when one link is longer than the others combined.

Arcs show each joint angle. θ1 is measured from the dashed horizontal; θ2 from the dashed extension of link 1. In inverse mode the square is the target (dashed and labelled unreachable when outside the ring), and the arm is solved with the law of cosines. Most targets have two solutions: elbow-up and elbow-down.

Assumptions & limitations
  • Ideal rigid links and revolute joints with no mass, friction, backlash, or flex.
  • Joints may rotate a full ±180°; real joints have hard limits that shrink the workspace, and links cannot pass through each other or the floor.
  • Kinematics only: nothing here says whether the motors are strong or fast enough to hold or reach a pose (that is dynamics).
  • Three-link inverse kinematics is made solvable by fixing the tool angle φ; real controllers choose among redundant solutions with extra goals.
  • Unreachable targets are projected onto the nearest edge of the reachable ring for display; a real controller would refuse or plan around them.
Change the joint angles and watch the hand move. Try to reach the same point with the elbow bent up and with it bent down.

Inverse kinematics

Now the hard direction. Given a target (x, y), find θ₁ and θ₂.

The trick is to work out the elbow angle first, using only distances. Let r be the distance from the base to the target, so r² = x² + y². The base, the elbow and the hand form a triangle with sides L₁, L₂ and r. The law of cosines relates the sides of any triangle to its angles, and for this arm it gives:

r² = L₁² + L₂² + 2 · L₁ · L₂ · cos θ₂

You can check it against the worked example: 100 + 64 + 2 · 10 · 8 · cos 45° = 164 + 113.1 = 277.1, and 16.65² ≈ 277.2. It matches, up to rounding. Rearranging:

cos θ₂ = (r² − L₁² − L₂²) / (2 · L₁ · L₂)

Cosine values must lie between −1 and 1. This simple fact tells you the workspace:

  • If the right-hand side is greater than 1, the target is too far away: r > L₁ + L₂. No solution.
  • If it is less than −1, the target is too close: r < |L₁ − L₂|. No solution.
  • If it is exactly 1 or −1, the arm must be fully straight or fully folded. One solution.
  • Otherwise, there are two angles with that cosine, +θ₂ and −θ₂. These are the "elbow down" and "elbow up" shapes you may have found in the explorer. Two solutions.

Once θ₂ is known, the shoulder angle follows:

θ₁ = atan2(y, x) − atan2(L₂ · sin θ₂, L₁ + L₂ · cos θ₂)

In words: point at the target, then subtract the angle by which the bent elbow swings the hand off that line.

Worked example

Same arm (L₁ = 10, L₂ = 8). Target: (12, 6).

r² = 12² + 6² = 180
cos θ₂ = (180 − 100 − 64) / (2 · 10 · 8) = 16 / 160 = 0.1
θ₂ ≈ ±84.26°

Take θ₂ = +84.26°. Then L₂ · sin θ₂ ≈ 7.960 and L₁ + L₂ · cos θ₂ = 10 + 0.8 = 10.8.

θ₁ = atan2(6, 12) − atan2(7.960, 10.8)
   ≈ 26.57° − 36.39°
   ≈ −9.82°

Check with forward kinematics: 10 · cos(−9.82°) + 8 · cos(74.44°) ≈ 9.85 + 2.15 = 12.00, and 10 · sin(−9.82°) + 8 · sin(74.44°) ≈ −1.71 + 7.71 = 6.00. It works. The other solution, θ₂ = −84.26°, gives θ₁ ≈ 26.57° + 36.39° = 62.96°, and also lands on (12, 6).

Always verify an inverse solution with forward kinematics. It is the easiest way to catch a sign error.

Why this matters

Real arms have more joints and move in three dimensions, but the pattern holds. Forward kinematics is a direct calculation. Inverse kinematics can have no solution, one, two or infinitely many (for redundant arms), and the robot must choose among them — perhaps the one that avoids an obstacle, stays within joint limits, or requires the least motion from where the arm is now.

Project

Paper and calculator project: map a workspace

Choose your own link lengths for a two-link arm (for example L₁ = 6 and L₂ = 4).

  1. On squared paper, draw the inner and outer edges of the workspace.
  2. Pick five target points: two well inside, one on the outer edge, one inside the inner hole and one outside the reach.
  3. For each, compute cos θ₂ and decide how many solutions exist.
  4. For one target with two solutions, compute both pairs of angles and check them with forward kinematics. Sketch both arm shapes.

A calculator in degree mode is enough. If you know some Python, you may write a short program instead — remember that Python's math functions use radians.

Deliverables

  • A scale drawing of the workspace with your five targets marked
  • A table of r², cos θ₂ and the number of solutions for each target
  • Both joint-angle solutions for one target, verified by forward kinematics

Knowledge check

Check your understanding

  1. 1. In a two-link arm with θ₂ measured relative to link 1, which angle gives the absolute direction of link 2?
  2. 2. With L₁ = 10 and L₂ = 8, both joints at 0°, where is the hand?
  3. 3. For a target, the inverse kinematics formula gives cos θ₂ = 1.4. What does this mean?
  4. 4. Why is it good practice to run forward kinematics on an inverse kinematics answer?
  5. 5. Which statement about inverse kinematics for a two-link planar arm is true?

Sign in to track your progress. Reading is free without an account.