Skip to content
Tactiverge

Textbooks/Robotics From First Principles/Chapter 3Lite (plain text) version

3Vectors and frames

Version 1 · Technically checked (automated checks only) · 4 source lessons · 7 practice items

Text
All chapters and search
  1. 1. Sense, think, act
  2. 2. Actuators and drives
  3. 3. Vectors and frames
  4. 4. Rotations and transforms
  5. 5. Forward kinematics
  6. 6. Inverse kinematics
  7. 7. Motion and trajectories
  8. 8. Where am I? Drift, uncertainty and fusion

Introduction

A position is an arrow from somewhere. Change the somewhere and the same point gets a new address. Robots juggle frames constantly: the world frame on the map, the body frame on the chassis, a frame on every joint. This chapter adds and measures arrows, finds directions with atan2, and converts a point seen by the robot into a point on the map, which is how a robot knows where an obstacle really is.

xy(2, 2)(1, 1)robot at (2, 1)heading 90°body (1, 0) = aheadbody (0, 1) = left
Figure 3.1. One point, two addresses. A robot at (2, 1) on a map, facing 90° (straight up the y axis). A point 1 m ahead in its body frame is at (2, 2) in the world, and a point 1 m to its left is at (1, 1).

Explanation

This chapter is built from 4 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.

3.1 Vectors: arrows you can add

A drone flies 3 m east, then 4 m north. It is 5 m from where it started, not 7. Where did the other 2 m go?

Size and direction, written as components

A vector is a quantity with a size and a direction, such as a displacement, a velocity or a force. In 2D we write it as two components, v = (vx, vy): how far along x, then how far along y, measured in some coordinate frame. The same arrow drawn anywhere on the page is the same vector; only its components matter.

Adding: tip to tail, or part by part

To add a and b, draw b starting where a ends; the sum runs from the start of a to the end of b. Algebraically that is just a + b = (ax + bx, ay + by). Subtraction works the same way: a − b is the arrow from the tip of b to the tip of a. Scaling by a number k multiplies both parts: k·a = (k·ax, k·ay).

Magnitude: Pythagoras in disguise

The components form the two short sides of a right-angled triangle, so the length (magnitude) is |v| = √(vx² + vy²). Lengths do not add like components: |a + b| ≤ |a| + |b|, with equality only when a and b point the same way. That is the drone's missing 2 m: 3 east + 4 north is (3, 4), length 5.

Common mix-ups

  • The length of a + b is |a| + |b|.
    ✓ Only when a and b point the same way. In general |a + b| is smaller, and you must add components first.
  • Moving an arrow to a different place on the page makes it a different vector.
    ✓ A vector is just its components. Position on the page doesn't matter; that is what lets you draw tip to tail.

Open the full lesson: Vectors: arrows you can add →

3.2 Which way is it pointing? Direction with atan2

Your calculator says tan⁻¹(−1 ÷ −1) = 45°. But (−1, −1) points down and to the left. Who is wrong?

Two ways to write the same arrow

Components: (x, y). Polar form: length r and direction θ, measured anticlockwise from +x. To go from polar to components: x = r cos θ, y = r sin θ. To go back: r = √(x² + y²) and θ from the inverse tangent, carefully.

Why tan⁻¹(y/x) lies

tan θ = y/x, but dividing throws away the signs: (1, 1) and (−1, −1) both give y/x = 1. So tan⁻¹ can only answer between −90° and 90°: it is right for vectors pointing rightwards (x > 0) and exactly 180° out for vectors pointing leftwards. At x = 0 it divides by zero.

atan2: the angle that knows its quadrant

atan2(y, x) takes the two parts separately, checks their signs and returns an angle in (−180°, 180°]. Add 360° to negative answers if you want 0–360°. It is in every language: Python's math.atan2, JavaScript's Math.atan2, C's atan2. Note the order: y first. Robot code uses it to turn components back into headings and joint angles.

