Espurna
EN
KinematicsIntermediateFKIKforward kinematicsinverse kinematicsarmlaw of cosines

Forward and inverse kinematics

In 30 secondsFK: from angles to hand position, always one answer. IK: from position to angles; there can be two solutions (elbow up or down) or none if the point is out of reach.

Also available in: Català · Castellano

Forward kinematics (FK)

Two-link arm:

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

Each link adds its vector, rotated by all the previous angles.

Inverse kinematics (IK)

You know where you want the hand and look for the angles. For two links there is a closed-form formula (law of cosines):

  • cosθ2 = (x² + y² − L1² − L2²) / (2·L1·L2)
  • θ1 = atan2(y, x) − atan2(L2·sinθ2, L1 + L2·cosθ2)

Solutions: two (elbow up and down, the sign of θ2), one at the edge of the reach, none outside. The reach goes from |L1 − L2| to L1 + L2; outside it, the cosine comes out greater than 1.

Example

L1 = L2 = 1, target (1, 1): cosθ2 = (2 − 2) / 2 = 0 → θ2 = 90°, θ1 = 45° − 45° = 0°. Check: (1, 0) + (0, 1) = (1, 1). The other solution: θ2 = −90°, θ1 = 90°.

With more joints it is usually solved with numerical methods based on the Jacobian.

In the demo

Switch from FK to IK, drag the target, flip the elbow and take it outside the reach circle to see the warning.

Common questions

Why are there two solutions? Because the elbow can bend up or down and the hand still ends up in the same place, like your arm with your hand resting on the table.

Interactive demo

Related concepts