Skip to the lesson
FixTheRobot Explore Robotics / Linear Algebra / M1 Mathematical Foundations / M1-T1

Linear Algebra · Theory · M1

M1-T1 — Vectors and Coordinates

A vector is an arrow you can add, stretch and measure. Robots use arrows for where things are, which way to go and how fast.

  • Lesson 1 of 3
  • Module 1: Mathematical Foundations
  • Foundations
  • About 13 minutes to read

Every robot program starts with the same question: where is the thing I care about, relative to me? This lesson builds the language to answer it. You will separate a position from a displacement, add motions head to tail, see why the numbers of a vector change when the axes change while the arrow does not, and derive the formula that turns world coordinates into robot coordinates.

Learning objectives

After this lesson, you should be able to:

  • Distinguish a position (a point) from a displacement (an arrow) and compute the displacement from one position to another.
  • Add, subtract and scale vectors by components and by the head-to-tail picture, and say what each means as robot motion.
  • Describe a velocity as a vector with a speed and a heading, and predict the position after a time step.
  • Express the same vector in the world frame and in a robot frame, and derive the conversion with the angle-subtraction identities.

Introduction and motivation

Every robot answers three questions all the time: where am I, where is the thing I care about, and how should I move? Positions, directions and velocities are all vectors, so the whole course rests on this lesson. A mobile robot driving to a charging dock, a drone holding a hover against the wind and a manipulator reaching for a cup all begin with an arrow from here to there.

The intuition

Stand in a hallway and point at a door. Your arm is a vector: it has a direction and a length, and nothing else. It does not matter where you stand; a person next to you pointing the same way with the same stretch is making the same vector. A vector is an arrow that can be slid anywhere.

A position is different. It is a place, a point in the world measured from a chosen origin. To say where the robot is, you first pick an origin and two axes, say x to the east and y to the north, and then write two numbers. Those two numbers are the arrow from the origin to the robot: the position vector.

The useful object for a robot is the arrow between two places. If the robot is at r and the target is at t, the arrow from robot to target is the displacement d = t − r. It answers “how far, and which way, from here to there?”, which is exactly what a motion controller needs.

Position, displacement and two legs of motionA coordinate grid with the origin at the lower left. A robot sits at (2, 1) and a target at (6, 4). The displacement d from robot to target is the arrow (4, 3). The same displacement is also reached in two legs: first (4, 0) to the east, then (0, 3) to the north. Thin dashed arrows from the origin show the position vectors r and t. x (east)y (north) r = (2, 1) t = (6, 4) leg 1: (4, 0) leg 2: (0, 3) d = t − r= (4, 3) robot target
The robot at (2, 1) and the target at (6, 4). The green arrow is the displacement. The blue and orange arrows reach the same place in two legs: arrows add by placing them head to tail.

Arrows add head to tail

Walk 4 m east, then 3 m north. You end up where a single 5 m walk to the north-east would take you. That is vector addition: put the second arrow where the first one ends, and the sum is the arrow from the start of the first to the end of the second. Stretching an arrow (multiplying it by a number) is going further in the same direction, or backwards if the number is negative.

Interactive figure. Two arrows a and b are placed head to tail; their sum is the arrow from the start of a to the end of b. The readout lists the components and lengths of a, b and a + b. This figure needs JavaScript to be interactive.

Drag the blue handle to change a, and the gold handle to change b. The green arrow a + b is the combined motion. Try making them point in opposite directions: the sum gets short.

Same arrow, different numbers

The numbers you write down for an arrow depend on the axes you chose. A robot has its own axes: forward and left. If the robot turns, the arrow to the target has not moved, but its forward and left components have. A navigation stack constantly converts between the world axes (good for maps) and the robot axes (good for commands), so it pays to understand exactly how the numbers change.

Interactive figure. A robot at the origin has forward and left axes at an angle you choose. An arrow d points to a target. The readout gives its components in the world axes and in the robot axes, and says in plain English how far ahead and to which side the target is. This figure needs JavaScript to be interactive.

