A Mission Directed by Math: How the Dot Product Guides Autonomous Systems
The Intuition: Why the Dot Product is a Geometric Shortcut
Before we see the dot product as just a formula, let’s build the intuition for why it works. How can a simple calculation like \((v_x AB_x) + (v_y AB_y)\) tell us about the angle between two vectors?
The secret is a concept called projection.
Imagine shining a flashlight from directly above vector \(\vec{B}\) down onto the line of vector \(\vec{A}\). The shadow that \(\vec{B}\) casts on \(\vec{A}\) is its projection. This projection forms a right-angled triangle.
Using SOH CAH TOA, we can see that the length of this shadow is \(\|\vec{B}\| \cos(\theta)\).
Geometrically, the dot product is defined as the length of the first vector multiplied by the length of the second vector’s shadow projected onto it: \(\vec{A} \cdot \vec{B} = \|\vec{A}\| \times (\|\vec{B}\| \cos(\theta))\)
The Proof: Connecting Geometry and Algebra
The “magic” is proving that the geometric definition above is always equal to the simple algebraic calculation.
But why care about projecting? Because geometry is the bedrock. It enforces the laws that govern how angles and dimensions are interdependent. By projecting vectors, we create triangles, which allows us to apply these well-established geometric rules to understand the relationship between the vectors.
Step 1: Express Vectors using Trigonometry
Let’s take two vectors, \(\vec{A}\) and \(\vec{B}\), on a 2D plane. We can express their components using trigonometry, where \(\theta_A\) and \(\theta_B\) are the angles each vector makes with the positive x-axis.
- Vector A: \((A_x, A_y) = (\|\vec{A}\|\cos(\theta_A), \|\vec{A}\|\sin(\theta_A))\)
- Vector B: \((B_x, B_y) = (\|\vec{B}\|\cos(\theta_B), \|\vec{B}\|\sin(\theta_B))\)
Step 2: Use the Algebraic Formula
Now, let’s plug these component definitions into the algebraic formula for the dot product. \(\vec{A} \cdot \vec{B} = A_x B_x + A_y B_y\) \(\vec{A} \cdot \vec{B} = (\|\vec{A}\|\cos\theta_A)(\|\vec{B}\|\cos\theta_B) + (\|\vec{A}\|\sin\theta_A)(\|\vec{B}\|\sin\theta_B)\)
Step 3: Simplify and Use a Trigonometric Identity
Let’s factor out the lengths, \(\|\vec{A}\|\) and \(\|\vec{B}\|\).
\(\vec{A} \cdot \vec{B} = \|\vec{A}\|\|\vec{B}\| (\cos\theta_A\cos\theta_B + \sin\theta_A\sin\theta_B)\) We can now recognize the term in the parentheses as the trigonometric identity for the cosine of a difference of angles: \(\cos(\theta_A - \theta_B) = \cos\theta_A\cos\theta_B + \sin\theta_A\sin\theta_B\)
Note: For a great resource that helped me get comfortable with these concepts, see this guide on deriving trigonometric identities.
Step 4: The Final Connection
The angle \(\theta\) between the two vectors is simply the difference between their individual angles: \(\theta = \theta_A - \theta_B\). Substituting this back into our equation gives us the geometric formula: \(\vec{A} \cdot \vec{B} = \|\vec{A}\|\|\vec{B}\|\cos(\theta)\)
This proves that the simple algebraic calculation is just a clever way of using trigonometric identities to arrive at the same result as the geometric projection.
Application
Let’s get right to it. In physics, a vector is a powerful tool used to describe something with both magnitude (a size or value) and direction.
An example is a rocket travelling with a velocity vector, \(\vec{v}\), with components like \((v_x,v_y,v_z)\) in m/s.
The signed values of the components give us the direction. A positive value means one direction (e.g., forward or up), and a negative value means the opposite.
The total speed of the rocket is the magnitude of this vector, calculated using the Pythagorean theorem:
\[\|\vec{v}\| = \sqrt{v_x^2 + v_y^2 + v_z^2}\]The Mission & The Challenge
The objective of our mission is to reach Planet LXS. Our rocket is equipped with an autonomous pilot, and the destination is located at a specific point in space, let’s call it \(B\).
Here’s the challenge: How does the rocket’s autonomous pilot know if it’s on the correct path? After dodging some space debris, the rocket might not be pointing toward B anymore. How can the autopilot perform a quick sanity check to ensure it’s still heading in the right direction?
The Solution - The Power of the Dot Product
Our rocket’s current position is \(A = [2,5,0]\), and its destination is \(B=[8,11,0]\). Due to a quick maneuver, its velocity vector is currently \(\vec{v} = [-0.5,0.8,0]\).
Our first step is to find the vector for the path the rocket should be taking. We do this by subtracting the initial position from the destination:
\[\vec{AB} = \vec{B} - \vec{A} = [8-2,11-5,0-0] = [6,6,0]\]Before we get to the dot product, let’s try an intuitive approach.
A natural thought is to use trigonometry to find the angle between them. This would involve visualizing each vector’s components as sides of a right-angled triangle. We’d compute the angles and the contributions along each component. For instance, we might think of the contributions from each axis as:
x-contribution: \(v_x \cdot AB_x\) y-contribution: \(v_y \cdot AB_y\) z-contribution: \(v_z \cdot AB_z\)
To find the angle between two vectors using a purely trigonometric approach, we would first find the angle each vector makes with a reference axis (like the x-axis).
Calculate the magnitude (norm) of each vector:
\[\|\vec{v}\| = \sqrt{(-0.5)^2 + (0.8)^2 + (0)^2} = \sqrt{0.25 + 0.64} = \sqrt{0.89} \approx 0.943\] \[\|\vec{AB}\| = \sqrt{(6)^2 + (6)^2 + (0)^2} = \sqrt{36 + 36} = \sqrt{72} \approx 8.485\]Calculate the angle each vector makes with the positive x-axis using arccos (or atan2 for full quadrant awareness):
Angle of \(\vec{v}\) (let’s call it \(\theta_v\)): \(\arccos(\frac{-0.5}{0.943}) \approx 122.0^\circ\)
Angle of \(\vec{AB}\) (let’s call it \(\theta_{AB}\)): \(\arccos(\frac{6}{8.485}) \approx 45.0^\circ\)
Find the angle between the two vectors by subtracting their individual angles:
Angle between \(\vec{v}\) and \(\vec{AB}\) (\(\theta_{v,AB}\))
\[|122.0^\circ - 45.0^\circ| = 77.0^\circ\]This approach, while intuitive, can become a long, multi-step process involving calculating individual angles and projections.
But this is where the genius of the dot product comes in. The dot product encapsulates all that trigonometry into a single, elegant calculation. It’s the mathematical shortcut that gives us the information we need. The calculation is straightforward: we multiply the corresponding components and add them up.
For our vectors, the dot product is:
\[\vec{v} \cdot \vec{AB} = (-0.5 \cdot 6) + (0.8 \cdot 6) + (0 \cdot 0) = -3.0 + 4.8 + 0 = 1.8\]The result is a single scalar number, 1.8 and tells us something powerful. A positive result means we are moving in the right direction, and a negative means we are moving in the wrong direction. This is good, but to get an even more intuitive sense of alignment, we can normalize this dot product. This means we divide the dot product by the product of the magnitudes of the two vectors:
\[\text{Normalized Dot Product} = \frac{\vec{v} \cdot \vec{AB}}{\|\vec{v}\| \|\vec{AB}\|} = \frac{1.8}{(0.943)(8.485)} = \frac{1.8}{7.993} \approx 0.225\]This normalized value, which is the cosine of the angle between the vectors, gives us a standardized measure of alignment between -1 and 1.
Well, Can you hear the music?
That positive result tells the rocket’s control system it’s on the right track!
The normalized dot product gives us a metric that ranges from -1 to 1, regardless of the vectors’ magnitudes. This gives us a standardized measure of alignment.
-
A value of 1 means the velocity is perfectly aligned with the destination (the angle is 0°).
-
A value of 0 means the rocket is moving perpendicular to the destination (the angle is 90°), making no progress.
-
A value of -1 means the rocket is moving in the exact opposite direction (the angle is 180°), moving farther away.
The control system’s goal is to constantly adjust its thrusters to make this normalized value as close to 1 as possible. This simple, elegant piece of math is what allows an autonomous system to course-correct and safely reach its destination. It gives us a tangible, standardized metric for a robot’s alignment.