Linear Algebra · Theory · M8
M8-T2 — Forward Kinematics of a Two-Link Manipulator
The hand of a two-link arm is the sum of two rotating vectors. Its forward kinematics, workspace and inverse kinematics are all a few lines of trigonometry.
The planar two-link arm is the hydrogen atom of manipulators: small enough to solve by hand, rich enough to show forward kinematics, workspace limits, multiple inverse solutions and (later) the Jacobian and singularities. We derive its kinematics two ways and check both against numbers.
Learning objectives
After this lesson, you should be able to:
- Write the hand position of a planar two-link arm as a function of its joint angles.
- Derive the same result as a product of homogeneous transforms from Module 7.
- Describe the workspace as an annulus and solve inverse kinematics in closed form with the law of cosines.
- Identify the two inverse solutions (elbow up and down) and what happens at the workspace boundary.
Introduction and motivation
The two-link arm models a SCARA robot, the shoulder and elbow of a human or industrial arm, a robot leg (hip and knee) and a camera on a two-axis pan-tilt mast. Its formulas are used again and again in tuning, in teaching, and as a test bed for new inverse kinematics code: if a solver cannot handle a two-link arm near a singularity, it will not handle anything bigger.
The intuition
Walk along the first link: you move l₁ in the direction of the first angle. Then turn by the elbow angle and walk l₂ in the new direction, which is q₁ + q₂ measured from the x-axis. The hand is where you end up: the sum of two vectors of fixed length whose directions you control.
Interactive figure. A two-link planar arm. The readout shows the hand position for the chosen joint angles so that formulas can be checked by hand. This figure needs JavaScript to be interactive.
Geometric and physical interpretation
Geometric view. With the elbow straight (q₂ = 0) the arm reaches its maximum distance l₁ + l₂; folded back (q₂ = ±180°) it reaches the minimum |l₁ − l₂|. Every distance between is reachable, in every direction, so the workspace is the annulus between these radii. Inside it, each hand position has two arm shapes, mirror images through the line from base to hand. Physical view. The ‘elbow up’ and ‘elbow down’ shapes reach the same point with different joint angles; which is better depends on obstacles and joint limits.
The mathematics
- l₁, l₂
- the link lengths.
- q₁
- the shoulder angle, from the x-axis to link 1.
- q₂
- the elbow angle, from link 1 to link 2.
- p = (x, y)
- the hand position.
- r
- the distance from base to hand, √(x² + y²).
Forward kinematics
x = l₁ cos q₁ + l₂ cos(q₁ + q₂) y = l₁ sin q₁ + l₂ sin(q₁ + q₂)
What it means. Each term is a link vector. The second link points at absolute angle q₁ + q₂ because the elbow angle is relative to link 1. The map from (q₁, q₂) to (x, y) is nonlinear.
Workspace
|l₁ − l₂| ≤ r ≤ l₁ + l₂
What it means. Triangle inequality: the hand, the elbow and the base form a triangle with sides l₁, l₂ and r.
Inverse kinematics
cos q₂ = (x² + y² − l₁² − l₂²) / (2 l₁ l₂), q₂ = ± arccos(·) q₁ = atan2(y, x) − atan2(l₂ sin q₂, l₁ + l₂ cos q₂)
What it means. The law of cosines gives the elbow angle, with a sign for elbow up or down; then q₁ is the direction to the hand minus the angle the second link adds.
Hand = l₁(cos q₁, sin q₁) + l₂(cos(q₁+q₂), sin(q₁+q₂)). Workspace: annulus |l₁−l₂| ≤ r ≤ l₁+l₂. Inverse: law of cosines for q₂ (two signs), then q₁.
Step-by-step derivation: forward map, transforms and the inverse
- Vector sum. Link 1 is the vector
l₁(cos q₁, sin q₁). Link 2 has the absolute angleq₁ + q₂and isl₂(cos(q₁ + q₂), sin(q₁ + q₂)). The hand is their sum, giving the formulas above. - As a product of transforms (Module 7). Use 2D homogeneous transforms:
T = Rot(q₁) Trans(l₁, 0) Rot(q₂) Trans(l₂, 0). Rotate by q₁, move l₁ along the new x-axis, rotate by q₂, move l₂ along the newest x-axis. The hand is the translation column of T. Multiplying out gives the same two formulas, withq₁ + q₂arising from the product of rotationsRot(q₁)Rot(q₂) = Rot(q₁ + q₂). - Squared distance. From the formulas,
x² + y² = l₁² + l₂² + 2 l₁ l₂ (cos q₁ cos(q₁ + q₂) + sin q₁ sin(q₁ + q₂)) = l₁² + l₂² + 2 l₁ l₂ cos q₂, since the bracket equalscos((q₁ + q₂) − q₁) = cos q₂. - Solve for q₂. Rearranging,
cos q₂ = (x² + y² − l₁² − l₂²)/(2 l₁ l₂). A solution exists exactly when the right side lies in [−1, 1], which is the annulus condition. Both+arccosand−arccoswork: elbow down and elbow up. - Solve for q₁. The hand direction is
atan2(y, x). Relative to link 1, the hand sits at the angleatan2(l₂ sin q₂, l₁ + l₂ cos q₂)(the direction of the vector sum in the link-1 frame). Soq₁ = atan2(y, x) − atan2(l₂ sin q₂, l₁ + l₂ cos q₂). - Boundary. At
r = l₁ + l₂,cos q₂ = 1and the two solutions coincide (q₂ = 0). Atr = |l₁ − l₂|,cos q₂ = −1and they coincide atq₂ = ±180°.
Numerical safety. Clip cos q₂ to [−1, 1] before arccos, since rounding near the boundary can push it to 1.0000001 and produce a not-a-number result. Use atan2, never atan of a ratio.
Orientation of the hand. The hand also has an orientation angle φ = q₁ + q₂. That is the third task coordinate in the planar pose, and shows why a two-link arm cannot reach a general (x, y, φ): the angle is determined by the position and the elbow sign.
A worked example: forward and inverse kinematics with l₁ = 1.1, l₂ = 0.8
- Forward, first pose.
q = (0°, 90°):x = 1.1 cos 0 + 0.8 cos 90° = 1.1,y = 0 + 0.8 sin 90° = 0.8. Hand at(1.1, 0.8). - Forward, second pose.
q = (90°, −90°):x = 1.1 cos 90° + 0.8 cos 0° = 0.8,y = 1.1 sin 90° + 0.8 sin 0° = 1.1. Hand at(0.8, 1.1): the same two links, mirrored through the line y = x. - Inverse of (1.1, 0.8).
r² = 1.85,cos q₂ = (1.85 − 1.21 − 0.64)/(2·1.1·0.8) = 0/1.76 = 0, soq₂ = ±90°. - Elbow sign +90°.
q₁ = atan2(0.8, 1.1) − atan2(0.8·1, 1.1 + 0) = 36.03° − 36.03° = 0°✓ (the first pose). - Elbow sign −90°.
q₁ = 36.03° − atan2(−0.8, 1.1) = 36.03° + 36.03° = 72.05°. Check:x = 1.1 cos 72.05° + 0.8 cos(−17.95°) = 0.3399 + 0.7611 = 1.100,y = 1.1 sin 72.05° + 0.8 sin(−17.95°) = 1.0462 − 0.2465 = 0.800✓. - Workspace. Reach from 0.3 to 1.9. The point
(1.9, 0)is on the outer boundary:cos q₂ = (3.61 − 1.85)/1.76 = 1.0, so q₂ = 0 (straight arm) and there is only one solution. - Homogeneous check.
Rot(0°) Trans(1.1, 0) Rot(90°) Trans(0.8, 0)applied to the origin gives(1.1, 0.8)✓.
Robotics application
Manipulators and legged robots. The same formulas give the foot position of a two-segment leg and the tip of a SCARA arm; swapping the sign of q₂ switches the knee direction.
Mobile robots. A pan-tilt sensor mast is a two-joint chain whose forward kinematics places the camera or LiDAR in the base frame (the mount transform of Module 7 becomes configuration-dependent); see TF frames and consistency and rigid transforms in 2D.
UAV with a gimbal. Gimbal roll and pitch act like two links of zero length: forward kinematics is a product of two rotations; see UAV coordinate frames.
LiDAR and calibration. Hand-eye calibration solves for an unknown transform from observations of the same forward kinematics at several joint angles; see LiDAR point clouds for how sensor poses enter mapping.
Engineering implications and limitations
Practical rules
- Clip before arccos. Rounding near the reach limit makes cos q₂ slightly exceed 1; clip it, or the solver returns a not-a-number value exactly when the arm is stretched.
- Reject unreachable targets. Test
|l₁ − l₂| ≤ r ≤ l₁ + l₂first and report “unreachable”, optionally projecting to the nearest reachable point. - Pick the elbow by continuity. Choose the solution closest to the current joint angles so the arm does not flip between elbow up and down.
- Respect joint limits. A mathematically valid solution may violate a joint range; check both signs.
- Test with round trips.
fk(ik(p)) = pfor random reachable points, andik(fk(q))returns q or its mirror solution. - Keep angle conventions straight. q₂ relative to link 1 (as here) versus absolute second-link angle changes the formulas; document which one is used.
Limits
The closed form works only for this two-link geometry. Arms with offsets, more joints or spherical wrists need numerical inverse kinematics, which uses the Jacobian developed in the following lessons.
Common misconceptions
“The second angle is measured from the x-axis.”
Here q₂ is relative to link 1; the absolute angle of link 2 is q₁ + q₂.
“Every point within reach has exactly one solution.”
Inside the annulus there are two (elbow up and down); only on the boundary do they coincide.
“The workspace is a full disc of radius l₁ + l₂.”
It is an annulus when l₁ ≠ l₂: the points closer than |l₁ − l₂| cannot be reached.
“atan(y/x) is enough for the direction to the hand.”
It loses the quadrant and fails at x = 0; use atan2.
Engineering takeaways
- Hand = l₁(cos q₁, sin q₁) + l₂(cos(q₁ + q₂), sin(q₁ + q₂)); it can equally be built as Rot Trans Rot Trans.
- The workspace is the annulus |l₁ − l₂| ≤ r ≤ l₁ + l₂.
- Inverse kinematics: cos q₂ from the law of cosines (two signs), then q₁ = atan2(y, x) − atan2(l₂ sin q₂, l₁ + l₂ cos q₂).
- The two solutions merge on the workspace boundary and no solution exists outside.
- Clip arccos arguments, use atan2, choose the solution by continuity and joint limits.
References and further reading
Primary papers and authoritative documentation.
- Modern Robotics (Lynch and Park), free preprint: chapter 4, forward kinematics and chapter 6, inverse kinematics of simple arms
- Michigan ROB 101: Computational Linear Algebra: forward and inverse kinematics of a planar arm
- Buss, Introduction to Inverse Kinematics with Jacobian Transpose, Pseudoinverse and Damped Least Squares: inverse kinematics and the Jacobian methods, including the two-link example; the site did not load when we last checked
- UCSD ECE276A: Sensing and Estimation in Robotics: forward kinematics via transform products
Knowledge check
Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
For l₁ = l₂ = 1, find the hand position when q = (30°, 60°).
Explanation
x = cos 30° + cos 90° = 0.866 + 0 = 0.866; y = sin 30° + sin 90° = 0.5 + 1 = 1.5. Hand at (0.866, 1.5).
Question 2
With l₁ = 1.1 and l₂ = 0.8 find q₂ for a target at distance r = 1.5 and say how many solutions exist.
Explanation
cos q₂ = (2.25 − 1.21 − 0.64)/1.76 = 0.2273, q₂ = ±arccos(0.2273) = ±76.9°. Two solutions (elbow up and elbow down), since 0.3 < 1.5 < 1.9.
Question 3
A solver is given a target at distance exactly l₁ + l₂ computed from floating point and returns a not-a-number value. Why, and how do you fix it?
Explanation
Rounding makes (r² − l₁² − l₂²)/(2l₁l₂) equal to 1.0000000000000002, outside the domain of arccos. Clip the value to [−1, 1] (or test reach with a small tolerance) before calling arccos.
What’s next
The forward map is nonlinear. To control velocities we need its derivative. That means partial derivatives of functions of several variables, which the next lesson develops with the Jacobian in mind.
Related content
Nothing below is required to finish this lesson.
- BeforeM8-T1: Introduction to Robot Kinematics
Define joints, links, configuration space and the task space, and state what forward and inverse kinematics mean.
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.