Rotate the robot with the heading slider. The orange arrow never moves, but its world components (dashed grey) and its robot-frame components (dashed green and gold) change. The length stays the same.

A vector is the arrow. Its components are just one way of writing the arrow down, and they depend on the axes. When two programmers disagree about a vector, check the frame before the numbers.

Geometric and physical interpretation

Geometric view. A vector is an arrow with a length and a direction, free to slide anywhere on the plane. Adding two arrows is walking one after the other; stretching an arrow is walking further. Physical view. A displacement is a distance you travel, a velocity is a displacement per second, and a force is a push with a direction. All of them obey the same arithmetic, which is why one set of rules serves odometry, control and sensing alike.

The mathematics

In the plane, choose an origin and two perpendicular unit arrows ex = (1, 0) and ey = (0, 1). Every vector is a combination of these two:

v = vx · ex + vy · ey = (vx, vy)

What it means. A vector is built by walking vx steps along x and vy steps along y. The pair (vx, vy) is only the recipe; the arrow itself exists without it.

r, t
position vectors: the arrows from the origin to the robot and to the target.
d = t − r
the displacement from the robot to the target.
v
a velocity, in metres per second. Its length is the speed.
Δt
a time step in seconds.
θ
the robot heading: the angle of its forward direction, counter-clockwise from +x, in radians.
f, l
the robot's forward and left unit arrows.

Displacement and the origin

d = t − r = (tx − rx, ty − ry)

What it means. Subtract the start from the end, component by component. The result is the arrow from the robot to the target and tells the robot how far to go in each axis direction.

Adding and scaling

a + b = (ax + bx, ay + by)        k · a = (k·ax, k·ay)

What it means. Adding vectors composes motions: do a, then do b. Scaling by k stretches the arrow; a negative k reverses it. Subtraction a − b = a + (−1)·b is the arrow from the end of b to the end of a.

Velocity and motion

r(t + Δt) = r(t) + v · Δt

What it means. Moving at velocity v for Δt seconds adds the displacement v·Δt to the position. A path made of several legs is a sum of such displacements.

Heading and speed

v = s · (cos θ, sin θ)        s = speed, θ = heading

What it means. A speed s and a heading θ carry the same information as the pair (vx, vy). The pair (cos θ, sin θ) is the unit arrow that points along the heading.

Components in the robot frame

The robot frame has the unit arrows f = (cos θ, sin θ) pointing forward and l = (−sin θ, cos θ) pointing to the left, a quarter turn counter-clockwise from f. Writing a world vector v in this frame means finding the numbers vf and vl with v = vf f + vl l. The derivation below shows they are:

vf =  vx · cos θ + vy · sin θ
vl = −vx · sin θ + vy · cos θ

What it means. v_f is how far the arrow reaches ahead of the robot and v_l how far it reaches to the robot's left. It is the same arrow, measured against axes that turned by θ.

The arrow is frame-independent. Its components are not. The length |v| is the same in every frame, which is why robot-frame and world-frame answers can always be checked against each other.

Step-by-step derivation: why the robot-frame formula looks like that

Claim 1: the displacement does not depend on the origin. Move the origin by an offset o. Every position gains the same offset: r′ = r + o (written as new numbers) and t′ = t + o. Then

t′ − r′ = (t + o) − (r + o) = t − r

What it means. The offset appears in both positions and cancels. Positions depend on where you put the origin; displacements do not. This is why a controller is happier with “go 4 m east and 3 m north” than with an absolute map coordinate.

Claim 2: robot-frame components come from the angle-subtraction identities. Write the vector in polar form with length s and angle α measured from the world x axis: v = (s cos α, s sin α), so vx = s cos α and vy = s sin α. Seen from a robot that faces angle θ, the same arrow is rotated by −θ: it makes the angle α − θ with the robot's forward axis. Its forward and left components are therefore:

  1. Forward component. v_f = s cos(α − θ). Expand with cos(α − θ) = cos α cos θ + sin α sin θ.
  2. Substitute s cos α = vx and s sin α = vy: v_f = vx cos θ + vy sin θ.
  3. Left component. v_l = s sin(α − θ). Expand with sin(α − θ) = sin α cos θ − cos α sin θ.
  4. Substitute again: v_l = −vx sin θ + vy cos θ. These are the two formulas of the previous section.

