Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Vectors and Geometry  ›  Lesson

Length, Direction and the Dot Product

Linear Algebra 15 minA vector's length comes from Pythagoras, dividing by that length gives a unit direction, and the sign of a dot product says whether something is ahead, beside or behind.

Length, Direction and the Dot Product

A gull swoops toward the drone. Should the warning light flash? Only if the gull is in front, where the pilot has no time to dodge. "In front of" sounds like a job for angles and trigonometry, but games answer it with two multiplications and an addition: the dot product.

The rule

Dot product sign: positive ahead, zero beside, negative behind.

Three tools, in the order you'll reach for them.

Length. An arrow's length, its magnitude, comes from Pythagoras: ∥v∥=x2+y2\lVert \mathbf{v} \rVert = \sqrt{x^2 + y^2}. The arrow from the drone to the crate, (6,−8)(6, -8), is 36+64=10\sqrt{36 + 64} = 10 m long. The distance between two points is the length of the arrow between them.

Direction. Divide an arrow by its own length and you get a unit vector: length 1, pointing the same way. (6,−8)/10=(0.6,−0.8)(6, -8) / 10 = (0.6, -0.8). A unit vector separates which way from how far. To fly toward the crate at 5 m/s, the velocity is 5×(0.6,−0.8)=(3,−4)5 \times (0.6, -0.8) = (3, -4).

Dot product. Multiply matching components and add: a⋅b=axbx+ayby\mathbf{a} \cdot \mathbf{b} = a_x b_x + a_y b_y. For two unit vectors, the result is the cosine of the angle between them: 1 when they point the same way, 0 at right angles, −1 when they point opposite ways. For any two arrows, the sign alone says ahead, beside or behind.

The shortcut

"Is it in front?" needs no angles and no square roots: dot the facing direction with (target − self) and read the sign. Only for a cone, such as a camera's view, do you normalise both arrows and compare with a cosine: a target is inside a cone of half-angle θ\theta when the dot of the two unit vectors is at least cos⁡θ\cos\theta.

Is the boat inside the drone camera's view?Step 1 of 4
  1. Facing and offset

    The drone at (2, 11) faces (0.6, −0.8), down and to the right. The boat at (14, 2) sits at offset (14 − 2, 2 − 11) = (12, −9).

Two traps. Comparing a dot of un-normalised arrows with a cosine gives nonsense, because the lengths inflate the result. And for "is it within 10 m?" skip the square root entirely: compare the squared length with 102=10010^2 = 100.

Drills

Answer fast — trust the rule.

How long is the arrow (5, −12)?
52+122= ?\sqrt{5^{2} + 12^{2}} = \,?
quick drill

What is the unit vector of (0, −4)?

The drone faces (1, 0). A gull sits at offset (−3, 2) from it. What is the dot product?
1×(−3)+0×2= ?1 \times (-3) + 0 \times 2 = \,?
quick drill

Two unit vectors have a dot product of 0. How do they point?

quick drill

For offset (dx, dy), which test correctly says "the crate is within 10 m" without a square root?

Remember

  • Length is Pythagoras; divide by it to get a unit direction.
  • Dot the facing with (target − self): positive ahead, zero beside, negative behind.
  • For cones, normalise both and compare with the cosine; for distances, compare squares.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainCamera cone check

The drone faces (0.6, −0.8) and a boat sits at offset (12, −9) from it. Explain, with the numbers, how the game decides whether the boat is inside a camera cone with a half-angle of 60°.