This interactive simulation visualizes Forward Kinematics (FK) and Inverse Kinematics (IK) for a planar 2-link robot arm. You can drive the arm by angles (FK) or by dragging the end-effector target (IK), and see the underlying math update in real time.
Math behind the Simulation
1. Two-link planar arm
The arm has two links: length L1 (shoulder–elbow) and L2 (elbow–end-effector). Joint angles are θ1 (base) and θ2 (elbow, relative to link 1). The end-effector position (in a math frame with x right, y up) is:
y = L1 sin(θ1) + L2 sin(θ1 + θ2)
2. Forward kinematics (FK)
Given θ1, θ2, L1, L2, we compute x, y directly from the equations above. The elbow is at (L1 cos θ1, L1 sin θ1).
3. Inverse kinematics (IK)
Given a target (x, y), we solve for θ1, θ2. Let d = √(x2 + y2). If d > L1 + L2 we clamp to max reach; if d < |L1 − L2| we clamp to min reach. Using the Law of Cosines:
so θ2 = ±acos(...). “Elbow up” uses θ2 < 0; “elbow down” uses θ2 > 0. Then θ1 = atan2(y, x) − atan2(L2 sin θ2, L1 + L2 cos θ2).
4. Workspace and singularities
The reachable set is an annulus (donut): outer radius L1 + L2, inner radius |L1 − L2|. Singularities occur when the arm is fully extended or fully folded (θ2 = 0 or ±π): the Jacobian becomes singular and small Cartesian motions require large joint motions.
5. Jacobian and manipulability ellipsoid
Definition. The Jacobian J is the matrix of partial derivatives of end-effector position (x, y) with respect to joint angles (θ1, θ2): J = ∂[x; y]/∂[θ1; θ2]. The entries are j11 = ∂x/∂θ1, j12 = ∂x/∂θ2, j21 = ∂y/∂θ1, j22 = ∂y/∂θ2, which you can derive from the FK expressions above.
Velocity mapping. J maps joint velocities to end-effector velocity: [ẋ; ẏ] = J [θ̇1; θ̇2], i.e. ẋ = j11θ̇1 + j12θ̇2 and ẏ = j21θ̇1 + j22θ̇2.
Use in this simulation. We compute J from the current (θ1, θ2, L1, L2) and show its entries live in the Jacobian J panel. The manipulability ellipsoid (cyan ellipse at the end-effector) is derived from JJT: its axes indicate directions of higher velocity capability for unit joint velocity. The ẋ, ẏ from J panel compares end-effector velocity from J·[θ̇1; θ̇2] with measured velocities (from finite differences), and the velocity subplots show θ̇1, θ̇2 and ẋ, ẏ over time.
Simulation
The interactive simulator is below. Use the controls to explore the concepts described above.
2D Kinematics
FK (live):
Joint velocity
θ̇₁ = — rad/s
θ̇₂ = — rad/s
Jacobian J
Definition: J = ∂[x; y]/∂[θ₁; θ₂]. J maps [θ̇₁, θ̇₂]ᵀ → [ẋ, ẏ]ᵀ.
Use here: Live J from FK; manipulability ellipse from JJᵀ; ẋ, ẏ from J·[θ̇₁; θ̇₂] vs measured.
j₁₁ = ∂x/∂θ₁ = −L₁ sin θ₁ − L₂ sin(θ₁+θ₂) = —
j₁₂ = ∂x/∂θ₂ = −L₂ sin(θ₁+θ₂) = —
j₂₁ = ∂y/∂θ₁ = L₁ cos θ₁ + L₂ cos(θ₁+θ₂) = —
j₂₂ = ∂y/∂θ₂ = L₂ cos(θ₁+θ₂) = —
ẋ, ẏ from J
[ẋ; ẏ] = J [θ̇₁; θ̇₂]
ẋ = j₁₁·θ̇₁ + j₁₂·θ̇₂ = —
ẏ = j₂₁·θ̇₁ + j₂₂·θ̇₂ = —
Measured: ẋ = —, ẏ = — px/s
Usage
Follow these steps to explore 2D robot arm kinematics:
- Mode: Forward (FK) — you control θ1, θ2 via sliders; the end-effector position is computed. Inverse (IK) — you click and drag the pink target; the angles are computed from the target. If the target is outside the reachable annulus, a warning overlay appears and the arm clamps to the workspace; the pink dot remains at the requested position.
- Sliders: In FK mode, use θ1 and θ2 to move the arm. The FK math panel updates with the current x, y and the formula values.
- L1, L2: Link lengths (pixels). Changing them updates the workspace annulus and FK/IK.
- Elbow Up / Down: In IK mode, toggles between the two IK solutions. The ghost arm (dashed) shows the other configuration.
- Trace: Check the Trace checkbox to show a trail behind the end-effector; uncheck to clear it. The checkbox is on its own row; Step Fwd, Step Bwd, Run, and Reset are in a single line below.
- Step Fwd / Step Bwd: Nudge angles (FK) or target (IK) by a small step. Step Fwd stops any running animation first.
- Run / Stop: Animates the arm (FK: angles change; IK: target moves on a circle).
- Reset: Restore default angles, clear the trace, and uncheck Trace.
- Velocity subplots: Two plots at the top-right of the canvas show joint velocities (θ̇₁, θ̇₂) and end-effector velocities (ẋ, ẏ) over a rolling time window.
- Info panels: Below the simulation, three panels show live joint velocities, the Jacobian J (formulas and values), and ẋ, ẏ from J compared to measured velocities.
- Manipulability ellipsoid: The cyan ellipse at the end-effector indicates directions of higher velocity capability (from the Jacobian).
Parameters
- θ1, θ2: Joint angles (degrees). θ1 is the base angle; θ2 is the elbow angle relative to link 1.
- L1, L2: Link lengths in pixels (20–250). Defaults 150, 120.
- Workspace: Annulus with outer radius L1 + L2, inner radius |L1 − L2|.
- Velocities: Joint velocities (θ̇₁, θ̇₂) in rad/s; end-effector velocities (ẋ, ẏ) in px/s. Subplot time window and layout are configurable via
robotarm.jsConfig.
Limitations
- Two-link planar arm only. The model is a 2-DOF arm in a single plane. Real manipulators have 6+ joints in 3D, where IK has many solutions (or none in closed form) and is usually solved numerically.
- Idealized kinematics, no dynamics. Only positions and velocities are modeled. Mass, inertia, gravity, joint torques, friction, and actuator limits are ignored — this is pure geometry, not a physical robot.
- No joint limits or self-collision. Angles wrap freely and the two links may overlap; real joints have angular limits and the arm cannot pass through itself or obstacles.
- Analytic IK with two branches. Inverse kinematics uses the closed-form law-of-cosines solution with an elbow-up/elbow-down choice; near singularities (fully extended/folded) the Jacobian is ill-conditioned and the displayed velocity mapping degrades.
- Pixel units, no calibration. Link lengths and velocities are in screen pixels, not metric units, so the numbers illustrate relationships rather than a specific physical robot.
- Teaching tool. Intended to build intuition for FK/IK, the workspace annulus, and the Jacobian — not a robot controller or motion planner.