Skip to content

Inverse Kinematics

Given a target, which joint angles put the hand there? Sometimes two answers, sometimes none

1. The reverse question

Forward kinematics takes two angles and returns a point. Inverse kinematics takes the point and returns the angles. The target is a hand position (x, y); the unknowns are θ1 and θ2. For a planar 2R arm the answer is closed-form: no iteration, no initial guess, just two triangles.

What inverse kinematics solves

The first step is not trigonometry; it is a reachability check. If the target is outside the annulus from the previous lesson, no angle pair can satisfy the equations. A solver that skips this check will return a number that looks plausible and is wrong.

2. The triangle

Draw the base, the elbow, and the hand. Those three points form a triangle with sides L1, L2, and r, where r is the distance from the base to the target. The angle at the elbow is π − θ2, because θ2 is the exterior bend. The law of cosines then gives θ2 directly.

Distance and the elbow angle

There are two angles with the same cosine: θ2 and −θ2. Both put the hand at the same distance from the base. The sign chooses which side of the base-to-target line the elbow sits on.

The two elbow branches

3. Two elbows

Once θ2 is known, the base angle follows from the direction of the target and the direction of the second link. The expression below is the standard one: point the base at the target, then subtract the angle that the forearm takes away from that line.

Base angle for a chosen elbow

The two signs of θ2 produce the two elbows. For a target above the x-axis, the negative branch is the elbow-up pose and the positive branch is the elbow-down pose. For a target below the axis the labels flip relative to the screen, which is why the playground calls them θ2 < 0 and θ2 > 0 instead of “up” and “down.”

Why the elbow can be on either side

The arm is a two-bar linkage. The distance from the base to the hand fixes the triangle, but not its reflection. Reflecting the triangle across the base-to-target line gives the other solution, and both are physically valid unless a joint limit or an obstacle rules one out.

4. Worked example

Take L1 = L2 = 1 m and target (1, 1). The distance is r = √2. The cosine of θ2 is zero, so θ2 is ±90°. The base angle is 45° minus the forearm offset.

Example: L1 = L2 = 1 m, target (1, 1)

Branch 1, θ2 = +90°:

The arm goes straight along +x, then straight up. The elbow is at (1, 0) and the hand is at (1, 1).

Branch 2, θ2 = −90°:

The upper arm goes straight up, then the forearm goes straight right. The elbow is at (0, 1) and the hand is again at (1, 1). Both branches are exact.

Plug either branch back into forward kinematics to verify the point. If the numbers do not return (1, 1), the sign convention or the angle sum is wrong. The playground shows both branches at once, so you can check the geometry before trusting the arithmetic.

5. No solution, many solutions

Three cases deserve names. They are not edge cases to handle later; they are the normal behavior of inverse kinematics.

  • Outside the annulus — r > L1 + L2 or r < |L1 − L2|. The triangle cannot close. There is no real θ2, and the solver must report failure rather than clamp silently.
  • On the boundary — r = L1 + L2 or r = |L1 − L2|. The two branches merge into one. The arm is straight or fully folded, and the Jacobian determinant is zero.
  • At the base with equal links — r = 0 and L1 = L2. The elbow can be anywhere on the circle, so there are infinitely many solutions. A closed-form solver picks one arbitrarily unless you add a preference.
Jacobian determinant for the planar 2R arm

6. Practice

Try it

L1 = L2 = 1 m, target (0, 1). How many inverse-kinematics solutions are there, and what are the elbow angles?

Try it

L1 = L2 = 1 m, target (2.2, 0). What does inverse kinematics return?

Try it

At full extension, θ2 = 0. What is det J, and what does it mean physically?

Try it

Why does the solver need a branch choice even when the target is reachable?

7. Resources

The arm playground is the check: drag the target, switch the branch, and watch the readouts. Then change the link lengths until the target falls inside the hole or beyond the fingertip. The solver should refuse, not invent an angle.

Open the arm playground →

Continue the track

Open the playground for this topic

Arm Playground →

Drag a target. The planar arm solves its own inverse kinematics, and you can switch elbows or change link lengths.

The mathematics behind this topic: Multivariable calculus.

Site soundtrack