Inverse Kinematics
Forward kinematics goes from joint angles to hand position, which is easy and has one clean answer. Real tasks work in reverse: you see a cup at (x, y) and need to figure out what joint angles put your hand there. That's Inverse Kinematics (IK) — and unlike FK, it gets weird fast.
Core ideas covered in this module
- Elbow-up vs. elbow-down ambiguity
- Workspace boundaries & singularities
- Geometric vs. iterative IK (CCD)
Ambiguity, unreachable targets, and stretched-out singularities
Try touching a spot on your desk in front of you without moving your hand. You can probably drop your elbow down low or hike your elbow up high while keeping your fingertips in the exact same spot. A 2-link arm has that same two-branch choice: elbow-up vs. elbow-down.
Now try reaching a mug across the room without leaning forward: the target is outside your reachable workspace, so no exact solution exists. And right at the edge where your arm stretches completely straight, you hit a singularity — moving the hand radially outward becomes impossible, and tiny changes in target direction force large joint swings.
Triangle geometry vs. iterative solvers
For a 2-link planar arm, we can solve IK in one shot using the law of cosines on the triangle formed by the shoulder, elbow, and target. For a 7-DOF arm or a humanoid reaching around a shelf, closed-form formulas are messy or nonexistent, so we use iterative solvers like Cyclic Coordinate Descent (CCD) or Jacobian methods: start from the current pose and nudge one joint at a time to reduce tip error step by step.
Interactive lab
Iterative vs. Geometric Inverse Kinematics Playground
Canvas / SVG· LiveAmbiguous Solution Branch
Dashed links show the alternate valid configuration that reaches the exact same hand point.
Watching CCD converge (and why it slows down)
In Iterative (CCD) mode, click +1 Step a few times. Each iteration aligns the elbow toward the target, then aligns the shoulder toward the target. The first two or three steps slash most of the distance error; later steps polish the final millimeters.
Because iterative solvers start from the arm's current joint angles, they naturally stay on whichever elbow branch is closest instead of violently flipping configurations mid-motion.
Law of cosines for 2-link elbow angle
cos(θ₂) = (x² + y² - L₁² - L₂²) / (2 · L₁ · L₂) → θ₂ = ± arccos(...)
If the right-hand side falls outside [-1, 1], the target is unreachable. The ± sign gives the elbow-down and elbow-up solutions.
Why does a 2-link arm suddenly show two valid IK solutions for most points inside its workspace, and only one right on the outer boundary circle?
Many teleoperation rigs and learned policies output target end-effector poses at 20–50 Hz and rely on a damped iterative IK solver underneath to convert those poses into smooth, singularity-safe joint commands.
Hands-On Python Notebook
05 · Inverse Kinematics: Geometric vs. Iterative CCD
Implement closed-form law-of-cosines IK alongside iterative Cyclic Coordinate Descent (CCD) and plot convergence error across iterations.
Try this on your own inside the notebook
- Test a target right on the singularity boundary r = L₁ + L₂
- Adapt solve_ik_ccd() to handle a 3-link planar arm
In Google Colab, use File → Save a copy in Drive to keep your own edits and notes. Or download the files directly:
uvx marimo edit --sandbox notebooks/course-1/05_inverse_kinematics.pyWrap up this module
Saved automatically in your browser profile so you can pick up right where you left off.