Find a course

Module 1: Vectors and Linear SystemsLesson 2 of 1214 min

Dot Product, Angles and Projections

Use the dot product to find angles, test for perpendicular vectors and project one vector onto another, then meet the cross product in 3D.

Step 1 of 12Learn

Multiplying vectors to get a number

How similar are two movie fans? Rate five movies from −2 (hated it) to 2 (loved it). Ana's ratings are (2, 1, −1, 0, 2) and Ben's are (2, 2, −2, 1, 1). Multiply matching ratings and add:

2·2 + 1·2 + (−1)(−2) + 0·1 + 2·1 = 4 + 2 + 2 + 0 + 2 = 10.

That's the dot product: u·v = u₁v₁ + u₂v₂ + … + uₙvₙ. It turns two vectors into one number. Agreements (both positive or both negative) add to the total; disagreements subtract. Recommendation systems use exactly this kind of score.

The dot product has a geometric meaning that makes it far more useful:

u·v = |u||v| cos θ, where θ is the angle between the vectors.

So the sign of the dot product tells you about the angle:

  • u·v > 0: the angle is acute (less than 90°); the vectors point roughly the same way.
  • u·v = 0: the angle is exactly 90°; the vectors are orthogonal.
  • u·v < 0: the angle is obtuse; they point roughly opposite ways.

Two useful facts follow. A vector dotted with itself gives its length squared: v·v = |v|². And the dot product follows familiar algebra rules: u·v = v·u, and u·(v + w) = u·v + u·w.

Step 2 of 12Practice · Chart

Ana and Ben rate five movies

Where both bars point the same way, the product is positive and pushes the dot product up. They agree almost everywhere, so the dot product is large: 10.

Tap the movie whose product adds nothing to the dot product.

Tap the bar that answers the question, then press Check.

Ana and Ben rate five moviesBar chart with 5 categories: Movie 1: Ana 2, Ben 2; Movie 2: Ana 1, Ben 2; Movie 3: Ana -1, Ben -2; Movie 4: Ana 0, Ben 1; Movie 5: Ana 2, Ben 1.-2-1012Movie 1Movie 2Movie 3Movie 4Movie 52212-1-20121
Ana and Ben rate five movies
ItemAnaBen
Movie 122
Movie 212
Movie 3-1-2
Movie 401
Movie 521

Step 3 of 12Practice · Work it out

Compute the dot product of u = (3, −2, 5) and v = (4, 1, −2).

Step 4 of 12Learn

Finding angles

Rearranging u·v = |u||v| cos θ gives a formula for the angle between any two nonzero vectors:

cos θ = (u·v) / (|u||v|).

Example. Find the angle between u = (1, 2) and v = (3, 1).

  • u·v = 3 + 2 = 5
  • |u| = √5 and |v| = √10, so |u||v| = √50 ≈ 7.071
  • cos θ = 5/7.071 ≈ 0.707, so θ = 45°.

The formula works in any dimension. In 50 dimensions you can't draw the angle, but you can still compute it, and data scientists do this constantly. The quantity cos θ is called cosine similarity: it measures how closely two vectors point in the same direction, ignoring their lengths. Two documents described by word counts have cosine similarity near 1 if they use words in similar proportions, regardless of how long each document is.

For Ana and Ben, |Ana| = √10 ≈ 3.16 and |Ben| = √14 ≈ 3.74, so cos θ = 10/11.83 ≈ 0.85. They have quite similar tastes.

Because |cos θ| ≤ 1, the formula also proves the Cauchy–Schwarz inequality: |u·v| ≤ |u||v|. The dot product can never exceed the product of the lengths, and it equals that product only when the vectors are parallel.

Step 5 of 12Explore

u·v = |u||v| cos θ

The curve shows the dot product as the angle θ (degrees) between the vectors grows. It is positive under 90°, zero at exactly 90° and negative beyond.

-20-1001020 050100150
Dot product at 0° (same direction)
6
Dot product at 60°
3

Step 6 of 12Try the calculator

Angle between two vectors in the plane

Enter u = (u1, u2) and v = (v1, v2). The calculator computes the dot product, both lengths and the angle in degrees. Try making the dot product zero.

Dot product u·v
5
Length of u
2.2361
Length of v
3.1623
Angle
45 degrees

Step 7 of 12Practice · Choose one

For which value of k are (2, k, 1) and (3, −1, 4) orthogonal?

Step 8 of 12Learn

Projections: the shadow of a vector

Shine a light straight down onto the line through a vector v. The shadow that another vector u casts on that line is the projection of u onto v:

proj_v(u) = (u·v / v·v) · v.

The fraction u·v / v·v is a scalar; it tells you how many copies of v the shadow is. If you only want the shadow's signed length, use the scalar projection u·v / |v|.

Example. Project u = (4, 2) onto v = (3, 0), the x-axis direction. u·v = 12, v·v = 9, so proj = (12/9)(3, 0) = (4, 0). The shadow of (4, 2) on the x-axis is (4, 0), as you'd expect.

Example. Project u = (2, 3) onto v = (1, 1). u·v = 5, v·v = 2, so proj = 2.5(1, 1) = (2.5, 2.5).

The leftover part, u − proj_v(u), is orthogonal to v. In the second example, (2, 3) − (2.5, 2.5) = (−0.5, 0.5), and its dot product with (1, 1) is 0. So every vector splits into a piece along v and a piece perpendicular to v. Physicists use this to split a force into components along a ramp and against it.

Projections will return in the last lesson: least squares, the method behind linear regression, is projection onto a subspace.

Step 9 of 12Practice · Work it out

Project u = (6, 2) onto v = (1, 2). What is the first entry of proj_v(u)?

Step 10 of 12Tap to reveal

The cross product, for 3D only

  1. What it is

    For u and v in ℝ³, the cross product u × v is a vector, not a number: (u₂v₃ − u₃v₂, u₃v₁ − u₁v₃, u₁v₂ − u₂v₁). It exists only in three dimensions.

  2. Direction

    u × v is perpendicular to both u and v. The right-hand rule gives its direction: curl your fingers from u toward v, and your thumb points along u × v. Reversing the order flips it: v × u = −(u × v).

  3. Length

    |u × v| = |u||v| sin θ, which is the area of the parallelogram spanned by u and v. Parallel vectors have cross product zero.

  4. Example

    (1, 0, 0) × (0, 1, 0) = (0, 0, 1): the x-direction crossed with the y-direction gives the z-direction. Graphics engines compute surface normals for lighting this way.

Step 11 of 12Note

Step 12 of 12Practice · True or false

If u·v is negative, the angle between u and v is greater than 90°.