Inverse kinematics (source code)

= Inverse kinematics

<Inverse kinematics> finds joint coordinates that place an <end effector> at a requested position or configuration. It reverses the mapping specified by <forward kinematics>, but need not have a unique solution: a target can be unreachable, attainable through several configurations, or attainable through a continuous family when the mechanism has redundant <degrees of freedom>.<Modern Robotics: Mechanics, Planning, and Control by Kevin M. Lynch and Frank C. Park>[Chapter 6, inverse kinematics; author supplement, analytical versus numerical solutions]{ref}

For a two-link planar <robot arm>, the <law of cosines> gives
$$
\cos\theta_2=\frac{x^2+y^2-l_1^2-l_2^2}{2l_1l_2}.
$$
With unit link lengths and target $(1,1)$, $\cos\theta_2=0$. Two position solutions are $(\theta_1,\theta_2)=(0,\pi/2)$ and $(\pi/2,-\pi/2)$. They have different arm shapes and tool orientations. A target at $(3,0)$ is unreachable because it lies beyond the total link length of two. Joint limits, obstacles and a specified tool orientation can exclude solutions even when the position is geometrically reachable.