Common mix-ups

  • tan⁻¹(y/x) always gives a vector's direction.
    ✓ Only when x > 0. Use atan2(y, x), which checks both signs.
  • atan2 takes (x, y) like a coordinate.
    ✓ It takes (y, x): the y component first. Swapping them gives the angle measured from the y axis instead.

Open the full lesson: Which way is it pointing? Direction with atan2 →

3.3 One point, many addresses: coordinate frames

The gripper's camera says the cup is 10 cm ahead. The base says it is 52 cm to the right. They are both correct. How?

A frame is an origin plus axes

A coordinate frame is a chosen origin and a pair of perpendicular unit axes (x and y in 2D). A point's coordinates are its distances along those axes from that origin. Change the origin or turn the axes and the numbers change, even though the point hasn't moved.

Every part gets a frame

Robots typically use a world frame fixed to the room, a base frame on the robot, a frame on each link (x along the link) and a tool frame at the gripper tip. Sensors have frames too: a camera measures in a camera frame. We label points with the frame they're in, for example p_base or p_camera, and never mix them.

Translating between frames

If frame B's origin sits at t in frame A and B's axes are not rotated, then p_A = p_B + t. If B is also rotated, the axes no longer line up and we must rotate first: p_A = R·p_B + t. Rotations need matrices (week 13); the full move between frames is a transform (week 14). For now: always ask 'in which frame is this number?'.

Common mix-ups

  • A point has one true set of coordinates.
    ✓ Coordinates belong to a frame. The point is real; its numbers depend on the frame you measure from.
  • Changing frames is always just adding an offset.
    ✓ Only when the axes are parallel. Rotated frames also mix x and y, which needs a rotation.

Open the full lesson: One point, many addresses: coordinate frames →

3.4 Body frame, world frame: how a vehicle sees the world

A pilot says 'traffic at two o'clock'. Air traffic control says 'traffic north-east of you'. Same aircraft. Why two languages?

Two frames, two jobs

The world frame is fixed: for an aircraft or rover, east (x) and north (y) on a flat map; for a spacecraft, axes pointing at chosen distant stars, because space has no 'north'. The body frame moves with the vehicle: x out of the nose, y out of the left side (and z up in 3D). Engines push along body axes; maps and waypoints are given in world axes.

Heading links them

Heading is the compass direction of the nose, in degrees clockwise from north. Maths angles go anticlockwise from +x (east). So the nose's maths angle is ψ = 90° − heading. A heading of 0° (north) is ψ = 90°; heading 90° (east) is ψ = 0°. Mixing the two conventions is a classic navigation bug.

What changes when you turn

Turn the vehicle and every body-frame coordinate of the outside world changes, while world-frame coordinates stay put. That is why a pilot's 'two o'clock' needs updating after every turn, while air traffic control's 'north-east' does not. Converting a world point into the body frame means: subtract the vehicle's position, then rotate by −ψ.

Common mix-ups

  • Heading and the mathematical angle are the same number.
    ✓ Heading is clockwise from north; the maths angle is anticlockwise from east. ψ = 90° − heading.
  • The body frame is just the world frame moved to the vehicle.
    ✓ It is moved AND rotated with the nose. That rotation is why turning changes every body-frame number.

Open the full lesson: Body frame, world frame: how a vehicle sees the world →

Worked examples

Vectors: arrows you can add: example 1

A rover drives a = (5, −2) m, then b = (−1, 6) m. Where does it end up, and how far is that from the start?

Solution

a + b = (5 − 1, −2 + 6) = (4, 4) m. Distance = √(4² + 4²) = √32 ≈ 5.66 m.

Which way is it pointing? Direction with atan2: example 1

Give the direction of (4, −9) in degrees from 0 to 360.

Solution

Fourth quadrant. atan2(−9, 4) ≈ −66.0°; add 360° → 294.0°. (Here tan⁻¹ happens to agree, −66°, because x > 0.)

Which way is it pointing? Direction with atan2: example 2

A 2.5 m link points at 200°. Where is its tip?

