Coordinates, angles and vectors
The language of position and direction: coordinate frames, radians, sine and cosine, and adding vectors tip to tail.
30 min · Self-paced · Free
Why robots need geometry
A robot arm reaching for a cup has to answer a deceptively simple question: where is my hand right now, and where do I want it to be? A robot cannot point and say "over there". It needs numbers. This lesson builds the small toolkit of geometry that robots use to turn positions and directions into numbers they can compute with. If some of it is familiar from school, good — we will connect it to motion as we go.
Coordinate frames
A coordinate frame is a reference for measuring positions. In two dimensions it is an origin (a point we call zero) and two perpendicular axes, usually called x and y. Any point can then be written as a pair of numbers (x, y): how far along each axis you must travel from the origin to reach it.
The crucial idea in robotics is that there is more than one frame. The same cup can be described from the table's corner, from the robot's base, or from the camera mounted above. Its coordinates are different in each frame, even though the cup has not moved. Much of the mathematics of robotics is about converting a position from one frame to another — "the camera sees the cup at this spot; where is that relative to my shoulder?"
For now we will use a single frame fixed at the base of a robot arm, with x pointing right and y pointing up, and we will measure angles anticlockwise from the positive x-axis. This convention is standard in mathematics and robotics, and sticking to one convention avoids a great many mistakes.
Degrees and radians
You probably measure angles in degrees, where a full turn is 360°. Engineers and programmers also use radians. The idea behind radians is natural: wrap a piece of string the length of a circle's radius around its edge. The angle it covers is one radian. Because a circle's circumference is 2π times its radius, a full turn is 2π radians.
So:
- 360° = 2π rad
- 180° = π rad
- 90° = π/2 rad
- 1 rad ≈ 57.3°
To convert, multiply by π/180 (degrees to radians) or by 180/π (radians to degrees). This matters in practice because most programming languages, including Python, expect angles in radians in their trigonometry functions. Passing 90 to a sine function when you meant 90° is a classic bug: the computer will happily compute the sine of 90 radians instead.
Sine and cosine as "how much along each axis"
Imagine a stick of length L pinned at the origin and pointing at an angle θ (theta) above the x-axis. Where is its tip?
The tip is some distance to the right and some distance up. Cosine and sine are precisely the functions that tell you these amounts for a stick of length 1:
- the tip is cos θ along x,
- and sin θ along y.
For a stick of length L, scale both by L:
x = L · cos θ
y = L · sin θCheck the intuition with easy angles. At θ = 0° the stick lies flat along x: cos 0° = 1 and sin 0° = 0, so the tip is at (L, 0). At θ = 90° it points straight up: cos 90° = 0 and sin 90° = 1, so the tip is at (0, L). At 45° the stick is halfway between, and both cos 45° and sin 45° equal about 0.707 — the tip is equally far right and up.
Worked example
A link 10 cm long is rotated 30° from the x-axis. Using cos 30° ≈ 0.866 and sin 30° = 0.5:
x = 10 · 0.866 = 8.66 cm
y = 10 · 0.5 = 5.00 cmThe tip is at about (8.66, 5.00). As a sanity check, x² + y² = 75.0 + 25.0 = 100, and √100 = 10, which is the link length. The tip is exactly as far from the origin as it should be — this is Pythagoras' theorem in action.
Vectors
A vector is a quantity with both a size and a direction, such as "10 cm at 30°". The stick above is a vector. We can write it either in polar form (length and angle) or in component form (its x and y parts, here (8.66, 5.00)). Sine and cosine convert polar to components. Going the other way:
length = √(x² + y²)
angle = atan2(y, x)The function atan2 is a two-argument version of the inverse tangent. It looks at the signs of both x and y to work out which quarter of the plane the vector points into, so it returns the correct angle all the way around the circle. The ordinary one-argument inverse tangent cannot tell (1, 1) apart from (−1, −1), because y/x is the same for both. Robotics code uses atan2 almost everywhere for this reason.
Adding vectors tip to tail
Here is the idea that unlocks robot arms. If you walk 3 m east and then 4 m north, where are you relative to where you started? You add the two movements tip to tail: start the second where the first ends. In components, you just add the x parts and add the y parts:
(3, 0) + (0, 4) = (3, 4)and your distance from the start is √(3² + 4²) = 5 m.
A robot arm is a chain of vectors, one per link. The first link starts at the base. The second link starts where the first ends. The position of the hand is simply the sum of all the link vectors. The only subtlety is working out the direction each link points, because a link's direction depends on all the joints before it. That is exactly the subject of the next lesson.
Knowledge check
Check your understanding
Go further
- MIT OpenCourseWare — 18.06 Linear Algebra ↗
A famous free university course on vectors and matrices — the mathematics behind coordinate transformations. Best for students who want a serious challenge.
Sign in to track your progress. Reading is free without an account.