The Mathematics
Given a base at the origin, link lengths L₁ and L₂, and target (tx, ty):
Reachability check
d = √(tx² + ty²)
reachable iff |L₁ − L₂| < d < L₁ + L₂
Solve for joint angles
Using the cosine rule:
cos(θ₂) = (d² − L₁² − L₂²) / (2·L₁·L₂)
θ₂ = ±acos(cos θ₂) ← elbow-up or elbow-down
θ₁ = atan2(ty, tx) − atan2(L₂·sin θ₂, L₁ + L₂·cos θ₂)
The ± in θ₂ gives two solutions — "elbow up" and "elbow down." Both reach the same target; choosing between them depends on obstacle avoidance and joint limits.
Singularities
When the arm is fully extended (d = L₁ + L₂) or fully folded (d = |L₁ − L₂|), the Jacobian loses rank — the arm can't move in certain directions. These singularities are where IK breaks down numerically.
Further reading
- Inverse kinematics (Wikipedia)
- Siciliano et al., Robotics: Modelling, Planning and Control
- Lynch & Park, Modern Robotics — free online textbook.