Claim 3: the length is unchanged. Add the squares:

vf² + vl² = (vx cos θ + vy sin θ)² + (−vx sin θ + vy cos θ)²
          = vx² (cos²θ + sin²θ) + vy² (sin²θ + cos²θ) + 2 vx vy (cos θ sin θ − sin θ cos θ)
          = vx² + vy²

What it means. The cross terms cancel and cos² + sin² = 1. Whatever axes you pick, the arrow keeps its length, so √(v_f² + v_l²) must equal √(vx² + vy²). This is the check you can run on any frame conversion.

The two formulas have the shape “multiply and add matching components”. That pattern is the dot product, the topic of the next lesson, and the pair of formulas together is a rotation matrix, which Module 2 and Module 7 build up properly.

A worked example: from a map position to “3 m ahead, 4 m to the right”

A robot is at r = (2, 1) metres. A beacon is at t = (6, 4). The robot faces north, θ = 90°.

  1. Displacement. d = t − r = (6 − 2, 4 − 1) = (4, 3). Its length is √(4² + 3²) = 5 m.
  2. Two legs. Drive east at v₁ = (2, 0) m/s for 2 s: displacement (4, 0). Then drive north at v₂ = (0, 1.5) m/s for 2 s: displacement (0, 3). Final position (2, 1) + (4, 0) + (0, 3) = (6, 4), the beacon, so the two legs add up to d.
  3. Robot axes. At θ = 90°, f = (cos 90°, sin 90°) = (0, 1) and l = (−sin 90°, cos 90°) = (−1, 0).
  4. Components. d_f = 4·cos 90° + 3·sin 90° = 3 and d_l = −4·sin 90° + 3·cos 90° = −4.
  5. Read it. Forward 3, left −4: the beacon is 3 m ahead and 4 m to the right. A negative left component means right.
  6. Check. √(3² + (−4)²) = 5, the same length as in the world frame.

The robot faces north and the beacon is north-east of it, so “ahead and to the right” matches the picture. The numbers (4, 3) and (3, −4) describe one and the same arrow in two sets of axes.

Robotics application

Waypoint missions. A mission is a list of positions. The robot needs the displacement from where it is now to the next waypoint, t − r, recomputed as it moves. Nothing else about the map matters.

Velocity commands. A drive controller outputs a velocity vector. Over one control step of Δt the position changes by v·Δt. Summing these small displacements is exactly how wheel odometry and dead reckoning estimate where a robot has been, and why small errors accumulate: every step adds one more slightly wrong arrow.

Wind, current and drift. A drone in a crosswind or a boat in a current moves with velocity v + w, where w is the disturbance. To travel along v_desired the vehicle must command v_desired − w, a vector subtraction. The length of that command shows how much of the vehicle's capability the wind consumes.

Sensor readings. A LiDAR or camera reports where an object is relative to the sensor, in the sensor's axes. Placing it on the map means converting those robot-frame components into world components with the inverse of the formula derived above. Mixing up the two frames is one of the most common causes of a robot that drives confidently to the wrong place. The SLAM track's lessons on poses and frames and 2D rigid transforms take this idea all the way to full transforms.

Engineering implications and limitations

Practical rules

  • Name the frame of every vector. Write d_world and d_robot, or map_p_goal; never a bare d. Most frame bugs are unnamed frames.
  • Keep units and angle conventions fixed. This course uses metres, seconds, radians, and angles counter-clockwise from +x. Mixing degrees and radians, or a clockwise heading, silently rotates every result.
  • Convert once, at the boundary. Do the arithmetic in one frame and convert at the edges, rather than mixing frames inside an expression.
  • Floating point is approximate. cos(90°) is not exactly 0 in a computer (it is about 6·10⁻¹⁷). Compare with a tolerance, never with ==.
  • Three dimensions work the same way. A drone adds a z component; addition, scaling and displacement are unchanged. Only the frame conversion needs a 3×3 rotation, which Module 7 builds.