Solution

x = 2.5 cos 200° ≈ −2.349 m, y = 2.5 sin 200° ≈ −0.855 m. Both negative: third quadrant, as expected for 200°.

One point, many addresses: coordinate frames: example 1

A camera is mounted 0.1 m forward and 0.05 m up from a gripper's origin, not rotated. It sees a cup at (0.25, −0.05) m in its own frame. Where is the cup in the gripper frame?

Solution

p_gripper = p_camera + t = (0.25 + 0.1, −0.05 + 0.05) = (0.35, 0) m: dead ahead of the gripper.

Body frame, world frame: how a vehicle sees the world: example 1

A simulated drone is at (0, 0) heading 180° (south). A waypoint is at (4, 0) km (east). Where is it in the body frame?

Solution

ψ = 90° − 180° = −90°: the nose points along −y. d = (4, 0). Forward = d·(cos ψ, sin ψ) = 4 × 0 + 0 × (−1) = 0. Left = d·(−sin ψ, cos ψ) = 4 × 1 + 0 = 4 km. Facing south, east is on your left.

Interactive figures

Figure 3.2 from Vectors: arrows you can addIn 'Add tip to tail', set a = (3, 1) and b = (1, 2.5). Check the green sum against your prediction. Now make b point exactly opposite to a. What happens to a + b? Then find a b for which |a + b| = |a| + |b|.
Can't use the interactive? Read a description instead

The vector playground draws vector a in blue from the origin, vector b in orange starting at the tip of a, and their sum in dashed green from the origin to the tip of b. The readout lists every component, the sum and its length, and the same information is in the text above.

Interactive figure (online). Description: The vector playground draws vector a in blue from the origin, vector b in orange starting at the tip of a, and their sum in dashed green from the origin to the tip of b. The readout lists every component, the sum and its length, and the same information is in the text above.

Figure 3.3 from Body frame, world frame: how a vehicle sees the worldStart with the aircraft. Choose ALPHA and read its body-frame position. Now change only the heading, in steps of 45°. Which numbers in the readout change, and which stay the same? Switch to the spacecraft: what replaces 'north'?
Can't use the interactive? Read a description instead

The diagram shows a top-down map with a vehicle icon, its forward (blue) and left (green) body axes, and a diamond-shaped waypoint joined to it by a dashed line. The readout gives the waypoint's world coordinates, distance and bearing, plus its body-frame forward and left distances. Turning the vehicle changes only the body-frame numbers.

Interactive figure (online). Description: The diagram shows a top-down map with a vehicle icon, its forward (blue) and left (green) body axes, and a diamond-shaped waypoint joined to it by a dashed line. The readout gives the waypoint's world coordinates, distance and bearing, plus its body-frame forward and left distances. Turning the vehicle changes only the body-frame numbers.

Laboratory

Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.

Guided practice

Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.

Practice 1

a = (2, −3) and b = (−5, 4). What is the x component of a + b?

Practice 2

What is the magnitude of the vector (6, 8)?

Practice 3

atan2(3, −4) is closest to which angle?

Practice 4

For which vector does tan⁻¹(y/x) give the correct direction?

Practice 5

Frame B's origin is at (3, −1) in frame A, with the same axis directions. A point is at (2, 4) in B. What is its x coordinate in A?

Practice 6 · a fresh version every time

In a simulation, an aircraft is at (−4, 0) km with its nose pointing 135° anticlockwise from the world +x axis. A waypoint is at (4, −2) km. In the aircraft's body frame (x forward, y to the left), what is the waypoint's forward (x) coordinate, in km? (2 decimal places; negative means behind)

km

Practice 7

A rover heads north (ψ = 90°) from (0, 0). A rock is at (−3, 5) m. How far to the LEFT of the rover is it, in metres? (Body frame: y is left.)

