Lite / Intelligent Robotic Systems / Week 10
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?
Why should I care?
The dot product turns two arrows into a single number that measures how much they point the same way. Robots use it to check whether an obstacle is ahead, how much of a force pushes along a rail, and how bright a lit surface looks. It's the cheapest useful calculation in all of geometry.
- Compute a dot product from components.
- Use a · b = |a||b| cos θ to find the angle between two vectors.
- Interpret the sign of a dot product and use it to test for perpendicular vectors and projections.
Predict
a = (3, 1) and b = (−1, 3). Without drawing, what can you say about the angle between them?
- Less than 90°
- Exactly 90°
- More than 90°
- You need a protractor to know
Guess first, then reveal
Exactly 90°. a · b = 3 × (−1) + 1 × 3 = 0, and a zero dot product means perpendicular. No angles needed.
Discover
Switch to 'Dot product and angle'. Keep b = (3, 0). Swing a round (try (3, 2), (0, 3), (−2, 2), (−3, −1)). Watch the sign of a · b and the green shadow. When is the dot product zero? When is it biggest for a fixed |a|?
What the interactive shows (text version)
In dot-product mode the playground draws a and b from the origin and shades the shadow of a along b in green. The readout gives the dot product, both lengths, the angle between them and the shadow length. For b = (3, 0) the dot product is 3 × a's x part: positive when a leans right, zero when a points straight up or down, negative when it leans left.
Watch (optional)
Watch for: Watch for the projection picture: the dot product is the length of one vector's shadow on the other, times the other's length.
Why multiplying components and adding gives the same number as lengths times the cosine of the angle: the projection picture behind the dot product.
“Dot products and duality | Chapter 9, Essence of linear algebra” by 3Blue1Brown (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
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.
Explain it another way
Intuitive
Imagine shining a torch straight down onto b. a casts a shadow along b. A long shadow pointing the same way gives a big positive dot product; a shadow pointing backwards gives a negative one; no shadow at all means the arrows are at right angles.
Technical
The dot product is the standard inner product on ℝ². It is linear in each argument, symmetric, and positive-definite (a · a > 0 for a ≠ 0). It is invariant under rotation, so the angle it measures doesn't depend on the frame you choose.
Mathematical
a = (3, −6), b = (−1, −6): a · b = −3 + 36 = 33. |a| = √45 ≈ 6.708, |b| = √37 ≈ 6.083. cos θ = 33 / 40.80 ≈ 0.8087, θ ≈ 36.0°.
Applied
A rover with heading vector h = (cos ψ, sin ψ) and a rock at relative position r computes h · r. Positive: the rock is ahead. Negative: behind. Its size is how far ahead, measured along the heading. No trigonometry needed in the loop.
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.
Worked example 1
Is the target at r = (−2, 5) ahead of or behind a robot facing h = (0.6, −0.8)?
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).
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.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Write a function is_ahead(heading_deg, rx, ry) that returns True when a point at (rx, ry) relative to a robot is in front of it, using only a dot product. Test it with a heading of 90° and points (0, 3), (2, −1) and (−4, 0.5).
Reflect
The dot product doesn't change when you rotate both vectors together. Why is that a useful property for a robot whose sensors spin with it?
Write your answer on paper or in your own notes. Lite never stores what you write.
Go further
- Dot product (Wikipedia)
Both definitions, their equivalence and many applications.