Lite / Textbooks / The Mathematics of Machines / Chapter 4
4. Vectors
Introduction
Forces, velocities and displacements have a size and a direction. A vector stores both as components that you can add part by part. This chapter adds vectors, finds their length with Pythagoras, finds their direction with atan2 (which, unlike a plain inverse tangent, knows which quadrant it is in) and uses the dot product to measure how much two directions agree.
Figure 4.1. Adding vectors tip to tail (described in words)
On a grid, vector a = (3, 1) is drawn from the origin, then vector b = (1, 2) from the tip of a. Their sum a + b = (4, 3) goes from the origin to the final tip, with length sqrt(4^2 + 3^2) = 5.
Explanation
Built from 3 School lessons. Each part is the lesson's own explanation.
4.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 Lite lesson: Vectors: arrows you can add
4.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 Lite lesson: Which way is it pointing? Direction with atan2
4.3 The dot product: how much do two arrows agree?
One number can tell a robot whether a target is in front of it or behind it, without a single angle being measured. How?
The recipe
a · b = ax·bx + ay·by: multiply matching parts and add. The result is a plain number (a scalar), not a vector. Order doesn't matter: a · b = b · a. And a · a = |a|², so the dot product contains Pythagoras.
What the sign says
From a · b = |a||b| cos θ: positive when the angle is under 90° (pointing roughly together), zero when perpendicular, negative when over 90° (pointing roughly apart). Lengths are never negative, so the sign comes entirely from cos θ.
Angles and shadows
Rearranged, cos θ = a · b ÷ (|a||b|), which gives the angle between any two non-zero vectors. And a · b ÷ |b| is the scalar projection of a on b: the length of a's shadow along b's direction. That is how a robot finds the part of a force that acts along a slide, or how far ahead an obstacle is along its heading.
Derivation: Why a · b = |a||b| cos θ (from the law of cosines)
Draw a and b from the same point, with angle θ between them. The third side of the triangle is the vector a − b.
The law of cosines for that triangle says: |a − b|² = |a|² + |b|² − 2|a||b| cos θ.
Expand the left side with components: |a − b|² = (ax − bx)² + (ay − by)² = ax² + ay² + bx² + by² − 2(ax·bx + ay·by).
But ax² + ay² = |a|² and bx² + by² = |b|², so the left side is |a|² + |b|² − 2(ax·bx + ay·by).
Compare the two expressions: the |a|² and |b|² cancel, leaving ax·bx + ay·by = |a||b| cos θ. The component recipe and the geometric meaning are the same number.
Common mix-ups
The dot product of two vectors is another vector.
✓ It is a single number. (Multiplying each part and keeping them separate is a different operation.)A negative dot product means one vector is 'negative'.
✓ It means the angle between them is more than 90°: they point roughly in opposite directions.
Open the Lite lesson: The dot product: how much do two arrows agree?
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°.
The dot product: how much do two arrows agree?: example 1
Is the target at r = (−2, 5) ahead of or behind a robot facing h = (0.6, −0.8)?
Solution
h · r = 0.6 × (−2) + (−0.8) × 5 = −1.2 − 4 = −5.2. Negative: the target is behind, 5.2 m back along the heading line (h has length 1).
Interactive figures, in words
Figure 4.2 from Vectors: arrows you can add
In '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|.
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.
Laboratory
These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.
- Equation Lab: Vectors (Equation Lab exploration)
Drag two vectors until their dot product is zero, and measure the angle between them.
Open on the full site - Simulation OS: Two-link reach (Simulation OS experiment)
Describe the arm's tip as the sum of two link vectors and predict its reach before running the model.
Open on the full site
Practice
Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.
- a = (2, −3) and b = (−5, 4). What is the x component of a + b?
Answer it in “Vectors: arrows you can add” - What is the magnitude of the vector (6, 8)?
Answer it in “Vectors: arrows you can add” - atan2(3, −4) is closest to which angle?
Answer it in “Which way is it pointing? Direction with atan2” - A target is at (−5, 12) m from a robot. How far away is it, in metres?
Answer it in “Which way is it pointing? Direction with atan2” - For which vector does tan⁻¹(y/x) give the correct direction?
Answer it in “Which way is it pointing? Direction with atan2” - Find a · b for a = (4, −1) and b = (2, 3).
Answer it in “The dot product: how much do two arrows agree?” - Which vector is perpendicular to (2, 5)?
Answer it in “The dot product: how much do two arrows agree?” - A 10 N force F = (8, 6) N pushes a cart that can only roll along the x axis. How many newtons act along the rail? (Hint: dot F with the unit vector (1, 0).)
Answer it in “The dot product: how much do two arrows agree?”
Engineering applications
Navigation
A rover's heading towards a waypoint is atan2(dy, dx). Using a plain inverse tangent of dy/dx would send it the wrong way whenever the target lies behind and to the left.
Useful work
The work a force does on a moving cart is the dot product of force and displacement. Only the part of the force along the motion counts, so a sideways push does no work on the cart.
Watch (optional)
Streaming video uses a lot of data. Everything you need is in the text.
- “Vectors | Chapter 1, Essence of linear algebra” by 3Blue1Brown
- “Vectors and 2D Motion: Crash Course Physics #4” by CrashCourse
- “Dot products and duality | Chapter 9, Essence of linear algebra” by 3Blue1Brown
Summary
- A vector in the plane is a pair of components (x, y); vectors add component by component.
- The magnitude is sqrt(x^2 + y^2); the direction is atan2(y, x).
- a·b = ax·bx + ay·by = |a|·|b|·cos θ.
- A dot product of zero means the vectors are perpendicular; a negative one means they point more than 90° apart.
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. Field Guide
- 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. Field Guide
- 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. Field Guide
- Pythagoras' theorem
- In a right-angled triangle, the square of the hypotenuse equals the sum of the squares of the other two sides. Field Guide
Project: Plan a three-leg route
A delivery robot drives three straight legs given as distances and headings. Convert each leg to components, add them, and give the straight-line distance and heading back to the start. Check the result by drawing the route to scale.
Deliverables
- A table of legs with components
- The total displacement, distance and heading
- A scale drawing and the difference between drawing and calculation
Write it up on paper or in your own notes. Lite never stores what you write.
References
- Gilbert Strang (2016). Introduction to Linear Algebra, 5th edition. Wellesley-Cambridge Press.
- Erwin Kreyszig (2011). Advanced Engineering Mathematics, 10th edition. Wiley.
Further reading from the lessons
- Euclidean vector (Wikipedia)
A thorough reference for vector notation and operations. - atan2 (Wikipedia)
The full definition, case by case, and its history in programming languages. - Dot product (Wikipedia)
Both definitions, their equivalence and many applications.