Robotics Fundamentals

Understand Inverse
Kinematics

The math that translates "reach to that point" into the joint angles that actually get you there.

Prerequisites: Trigonometry + Basic linear algebra. That's it.
12
Chapters
12+
Simulations
0
Assumed Knowledge

Chapter 0: Why Inverse Kinematics?

You tell a robot arm: "Reach to position (0.5, 0.3, 0.7)." The robot stares at you blankly. It doesn't know what "positions" are. All it has are six motors, each capable of rotating to some angle. You want the hand at a specific position and orientation in space, but the robot only speaks the language of joint angles.

This is the inverse kinematics (IK) problem: given where you want the end-effector to be, figure out what every joint angle should be. It's the translation layer between human intention ("put the hand there") and robot execution ("set motor 1 to 42.3°, motor 2 to −15.7°, ...").

The forward direction is easy. If I tell you joint 1 is at 30° and joint 2 is at 45°, you can compute the end-effector position with basic trigonometry. That's forward kinematics (FK) — just plug angles into sine and cosine equations. Going backwards? That's where all the pain lives.

The reaching problem: Forward kinematics is a function: angles → position. Inverse kinematics asks you to invert that function. The trouble? The function is nonlinear (sines and cosines don't have simple inverses), there may be multiple solutions (your elbow can bend up or down to reach the same point), and sometimes there's no solution at all (the target is too far away).

Think about your own arm. Reach for a cup on the table. Now reach for the same cup but with your elbow pointed up instead of down. Same hand position, completely different arm configuration. That's multiple IK solutions in action. Now try to touch the ceiling while sitting — you can't. That's the workspace boundary. IK must handle all three cases.

The Reaching Problem

A 2-link arm is frozen in place. The orange target is where we want the hand to go. The arm doesn't know which joint angles would achieve that. That's the IK problem.

Why Does This Matter?

Every robot motion you've ever seen — a welding robot tracing a seam, a surgical arm inserting a needle, a Mars rover extending its instrument arm — requires solving IK. The motion planner says "move to this pose," and IK converts that into the motor commands that actually move the arm.

The stakes are high. A bad IK solver means the robot can't reach valid targets. A slow IK solver means the robot hesitates. An IK solver that misses solutions means the robot takes inefficient paths or collides with obstacles. Industrial robots solve IK millions of times per day.

FK vs IK: The Asymmetry

PropertyForward KinematicsInverse Kinematics
InputJoint angles (θ1, ..., θn)Desired pose (position + orientation)
OutputEnd-effector poseJoint angles
UniquenessAlways unique (one set of angles → one pose)Often multiple solutions (0, 2, 4, 8, or 16)
ExistenceAlways existsMay not exist (target unreachable)
ComplexityLinear chain of matrix multiplicationsNonlinear system of trigonometric equations
ComputationTrivial (<1 μs)Hard (1 μs to 10 ms depending on method)
Check: What makes inverse kinematics harder than forward kinematics?

Chapter 1: Forward Kinematics First

Before we can invert kinematics, we need to thoroughly understand the forward direction. Forward kinematics (FK) computes the end-effector position given all joint angles. For a planar 2-link arm, it's pure trigonometry — and it's the foundation everything else builds on.

The 2-Link Planar Arm

Picture two rigid links connected by revolute joints (joints that rotate). The first link of length L1 attaches to a fixed base at the origin. It rotates by angle θ1 measured counter-clockwise from the positive x-axis. The second link of length L2 attaches to the end of the first link, rotating by θ2 relative to the first link's direction.

Where is the elbow (the point where the two links meet)?

xelbow = L1 cos(θ1)     yelbow = L1 sin(θ1)

This is just polar-to-Cartesian conversion. The first link starts at the origin and extends at angle θ1 for length L1.

Where is the end-effector (the tip of the second link)? The second link starts at the elbow and extends at the absolute angle θ1 + θ2. Why the sum? Because θ2 is measured relative to link 1, so the total angle from horizontal is θ1 + θ2.

x = L1 cos(θ1) + L2 cos(θ1 + θ2)
y = L1 sin(θ1) + L2 sin(θ1 + θ2)

That's it. Two equations mapping two joint angles to one 2D point. Forward kinematics is just a chain of rotations — each joint rotates everything downstream of it.

The chain rule of robotics: Joint 1 rotates the entire arm (both links). Joint 2 rotates only link 2 and the end-effector. In a 6-joint 3D robot, joint 1 rotates everything, joint 2 rotates everything after it, and so on. FK is the composition of all these rotations.
Interactive 2-Link FK

Drag the sliders to change joint angles. Watch the arm move and see the FK equations compute in real-time. The gray trail shows where the end-effector has been.

θ145°
θ230°

Worked Example: Step by Step

Let's compute FK with concrete numbers. Set L1 = 1.0, L2 = 0.7, θ1 = 45°, θ2 = 30°.

Step 1: Convert degrees to radians (since cos/sin expect radians in most programming languages):

θ1 = 45° × π/180 = π/4 ≈ 0.7854 rad
θ2 = 30° × π/180 = π/6 ≈ 0.5236 rad

Step 2: Compute the absolute angle of link 2:

θ1 + θ2 = 75° ≈ 1.3090 rad

Step 3: Compute the elbow position:

xelbow = 1.0 × cos(45°) = 1.0 × 0.7071 = 0.7071
yelbow = 1.0 × sin(45°) = 1.0 × 0.7071 = 0.7071

Step 4: Compute the end-effector position:

x = 0.7071 + 0.7 × cos(75°) = 0.7071 + 0.7 × 0.2588 = 0.7071 + 0.1812 = 0.888
y = 0.7071 + 0.7 × sin(75°) = 0.7071 + 0.7 × 0.9659 = 0.7071 + 0.6761 = 1.383

Verify: The arm points upward and slightly to the right. At 75° total angle, the hand is nearly vertical. The numbers match our geometric intuition. Set the sliders in the widget above to θ1=45, θ2=30 and confirm!

From 2D to 3D

In 3D, the same principle applies but with rotation matrices instead of single angles. Each joint has a rotation axis (not just "counter-clockwise"), and the FK chain becomes a product of 4×4 homogeneous transformation matrices. We'll build up to that in Chapters 5 and 6.

python
import numpy as np

def fk_2r(theta1, theta2, L1=1.0, L2=0.7):
    """Forward kinematics for a 2-link planar arm."""
    x = L1 * np.cos(theta1) + L2 * np.cos(theta1 + theta2)
    y = L1 * np.sin(theta1) + L2 * np.sin(theta1 + theta2)
    return x, y

# Example: theta1=45°, theta2=30°
x, y = fk_2r(np.radians(45), np.radians(30))
print(f"End-effector: ({x:.3f}, {y:.3f})")
# Output: End-effector: (0.888, 1.383)
Key insight: FK is a chain of rotations. Each joint rotates everything downstream. Joint 1 rotates the entire arm. Joint 2 rotates only link 2. In 3D with 6 joints, this becomes a product of six 4×4 matrices — but the principle is identical. Understanding this chain is the foundation for understanding why IK is hard: we need to find the individual rotations that compose to a desired result.
Check: If θ1 = 90° and θ2 = 0° (both links L1 = L2 = 1), where does the end-effector point?

Chapter 2: The 2R IK Problem

Now we flip the problem. Given a target position (x, y), find the joint angles θ1, θ2 that place the end-effector there. This is the simplest possible inverse kinematics problem — only two unknowns — and it already reveals the core challenges: multiple solutions, workspace limits, and the power of geometric thinking.

The Geometric Approach

Instead of staring at the FK equations and trying to algebraically invert them, let's think geometrically. We have a triangle.

The three sides are:

By the law of cosines, we can relate the interior angle at the elbow to these three sides:

d² = L1² + L2² − 2 L1 L2 cos(π − θ2)

Why π − θ2? Because the interior angle of the triangle at the elbow is the supplement of θ2. When θ2 = 0, the arm is fully extended and the interior angle is π (180°). When θ2 = π, the arm folds back on itself and the interior angle is 0.

Since cos(π − θ2) = −cos(θ2), we can rearrange:

cos(θ2) = (x² + y² − L1² − L2²) / (2 L1 L2)

Call this value c2. This is a single number computed directly from the target position and the link lengths. Three things can happen:

Finding θ2: The atan2 Trick

A naive approach would be θ2 = arccos(c2), giving two solutions ±arccos(c2). But never use arccos for IK. Here's why:

At the workspace boundary (c2 = ±1), the derivative of arccos is infinite. A tiny numerical error in c2 (say, 1.0000001 instead of 1.0) produces a NaN. The robust approach computes both sin(θ2) and cos(θ2) separately:

s2 = ± √(1 − c2²)
θ2 = atan2(s2, c2)

The positive square root gives elbow-up. The negative gives elbow-down. Two physically different arm configurations that reach the same target.

The atan2 commandment: In all of IK, always use atan2(y, x) instead of acos or atan. The function atan2 is defined for all inputs (including zero), handles all four quadrants correctly, and never produces NaN. IK-Geo uses atan2 exclusively — it's one of the reasons the solver is singularity-robust.

Finding θ1

Once we know θ2 (and therefore c2 and s2), the FK equations become linear in sin(θ1) and cos(θ1). Let's see why.

Expand the FK equations using angle addition formulas:

x = L1 cosθ1 + L2(cosθ1 cosθ2 − sinθ1 sinθ2)
y = L1 sinθ1 + L2(sinθ1 cosθ2 + cosθ1 sinθ2)

Group the sinθ1 and cosθ1 terms:

x = (L1 + L2 c2) cosθ1 − (L2 s2) sinθ1
y = (L1 + L2 c2) sinθ1 + (L2 s2) cosθ1

Let k1 = L1 + L2 c2 and k2 = L2 s2. Then:

θ1 = atan2(y, x) − atan2(k2, k1)

This elegant formula has a geometric interpretation: atan2(y, x) is the angle from the base to the target, and atan2(k2, k1) is the offset angle caused by the elbow bend.

Worked Example

Target: (1.2, 0.8), L1 = 1.0, L2 = 0.8.

Step 1 — Compute c2:

c2 = (1.2² + 0.8² − 1.0² − 0.8²) / (2 × 1.0 × 0.8) = (1.44 + 0.64 − 1.0 − 0.64) / 1.6 = 0.44 / 1.6 = 0.275

Step 2 — Compute s2 and θ2:

s2 = ±√(1 − 0.275²) = ±√(0.9244) = ±0.9614

Elbow-up: θ2 = atan2(0.9614, 0.275) = 74.0°

Elbow-down: θ2 = atan2(−0.9614, 0.275) = −74.0°

Step 3 — Compute θ1 (for elbow-up):

k1 = 1.0 + 0.8 × 0.275 = 1.22
k2 = 0.8 × 0.9614 = 0.769
θ1 = atan2(0.8, 1.2) − atan2(0.769, 1.22) = 33.69° − 32.22° = 1.47°

Step 4 — Verify with FK:

x = cos(1.47°) + 0.8 × cos(75.47°) = 0.9997 + 0.2006 = 1.200 ✓
y = sin(1.47°) + 0.8 × sin(75.47°) = 0.0257 + 0.7744 = 0.800 ✓

The FK output matches the target exactly. Always verify IK solutions with FK — it's the cheapest debugging step in robotics.

Workspace: Where Can the Arm Reach?

The set of reachable points forms an annular ring (donut shape). The outer boundary is rmax = L1 + L2 (arm fully extended, θ2 = 0). The inner boundary is rmin = |L1 − L2| (arm folded back, θ2 = π). Any target inside this ring has exactly two IK solutions. Any target outside has zero.

python
import numpy as np

def ik_2r(x, y, L1=1.0, L2=0.8):
    """Inverse kinematics for 2R planar arm. Returns list of (th1, th2) pairs."""
    d2 = x**2 + y**2
    c2 = (d2 - L1**2 - L2**2) / (2 * L1 * L2)
    if abs(c2) > 1:
        return []  # unreachable
    solutions = []
    for sign in [1, -1]:
        s2 = sign * np.sqrt(max(0, 1 - c2**2))
        th2 = np.arctan2(s2, c2)
        k1 = L1 + L2 * c2
        k2 = L2 * s2
        th1 = np.arctan2(y, x) - np.arctan2(k2, k1)
        solutions.append((th1, th2))
    return solutions

# Verify:
for th1, th2 in ik_2r(1.2, 0.8):
    x, y = fk_2r(th1, th2, 1.0, 0.8)
    print(f"th1={np.degrees(th1):.1f}° th2={np.degrees(th2):.1f}° -> ({x:.3f}, {y:.3f})")
Interactive 2R IK — Drag the Target

Drag the orange target anywhere on the canvas. Both IK solutions are shown simultaneously: teal = elbow-up, orange = elbow-down. The gray ring shows the workspace boundary. Move the target outside the ring to see what happens when IK has no solution.

Drag the target dot
Check: How many IK solutions does a 2R planar arm have for a target strictly inside its workspace (not on the boundary)?

Chapter 3: The Geometric Insight — Circles

In Chapter 2, we solved 2R IK with the law of cosines. That worked beautifully for two joints in a plane. But real robots have six joints in 3D space, with arbitrary axis orientations. How do we scale up?

The IK-Geo framework (Elias & Wen, 2022) provides an elegant answer. The key insight is deceptively simple, and once you see it, you can't unsee it.

Rotation Traces a Circle

When you rotate a point p around an axis k by angle θ, the point traces out a circle. This is true in any number of dimensions, but it's easiest to visualize in 3D.

The circle lies on a plane perpendicular to k, centered at the point where k passes closest to p. The radius of the circle is the perpendicular distance from p to the axis k.

In 2D, this is obvious — rotating a point around the origin sweeps a circular arc. In 3D, the same thing happens, but the circle lives on a cone around the rotation axis. Think of a spinning top: a point on the rim traces a circle around the spin axis.

The IK-Geo master insight: Every joint in a robot arm is a revolute joint. A revolute joint can only rotate. Rotation of a point around an axis always traces a circle. Therefore, every joint variable parameterizes a circle. IK becomes: find the joint angles where the right circles intersect. Every IK problem, no matter how complex, reduces to intersecting circles with other circles, planes, or spheres.

Subproblem 1: Circle Meets Point

The simplest geometric IK subproblem: given a rotation axis k and a point p1, find the angle θ that rotates p1 as close as possible to a target point p2.

Geometrically: the set of all points R(k, θ)p1 as θ varies is a circle. We need the point on this circle closest to p2.

The solution is elegant: project both p1 and p2 onto the plane perpendicular to k. The angle between their projections is θ. If p2 lies exactly on the circle, we get an exact match. Otherwise, we get the closest point. At most one solution.

Subproblem 2: Two Circles Intersect

Now the case that connects directly to 2R IK: two joints, two unknowns. Rotating p1 around axis k1 traces one circle. Rotating p2 around axis k2 traces another circle. The IK solution requires both rotations to produce the same intermediate point — so we need the two circles to intersect.

Two circles in 3D can intersect at 0, 1, or 2 points. Each intersection gives a pair (θ1, θ2). This is exactly the elbow-up / elbow-down duality from Chapter 2 — but stated in pure geometry instead of trigonometric algebra.

The power of this perspective is that it generalizes effortlessly to 3D. The law of cosines only works for planar arms. The circle-intersection approach works for any pair of revolute joints, regardless of axis orientation.

Circle-on-Axis Visualization

Drag the θ slider to rotate the point p around the axis k. The point traces a circle. The target is fixed. Click Solve SP1 to find the closest approach.

θ

The Unifying View

Here's why this geometric perspective is so powerful. Consider a 6R robot. Each joint traces a circle. The FK chain says: rotate point through circle 1, then circle 2, then circle 3, and so on. IK asks: for which specific angles on each circle does the composition reach the target?

IK-Geo decomposes this into subproblems. Sometimes you can solve two consecutive joints by intersecting their circles (SP2). Sometimes you need to intersect a circle with a sphere defined by a distance constraint (SP3). Sometimes with a plane (SP4). Each subproblem has a closed-form solution.

Why circles? A revolute joint can only rotate. Rotation of a point around an axis always traces a circle. So each joint variable parameterizes a circle. IK = finding the angles where the right circles intersect. This unifying view is what makes IK-Geo both fast (closed-form atan2 solutions) and complete (finds ALL solutions, not just one).
Check: Subproblem 1 (circle-point) has how many exact solutions at most?

Chapter 4: All Six Subproblems

IK-Geo identifies six canonical subproblems. Every IK problem for a serial robot with revolute joints can be decomposed into combinations of these six building blocks. Each subproblem has a closed-form solution using atan2 — no numerical iteration, no arccos, no tangent half-angle substitution.

Let's meet all six.

SPNameGeometryUnknownsMax Solutions
1Circle ∩ PointRotate p around k to reach q1 angle1
2Two CirclesTwo rotations compose: R1p = R2q2 angles2
3Circle ∩ SphereRotate p to land on a sphere1 angle2
4Circle ∩ PlaneRotate p to land on a plane1 angle2
5Three CirclesThree rotations compose, middle direction known3 angles4
6Four CirclesTwo pairs of rotations match a distance4 angles4

SP1: Circle ∩ Point (1 solution)

Problem: Given axis k, find θ such that R(k, θ)p = q.

Method: Project p and q onto the plane perpendicular to k. The angle between the projections is θ. Compute via atan2 of the cross product and dot product of the projections.

Exact solution exists when:p − (k·p)k‖ = ‖q − (k·q)k‖ and k·p = k·q. In words: both points must be the same distance from the axis and at the same height along the axis.

SP2: Two Circles (up to 2 solutions)

Problem: Given axes k1, k2, find θ1, θ2 such that R(k1, θ1)p1 = R(k2, θ2)p2.

Method: Each rotation traces a circle. Find where the two circles intersect. The intersection reduces to a 1D equation solvable with atan2.

Connection to 2R IK: This is exactly the elbow-up/down problem! SP2 is the generalization of 2R IK to arbitrary 3D axis orientations.

SP3: Circle ∩ Sphere (up to 2 solutions)

Problem: Find θ such that ‖R(k, θ)pc‖ = r.

Method: The rotated point must land on a sphere of radius r centered at c. A circle and a sphere in 3D intersect at up to 2 points (think of a hula hoop passing through a basketball).

Why it matters: When solving for an arm's reach to a target, the constraint "joint 3's position is at distance d from joint 5's position" is naturally a sphere constraint. SP3 is the 3D generalization of our 2R law-of-cosines approach.

SP4: Circle ∩ Plane (up to 2 solutions)

Problem: Find θ such that nT · R(k, θ)p = d.

Method: The rotated point must land on a plane defined by normal n and offset d. A circle intersects a plane at up to 2 points.

Use case: When a joint axis is parallel to a constraint direction, the problem reduces to a plane intersection.

SP5 and SP6: Multi-axis Subproblems (up to 4 solutions)

SP5: Three consecutive rotations with a known intermediate direction. Reduces to intersecting two circles derived from the outer rotations, with the middle rotation determined afterwards. Up to 4 solutions.

SP6: Four rotations split into two pairs, constrained by a distance equality. Also up to 4 solutions.

Subproblem Explorer

Click a subproblem to see its geometric construction. The blue circle is the rotation path. Solutions appear as green dots.

SP1: Rotate point p (teal) around axis k to reach target q (yellow). One solution.

Robustness guarantee: IK-Geo solves every subproblem using atan2, never acos or tangent half-angle substitution. This makes it singularity-robust: no division by zero, no numerical blowup at workspace boundaries, no branch-cut discontinuities. The same code handles regular points and degenerate configurations identically.

How Subproblems Compose

The maximum number of IK solutions for a 6R robot is determined by how the subproblems chain together. For a robot with a spherical wrist:

q1: SP1 or geometry
1–2 solutions (shoulder left/right)
×
q2, q3: SP3 + SP1
1–2 solutions (elbow up/down)
×
q4, q5, q6: Euler angles
1–2 solutions (wrist flip)
=
Total
Up to 2 × 2 × 2 = 8 solutions
Check: Which subproblem finds two unknown joint angles simultaneously?

Chapter 5: Into 3D — Rotation Matrices

We've solved 2D IK. Real robots live in 3D. To handle 3D, we need the mathematical language of rotation matrices — 3×3 matrices that rotate vectors without stretching, shrinking, or reflecting them.

What Makes a Rotation Matrix Special?

A 3×3 matrix R is a rotation matrix if and only if:

These two properties guarantee that rotation preserves distances and handedness. The set of all 3×3 rotation matrices forms a mathematical group called SO(3) — the Special Orthogonal group in 3 dimensions.

Axis-Angle Representation

Any 3D rotation can be described by two things: an axis (which direction to rotate around) and an angle (how far to rotate). This is the axis-angle representation: rotate by angle θ around unit vector k = [kx, ky, kz].

The standard rotation matrices around the three coordinate axes are:

Rx(θ) = [[1, 0, 0], [0, cosθ, −sinθ], [0, sinθ, cosθ]]
Ry(θ) = [[cosθ, 0, sinθ], [0, 1, 0], [−sinθ, 0, cosθ]]
Rz(θ) = [[cosθ, −sinθ, 0], [sinθ, cosθ, 0], [0, 0, 1]]

Notice the pattern: the row and column corresponding to the rotation axis are "identity-like" (1 on diagonal, 0 elsewhere). The other four entries form a 2D rotation.

The Rodrigues Formula

For rotation around an arbitrary axis k by angle θ, we use Rodrigues' rotation formula:

R(k, θ) = I cosθ + (1 − cosθ) kkT + sinθ [k]×

Where [k]× is the skew-symmetric matrix that computes the cross product:

[k]× = [[0, −kz, ky], [kz, 0, −kx], [−ky, kx, 0]]

This means [k]× v = k × v (cross product) for any vector v.

Let's unpack the three terms of Rodrigues' formula:

Intuition: Decompose any vector into a component along the axis (which stays fixed) and a component perpendicular to the axis (which rotates in the perpendicular plane). The projection term handles the fixed part. The cosθ and sinθ terms handle the rotating part — just like 2D rotation in the perpendicular plane.

Worked Example

Rotate v = [1, 0, 0] by 90° around k = [0, 0, 1] (the z-axis).

cos(90°) = 0, sin(90°) = 1.

Term 1: I · 0 = [[0,0,0],[0,0,0],[0,0,0]]

Term 2: (1 − 0) · kkT = [[0,0,0],[0,0,0],[0,0,1]] (only the zz entry survives because k=[0,0,1])

Term 3: 1 · [k]× = [[0,−1,0],[1,0,0],[0,0,0]]

Sum: R = [[0,−1,0],[1,0,0],[0,0,1]]

Apply: R · [1,0,0]T = [0,1,0] ✓

The x-axis unit vector rotated 90° around z becomes the y-axis unit vector. This matches our geometric intuition: looking down at the xy-plane, a 90° counter-clockwise rotation sends x to y.

python
import numpy as np

def rodrigues(k, theta):
    """Rotation matrix from axis k (unit vector) and angle theta."""
    k = np.array(k, dtype=float)
    K = np.array([[0, -k[2], k[1]],
                  [k[2], 0, -k[0]],
                  [-k[1], k[0], 0]])
    I = np.eye(3)
    return I * np.cos(theta) + (1 - np.cos(theta)) * np.outer(k, k) + np.sin(theta) * K

# Verify: rotate [1,0,0] by 90° around z
R = rodrigues([0, 0, 1], np.pi/2)
v = R @ np.array([1, 0, 0])
print(v)  # [0, 1, 0]
3D Rotation Visualizer

Choose a rotation axis and drag the angle slider. Watch the vector v = [1,0,0] rotate, and see the rotation matrix values update in real-time. The arc shows the rotation path.

θ

R = [[1.00, 0.00, 0.00], [0.00, 1.00, 0.00], [0.00, 0.00, 1.00]]

Check: What does R(z, 90°) do to the vector [1, 0, 0]?

Chapter 6: The 6R Robot Arm — 3D FK

Now we leave the plane and enter the real world: a 6-DOF robot arm with six revolute joints. Each joint rotates around its own axis. The forward kinematics is a chain of six rotations and translations, expressed as a product of homogeneous transformation matrices.

This is the robot arm that builds your car, fills your Amazon orders, and performs surgery. Let's understand it.

Homogeneous Transforms

In 3D, each link doesn't just rotate — it also translates. We need to handle both. A 4×4 homogeneous transformation matrix packs a rotation R and a translation d into a single matrix:

T = [[R3×3, d3×1], [01×3, 1]]    (4×4 matrix)

The beauty: composing two transforms (first transform by T1, then by T2) is just matrix multiplication:

Ttotal = T1 · T2

This is the power of homogeneous coordinates. Rotation and translation, which are normally different operations, become a single matrix multiply.

The FK Chain

Each joint i has a rotation axis hi and a reference position. The transform for joint i at angle qi is a rotation of qi around axis hi, plus the fixed offset between joints.

The full FK from base (frame 0) to end-effector (frame 6) is:

T06 = T1(q1) · T2(q2) · T3(q3) · T4(q4) · T5(q5) · T6(q6)

This gives us a 4×4 matrix encoding both the position (where the hand is — the translation column) and orientation (which way it's pointing — the rotation block) of the end-effector. Six numbers in (the joint angles), twelve numbers out (3×3 rotation + 3×1 position). But the rotation has only 3 independent degrees of freedom (it's constrained to be orthogonal), so the output is truly 6-dimensional: 3 for position, 3 for orientation. This matches our 6 joint inputs.

UR5-like Configuration

Our visualization models a simplified UR5-like robot (Universal Robots UR5, one of the most common collaborative robots). The joint axes alternate between vertical (Y-axis) and horizontal (Z-axis) rotations, creating the familiar "elbow" shape:

JointAxisRoleTypical Range
q1Y (vertical)Base rotation (turntable)±360°
q2Z (horizontal)Shoulder (lift)±360°
q3Z (horizontal)Elbow (reach)±360°
q4Y (vertical)Wrist 1 (rotate)±360°
q5Z (horizontal)Wrist 2 (tilt)±360°
q6Y (vertical)Wrist 3 (spin)±360°
Forward kinematics is just matrix multiplication. Six 4×4 matrices multiplied together. A modern CPU does this in nanoseconds. Going backwards — inverse kinematics — is where all the difficulty lives. The forward function is smooth, continuous, and unique. Its inverse is multi-valued, discontinuous at singularities, and only exists within the workspace.
3D 6R Robot Arm — FK Explorer

Drag sliders to change joint angles q1–q6. Drag on the canvas to orbit the camera. Colored segments show different links: shoulder/elbow, forearm, wrist. The orange tip is the end-effector.

q1 base
q2 shoulder-30°
q3 elbow60°
q4 wrist1
q5 wrist2-45°
q6 wrist3

End-effector: (0.00, 0.00, 0.00)

Experiment: Try setting all joints to 0° — the arm extends straight out. Then try extreme values. Notice how q1 spins the entire arm, while q6 only rotates the tip. This is the chain rule of FK in action: each joint affects everything downstream.
Check: How many joint angles does a 6R robot have?

Chapter 7: Decoupling Position and Orientation

Solving IK for six joints simultaneously sounds daunting. Six nonlinear equations in six unknowns, with trigonometric terms everywhere. But most industrial robots have a geometric trick up their sleeve that cuts the problem in half.

The Spherical Wrist

If the last three joint axes all intersect at a single point, the robot has a spherical wrist. The point where they intersect is called the wrist center.

Why does this help? Because the wrist center's position depends only on joints 1, 2, 3 (the "shoulder" and "elbow"). Joints 4, 5, 6 rotate the hand around the wrist center without moving it. This means we can split the 6-joint IK into two independent 3-joint problems:

  1. Position subproblem (q1, q2, q3): Place the wrist center at the correct position
  2. Orientation subproblem (q4, q5, q6): Rotate the hand to achieve the desired orientation

This is the Pieper criterion (1968): a 6R robot has closed-form IK if and only if three consecutive axes intersect at a point (or are parallel).

Finding the Wrist Center

The wrist center is offset from the end-effector by the tool length d6 along the approach direction (the z-axis of the desired frame). If the desired end-effector pose is position ptarget with rotation Rtarget, then:

pwrist = ptarget − d6 · Rtarget · [0, 0, 1]T

In words: start at the desired hand position, walk backwards along the hand's z-axis by the wrist-to-tip distance. That's the wrist center. This is computable immediately from the desired pose — no joint angles needed yet.

Solving the Position Subproblem (Joints 1-3)

With the wrist center known, we need q1, q2, q3 such that FK of joints 1-3 places the wrist center at pwrist. For a typical industrial robot (UR5, KUKA, ABB, Fanuc):

q1 (base rotation): This is usually the simplest. The base rotates around the vertical axis, so q1 = atan2(pwrist,y, pwrist,x). But wait — there's an ambiguity. The arm can reach the same wrist center from the "front" or the "back" (shoulder left/right). That gives 2 solutions for q1.

q2, q3 (shoulder + elbow): Once q1 is fixed, the remaining problem is planar — exactly the 2R IK from Chapter 2! We project the wrist center into the plane of links 2 and 3, then use the law of cosines / circle-sphere intersection. 2 solutions (elbow up/down).

Total for position: 2 × 2 = 4 configurations.

Solving the Orientation Subproblem (Joints 4-6)

Once joints 1-3 are known, the rotation R03 (from base to frame 3) is determined. The wrist must achieve the remaining rotation:

R36 = R03T · Rtarget

This is a known rotation matrix that must be decomposed into three rotations around the wrist axes. For a ZYZ wrist configuration (common in industrial robots), this is Euler angle extraction:

R36 = Rz(q4) · Ry(q5) · Rz(q6)

Extracting q4, q5, q6 from R36 is a well-known trigonometric exercise. The key: q5 = atan2(√(r31² + r32²), r33), and there are 2 solutions (wrist flip / no flip, corresponding to ±q5).

For each of the 4 position solutions, there are 2 orientation solutions, giving 4 × 2 = 8 total IK solutions.

Decoupling is the trick that makes most industrial robots solvable in closed form. The UR5, KUKA KR series, ABB IRB 6640, Fanuc M-20 — all have spherical wrists. Without decoupling, you need numerical search or the IK-Geo 1D scan (Chapter 10). The Pieper criterion tells you upfront whether a robot admits closed-form IK.
Position vs Orientation Decoupling

Toggle between position mode (only joints 1-3 move) and orientation mode (only joints 4-6 move). The yellow dot marks the wrist center. Watch how position joints move the wrist center while orientation joints rotate around it.

Sweep
Check: What geometric property enables position/orientation decoupling?

Chapter 8: Full IK Solver — All Solutions

This is the payoff chapter. Everything we've built — FK chains, the law of cosines, geometric subproblems, rotation matrices, position-orientation decoupling — comes together here. We build a complete IK solver for a 6R robot with a spherical wrist. Given a desired end-effector pose, we find all valid joint configurations.

The Solution Pipeline

Step 1: Compute Wrist Center
pwrist = ptarget − d6 Rtarget [0,0,1]T
Step 2: Solve q1
atan2 on wrist center projection → 2 solutions (shoulder L/R)
Step 3: Solve q2, q3
SP3 + SP1 (circle-sphere for elbow) → ×2 solutions (elbow up/down)
Step 4: Solve q4, q5, q6
Euler angles from R03T Rtarget → ×2 solutions (wrist flip)
Step 5: Filter by Joint Limits
Discard solutions violating qmin ≤ qi ≤ qmax → up to 8 valid

Why 8 Solutions?

Each binary choice doubles the solution count:

2 × 2 × 2 = 8 solutions

Each solution is a physically distinct robot configuration that reaches the same end-effector pose. They look completely different — the elbow points a different direction, the shoulder reaches around a different way — but the hand ends up in exactly the same place and orientation.

Selecting the "Best" Solution

With up to 8 solutions, which one should the robot use? Common criteria:

Speed benchmark: IK-Geo computes all 8 solutions for a UR5 in under 5 μs — 40× faster than IKFast, the previous state of the art. For a Franka Panda (7-DOF), GeoFIK finds all solutions parameterized by the redundancy angle in under 10 μs. This speed comes from using only atan2 arithmetic — no iterative search, no matrix decomposition, no polynomial root-finding.
python
def ik_6r_spherical_wrist(p_target, R_target, robot):
    """Full IK for 6R robot with spherical wrist.
    Returns list of joint angle tuples (q1...q6)."""
    solutions = []

    # Step 1: Wrist center
    p_wrist = p_target - robot.d6 * R_target @ np.array([0,0,1])

    # Step 2: Solve q1 (2 solutions)
    for q1 in solve_base_angle(p_wrist):  # shoulder L/R

        # Step 3: Solve q2, q3 (2 solutions each)
        for q2, q3 in solve_elbow(p_wrist, q1, robot):  # elbow up/down

            # Step 4: Solve q4, q5, q6 (2 solutions)
            R03 = fk_rotation(q1, q2, q3, robot)
            R36 = R03.T @ R_target
            for q4, q5, q6 in euler_zyz(R36):  # wrist flip

                # Step 5: Check joint limits
                q = [q1, q2, q3, q4, q5, q6]
                if robot.within_limits(q):
                    solutions.append(q)

    return solutions  # up to 8 solutions
Full 3D IK — All Solutions

Use the slider to adjust the target height. Use Prev/Next to cycle through all IK solutions. The solid arm is the selected solution; ghost arms show alternatives. Drag on the canvas to orbit the camera.

Solution 1 / 4
Target Height100

Computing solutions...

Check: Up to how many IK solutions can a 6R robot with a spherical wrist have?

Chapter 9: When IK Breaks — Singularities

Not every robot configuration is created equal. At certain configurations called singularities, the robot loses a degree of freedom — it can't move in some direction no matter what it does. Understanding singularities is essential because they cause real-world catastrophes: infinite joint velocities, controller instability, and dangerous vibrations.

The Jacobian

The Jacobian J is a matrix that maps joint velocities to end-effector velocities:

vee = J(q) · q̇

For a 2R planar arm, J is 2×2:

J = [[-L1s1 − L2s12, −L2s12], [L1c1 + L2c12, L2c12]]

Where s1 = sinθ1, c1 = cosθ1, s12 = sin(θ12), c12 = cos(θ12).

The determinant is:

det(J) = L1 L2 sin(θ2)

This is zero when θ2 = 0 or π — exactly when the arm is fully extended or fully folded.

What a Singularity Means Physically

When det(J) = 0, the Jacobian is not invertible. The equation q̇ = J−1 vee breaks down. Physically, this means:

Three Types of Singularities

Workspace boundary singularity: The arm is fully extended (θ2 = 0) or fully folded (θ2 = π). At this configuration, the arm can only move tangentially — it physically cannot reach further outward or fold further inward. The two IK solutions (elbow-up and elbow-down) merge into one.

Internal singularity: Two joint axes align, creating redundancy in one direction and a dead zone in another. For example, when a robot's shoulder and elbow axes become coplanar, the arm can spin freely around one axis but can't generate velocity perpendicular to it.

Wrist singularity: When q5 = 0 in a ZYZ wrist, axes 4 and 6 become collinear. The robot can spin joints 4 and 6 freely (only their sum q4 + q6 matters), but it's lost the ability to rotate about one axis. This is the most common singularity in industrial robots and must be carefully avoided during path planning.

At a singularity, tiny Cartesian motions require infinite joint velocities. Your motors will stall, your controller will oscillate, and your robot might damage itself or its surroundings. Every industrial robot has singularity avoidance built into its motion planner. The most common approach: detect when det(J) drops below a threshold and switch to a damped pseudoinverse (sacrificing tracking accuracy to avoid infinite speeds).
Singularity Explorer

Drag the target toward the workspace boundary. Watch the Jacobian determinant drop toward zero. The velocity ellipse shows which directions the arm can move easily (long axis) vs barely at all (short axis). At the boundary, the ellipse collapses.

Target distance100
Target angle45°

det(J) = 1.000 — Full mobility

IK Near Singularities

As the target approaches a singularity, the IK solutions become numerically ill-conditioned. Small changes in the target produce large jumps in joint angles. This is a fundamental mathematical property, not a bug in the solver. IK-Geo handles this gracefully because it uses atan2 (which is well-defined everywhere), but the solutions themselves become sensitive near singularities.

Check: What happens to the Jacobian at a singularity?

Chapter 10: Search-Based IK for General 6R

Everything so far assumes the robot has three consecutive axes that intersect (spherical wrist) or are parallel. But what about robots where no such structure exists? General 6R robots — where no three consecutive axes have special geometric relationships — have no closed-form IK solution. The system of equations is a polynomial of degree up to 16.

This is where IK-Geo's approach truly shines. Even for general robots, it doesn't abandon geometric reasoning for brute-force gradient descent. Instead, it reduces the problem to a 1D search over a single joint angle.

The 1D Search Strategy

The idea is beautiful in its simplicity. Pick one joint, say q4. For any fixed value of q4, the remaining five joints can be solved in closed form using subproblems. This is because fixing one angle creates enough geometric structure for the subproblems to apply.

So we define an error function:

e(q4) = ‖ R03(q1, q2, q3)T · Rtarget − R36(q4, q5, q6) ‖

Where q1, q2, q3, q5, q6 are all determined (via subproblems) as functions of the fixed q4. The zeros of e(q4) are the IK solutions.

The algorithm:

  1. Sweep q4 from −π to π in small steps (e.g., 1000 samples)
  2. At each sample, solve q1-q3 and q5-q6 in closed form via subproblems
  3. Evaluate the error e(q4)
  4. Find zero crossings of e(q4) using bisection or Newton's method
  5. For each zero, read off all six joint angles
The genius of IK-Geo: Even for the hardest robots, you only search over 1-2 angles. The remaining 4-5 angles are solved analytically by subproblems. Compare this to gradient-based IK (which searches in 6D space and may converge to local minima) or polynomial solvers (which compute all 16 roots of a degree-16 polynomial, most of them complex). One dimension of search is fast, robust, and easy to visualize.

How Many Solutions?

A general 6R robot can have up to 16 IK solutions (proven by algebraic geometry — the system is a degree-16 polynomial). In practice, most configurations have 2-8 real solutions. IK-Geo's 1D search finds them all by sampling densely enough to catch every zero crossing.

For robots with 2D search (two free parameters), the problem becomes finding the zero contour of a 2D error function. This is more expensive but still vastly better than 6D gradient descent.

Robot TypeSearch DimMax SolutionsExample
3 intersecting axes0 (closed form)8UR5, KUKA KR
3 parallel axes0 (closed form)8SCARA-type
2 intersecting + 1 special116Some custom arms
General 6R1-216Custom/exotic arms
1D Error Function Search

The error function e(q4) is plotted over [−π, π]. Zeros (where the curve crosses the horizontal axis) are IK solutions, marked with green dots. Drag the teal cursor to explore different q4 values. The arm below shows the resulting configuration.

q4

e(q4) = 0.000 — Scanning...

Check: For a general 6R robot with no special axis configurations, IK-Geo reduces to searching over how many angles?

Chapter 11: Connections

Inverse kinematics is the bridge between intention and motion. Every time a robot arm reaches for an object, welds a seam, inserts a peg, catches a ball, or sutures a wound — IK is the silent translator converting desired end-effector poses into motor commands. You now understand the mathematics behind all of it.

What We Covered

Ch 0-1: FK Foundation
Joint angles → end-effector position via trig/matrix chains
Ch 2: 2R IK
Law of cosines, atan2, elbow-up/down, workspace
Ch 3-4: IK-Geo Subproblems
Circle intersections as universal IK building blocks
Ch 5-8: 3D 6R Robots
Rotation matrices, decoupling, full IK with 8 solutions
Ch 9-10: Advanced
Singularities, Jacobian, search-based IK for general robots

IK Methods Compared

MethodTypeSpeedAll Solutions?Singularity-Safe?
IK-GeoGeometric<5 μsYesYes (atan2 only)
IKFastSymbolic~200 μsYesMostly
TRAC-IKNumerical~1 msNo (one at a time)No
Jacobian pseudoinverseIterativeVariableNoNo (blows up)
CCD / FABRIKHeuristicFastNoNo
Neural network IKLearned~100 μsNoDepends on training

Where IK Lives in the Robot Stack

Task Planning
"Pick up the cup from the table"
Motion Planning (RRT, PRM)
Collision-free path from start to goal pose
Inverse Kinematics
Convert each waypoint pose to joint angles
Trajectory Generation
Smooth joint-space trajectory with velocity/acceleration limits
Joint Controllers (PID / Torque)
Track joint trajectories with feedback control

Extensions and Frontiers

Redundant robots (7+ DOF): The Franka Panda has 7 joints — one more than needed for 6-DOF tasks. The extra joint gives a continuous family of IK solutions parameterized by a redundancy angle. GeoFIK (Elias & Wen, 2025) solves this geometrically, finding all solutions along the redundancy manifold with analytical Jacobians as a byproduct.

Cuspidal robots: Some robots can change between IK solution branches without passing through a singularity. These cuspidal configurations create topological traps for path planners — a motion that looks smooth in Cartesian space may require a discontinuous jump in joint space. Elias & Wen (2025) developed specialized path planning algorithms that detect and handle cusp crossings.

Learning-based IK: Neural networks can approximate IK, especially for complex kinematic chains (humanoid hands, snake robots, soft robots). But they sacrifice guaranteed accuracy, completeness, and interpretability. Geometric methods remain the gold standard for precision applications where you need all solutions and need to know when IK is infeasible.

Related Lessons

References

  1. A. J. Elias & J. T. Wen. "IK-Geo: Unified Robot Inverse Kinematics Using Subproblem Decomposition." arXiv:2211.05737, 2022.
  2. A. J. Elias & J. T. Wen. "GeoFIK: Fast Geometric Inverse Kinematics for the Franka Emika Panda." arXiv:2503.03992, 2025.
  3. A. J. Elias & J. T. Wen. "Cuspidal-Aware Path Planning for Serial Manipulators." arXiv:2501.18505, 2025.
  4. B. Pieper. "The kinematics of manipulators under computer control." PhD thesis, Stanford, 1968.
  5. J. Craig. Introduction to Robotics: Mechanics and Control, 4th ed. Pearson, 2017.
Closing thought: "What I cannot create, I do not understand." — Richard Feynman. You now understand the geometry behind every robot reach, every welding path, every surgical instrument movement. The same atan2 calls that guided the first industrial robots in the 1970s power the Mars rovers today. The math is timeless.