Concept 01: Vectors, Displacements & Scalar Scaling
▶ Interactive Demo: Vector Addition & Scaling Sandbox
Open the interactive demo below to drag vector arrows A and B, adjust the scalar multiplier slider, and see head-to-tail vector addition live.
1. The Real-World Problem: Combining Robot Moves
Suppose an autonomous robot performs two sequential driving steps:
- Move A: Drive 2 meters East and 1 meter North (
[2.0, 1.0]). - Move B: Drive 1 meter East and 2 meters North (
[1.0, 2.0]).
Where does the robot end up overall? You simply place the tail of Move B at the tip of Move A (Head-to-Tail addition). The net result is:
- Total X =
2.0 + 1.0 = 3.0 meters - Total Y =
1.0 + 2.0 = 3.0 meters
2. Solving It in Code (Java & WPILib)
First-Principles Java
Vector addition and scalar scaling:
// Robot starting velocity vector (vx, vy)
double v1x = 2.0;
double v1y = 1.0;
// Acceleration boost vector
double ax = 1.5;
double ay = 2.0;
double dt = 0.5; // half second
// v_new = v1 + a * dt
double vNewX = v1x + ax * dt; // 2.0 + 0.75 = 2.75 m/s
double vNewY = v1y + ay * dt; // 1.0 + 1.00 = 2.00 m/s
System.out.printf("New Velocity: (%.2f, %.2f) m/s%n", vNewX, vNewY);
Production WPILib Equivalent
In WPILib, Translation2d supports vector arithmetic:
import edu.wpi.first.math.geometry.Translation2d;
Translation2d velocity = new Translation2d(2.0, 1.0);
Translation2d acceleration = new Translation2d(1.5, 2.0);
Translation2d newVelocity = velocity.plus(acceleration.times(0.5));
3. Bridge to Machine Learning: Word Embeddings
In natural language processing AI (like Word2Vec and ChatGPT):
- Every word is represented as a list of numbers (a vector in 1536-dimensional space).
- Because concepts are vectors, the AI can perform vector arithmetic on meanings:
Vector("King") - Vector("Man") + Vector("Woman") ≈ Vector("Queen")
4. Review Checkpoints
Checkpoint 1
You have vector A = [4.0, -2.0] and vector B = [-1.0, 5.0].
Compute A + B.
Solution:
[4.0 + (-1.0), -2.0 + 5.0] = [3.0, 3.0].
Checkpoint 2
A robot’s velocity vector is v = [2.0, 4.0] m/s. The driver hits the “Turbo” button, scaling velocity by 1.5x. What is the new velocity vector?
Solution:
v_turbo = [2.0 · 1.5, 4.0 · 1.5] = [3.0, 6.0] m/s.