m
  1. a = (2, −3) and b = (−5, 4). What is the x component of a + b?
  2. What is the magnitude of the vector (6, 8)?
  3. atan2(3, −4) is closest to which angle?
    • −36.9°
    • 36.9°
    • 143.1°
    • 216.9°
  4. For which vector does tan⁻¹(y/x) give the correct direction?
    • (−2, 5)
    • (3, −1)
    • (−1, −1)
    • (0, 4)
  5. Frame B's origin is at (3, −1) in frame A, with the same axis directions. A point is at (2, 4) in B. What is its x coordinate in A?
  6. In a simulation, an aircraft is at (−4, 0) km with its nose pointing 135° anticlockwise from the world +x axis. A waypoint is at (4, −2) km. In the aircraft's body frame (x forward, y to the left), what is the waypoint's forward (x) coordinate, in km? (2 decimal places; negative means behind) (km)
  7. A rover heads north (ψ = 90°) from (0, 0). A rock is at (−3, 5) m. How far to the LEFT of the rover is it, in metres? (Body frame: y is left.) (m)

Engineering applications

  • Mapping obstacles

    A lidar reports each obstacle as a distance and angle from the robot. To put it on a shared map, the robot rotates it by its own heading and adds its own position: a body-to-world conversion, many thousands of times a second.

  • Why atan2

    The angle of an arrow from tan alone is ambiguous: (1, 1) and (−1, −1) give the same ratio. atan2 looks at both signs and returns the right quadrant, which is why navigation code uses it everywhere.

Watch

Optional verified videos. Nothing loads from YouTube until you press play.

Three views of a vector (an arrow, a list of numbers, a thing you can add and scale) drawn so clearly that components stop feeling abstract.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

Splits motion into horizontal and vertical parts that run independently, the trick behind every projectile calculation.

Length: see YouTube · captions on YouTube · source

Nothing loads from YouTube until you press play.

  • Vectors | Chapter 1, Essence of linear algebra (3Blue1Brown)
  • Vectors and 2D Motion: Crash Course Physics #4 (CrashCourse)

Chapter summary

  • A vector has components; add vectors by adding components, and find length with Pythagoras.
  • atan2(y, x) gives the direction of an arrow in the correct quadrant, unlike tan alone.
  • The same point has different coordinates in different frames.
  • Body to world: rotate by the robot's heading, then add the robot's position.

Glossary

Vector addition
Vectors are added component by component: the x parts add, the y parts add, and the result is the single vector with the same effect as both.
Vector magnitude and direction
A 2D vector can be written as components (x, y) or as a magnitude and a direction angle; cosine and sine convert between the two.
Coordinate frame
A coordinate frame is an origin plus a set of axes used to describe positions and directions. Robots use several: world, base, each joint, sensors and the tool.
Pythagoras' theorem
In a right-angled triangle, the square of the hypotenuse equals the sum of the squares of the other two sides.
Dot product
The dot product of two vectors multiplies matching components and adds them; it also equals the product of their lengths and the cosine of the angle between them.

Definitions from the Field Guide.

Project: From sensor to map

A robot at a known position and heading sees three obstacles, each given as a distance and bearing relative to its nose. Convert all three into world coordinates by hand and in code, then repeat after the robot turns 90°. Plot both sets and explain why the world positions did not change.

Deliverables

  • Hand calculations for one obstacle
  • A short program converting all three
  • A plot and a one-paragraph explanation

Keep your work in your Engineering Journal; it stays private unless you choose to share it.

References

  • Kevin M. Lynch and Frank C. Park (2017). Modern Robotics: Mechanics, Planning, and Control. Cambridge University Press.
  • John J. Craig (2005). Introduction to Robotics: Mechanics and Control, 3rd edition. Pearson Prentice Hall.
  • Roland Siegwart et al. (2011). Introduction to Autonomous Mobile Robots, 2nd edition. MIT Press.

Further reading from the source lessons

Publication record

Version
1
Status
Technically checked (automated checks only)
Technical review
Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
Written by
Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
Licence
All rights reserved by the founders unless a licence is approved.
Corrections
None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.