Limits

Treating a robot position as an arrow from an origin is exact on a flat map and a good approximation over a small area. Over long distances on the Earth the surface curves, and “vector from the origin” stops being a good model; GNSS software converts to a local flat frame first.

Common misconceptions

“A vector is a position.”

A position is a point and needs an origin. A vector is an arrow and does not. The same displacement (4, 3) can start anywhere. You may add a displacement to a position and get a position; adding two positions has no meaning.

“The components are the vector.”

The components are the recipe in one set of axes. Rotate the axes and the recipe changes while the arrow stays put. Always ask: components in which frame?

“Adding vectors adds their lengths.”

Only when they point the same way. In general the length of a sum is at most the sum of the lengths (try it in the first figure): 4 m east plus 3 m north is 5 m, not 7 m.

“A negative component means something went wrong.”

A negative component only says which side of the axis the arrow lies on. A left component of −4 is a perfectly good way to say “4 m to the right”.

Engineering takeaways

  1. A position is a point; a displacement t − r is an arrow, and it does not depend on where the origin is.
  2. Vectors add head to tail and scale by stretching, which is how motions combine and how a path is a sum of legs.
  3. A velocity v moves a robot by v·Δt in a time Δt; its length is the speed and its direction is the heading.
  4. Components belong to a frame. The robot-frame components are vf = vx cos θ + vy sin θ and vl = −vx sin θ + vy cos θ.
  5. A frame change never changes length, so |v| is the check on every conversion.

References and further reading

Where to read more. Free to read does not mean free to copy: follow each licence.

Knowledge check

Three conceptual questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

You move the origin of your map 10 m to the east. What happens to (a) the robot's position coordinates and (b) the displacement from the robot to a beacon? Why does that make displacements a safer thing to send to a controller?

Explanation

(a) Every position coordinate changes: x decreases by 10 for the robot and for the beacon, because both are now measured from a new origin. (b) The displacement does not change, because the 10 cancels in t − r. A controller that is told “go (4, 3) from where you are” works under any choice of map origin, while an absolute coordinate is only meaningful together with its origin.

Question 2

A drone commands a velocity of (0, 1.5) m/s for 4 s in a steady wind that adds (0.5, 0) m/s. Where does it end up relative to its start, and what velocity should it command to fly straight north at 1.5 m/s? What does that tell you about the wind?

Explanation

The actual velocity is the sum (0.5, 1.5), so after 4 s the displacement is (2, 6): it drifts 2 m east. To cancel the wind it must command v_desired − w = (0, 1.5) − (0.5, 0) = (−0.5, 1.5). That command has length √(0.25 + 2.25) ≈ 1.58 m/s, larger than the 1.5 m/s of useful progress: fighting the wind costs speed.

Question 3

A target's robot-frame components are forward = −2 and left = 0. Where is the target? Does its length from the robot depend on which frame you use? What might its world components be if the robot faces east?

Explanation

The target is exactly 2 m directly behind the robot (negative forward, no sideways offset). Its distance is 2 m in every frame, since a frame change preserves length. If the robot faces east (θ = 0), forward is +x, so the world displacement is (−2, 0); if it faced north the same target would have world components (0, −2).

What’s next

You can now describe where things are and how motions combine. Next you will measure those arrows: how long they are, how far apart two positions are, and what angle one arrow makes with another, using the dot product.

Practice this lesson

2D Robot Vector Navigator

Steer a simulated robot to a beacon with vectors: compute the heading, the distance and the sideways error from the planned path.

Next lesson

M1-T2 — Dot Product, Norms and Angles

Compute lengths, angles and projections with the dot product, and read it as how much one direction agrees with another.

Nothing below is required to finish this lesson.

  • Lab
    M1-L1: 2D Robot Vector Navigator

    Steer a simulated robot to a beacon with vectors: compute the heading, the distance and the sideways error from the planned path.