From a target point to joint angles
Forward kinematics turns joint angles into a tip position; inverse kinematics (IK) goes the other way, which is what a robot actually needs when told "move the gripper here". For a two-link planar arm with link lengths L₁ and L₂ there is a closed-form answer. The distance from the base to the target fixes the elbow angle by the law of cosines:
cos θ₂ = (x² + y² − L₁² − L₂²) / (2 L₁ L₂)
and the shoulder angle then follows from the direction of the target, corrected for where the elbow puts the forearm:
θ₁ = atan2(y, x) − atan2(L₂ sin θ₂, L₁ + L₂ cos θ₂)
Because cos θ₂ is the same for +θ₂ and −θ₂, there are two solutions: elbow up and elbow down, mirror images that put the tip on the same point.
Worked example
With the default L₁ = 100 mm and L₂ = 80 mm, reach the target (120, 80):
- x² + y² = 14400 + 6400 = 20800, so cos θ₂ = (20800 − 10000 − 6400) / (2 · 100 · 80) = 4400 / 16000 = 0.275, and θ₂ = ±74.04°.
- Elbow up: θ₂ = −74.04° gives θ₁ = 65.92°. The elbow sits at (40.8, 91.3), above the target.
- Elbow down: θ₂ = +74.04° gives θ₁ = 1.46°. The elbow sits almost on the x axis, below the target.
Run either pair through forward kinematics and the tip lands back on (120, 80): the quickest way to check an IK answer.
When there is no solution
The target must lie in a ring around the base: no farther than L₁ + L₂ (arm fully stretched) and no nearer than |L₁ − L₂| (arm fully folded). Outside it, the formula gives |cos θ₂| > 1 and the tool reports the target as unreachable. For the default arm the ring runs from 20 mm to 180 mm; (120, 80) is 144.2 mm away, inside it.
Three links with a tool angle
A third link in the same plane gives the arm a wrist, and usually you care which way the tool points as well as where it is: a gripper has to approach a part from above, a pen has to meet the paper square. Give the tool angle φ (measured from the x axis) and the problem has a closed form again:
- Step back from the target along the tool direction by L₃ to find the wrist point: W = (x − L₃ cos φ, y − L₃ sin φ).
- Solve the two-link arm for W exactly as above.
- The last joint makes up the rest of the tool angle: θ₃ = φ − θ₁ − θ₂.
With L₁ = 100, L₂ = 80, L₃ = 50 mm, target (150, 60) and φ = −30° (tool tilted 30° below horizontal), the wrist is at (150 − 50 cos(−30°), 60 − 50 sin(−30°)) = (106.70, 85.00), 136.42 mm from the base, so cos θ₂ = 0.1381 and θ₂ = ±82.06°:
- Elbow up: θ₁ = 74.05°, θ₂ = −82.06°, θ₃ = −21.99°
- Elbow down: θ₁ = 3.03°, θ₂ = 82.06°, θ₃ = −115.10°
Both sets add up to −30°, the tool angle. A 3-link target can be in reach for one tool angle and out of reach for another: what has to fit inside the 2-link ring is the wrist point, not the tip.
Choosing elbow up or down
The maths does not prefer one. Real arms choose by what is in the way (a table, the robot's own body), by which solution is closer to the current pose so the joints move less, and by joint limits: a servo that turns only 0–180° may reach one solution and not the other.
Beyond this
Without a fixed tool angle, a 3-link planar arm has infinitely many solutions (the wrist can sit anywhere on a curve), and real controllers pick one numerically, for example with the Jacobian, minimizing joint motion. Industrial six-axis arms such as the PUMA 560 have closed-form solutions worked out per robot. To see what any set of joint angles does on a full arm, enter its DH table in the DH parameters calculator; to size the motors for the pose, use the joint torque calculator.