Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 39 · Vectors and Curves in Space

Vectors in Space and the Dot Product

Work with vectors in three-dimensional space: length, unit vectors, the dot product, angles and projections, with worked examples and Python code.

A vector is a quantity with both a magnitude and a direction, such as a velocity or a force. In three-dimensional space we write a vector with three components, v = ⟨v₁, v₂, v₃⟩. Vectors are the language of multivariable calculus: derivatives of curves are vectors, gradients are vectors, and fields assign a vector to each point.

Basics: components, length, unit vectors

A point P(x, y, z) has a position vector ⟨x, y, z⟩ from the origin. The vector from A(a₁, a₂, a₃) to B(b₁, b₂, b₃) is ⟨b₁ - a₁, b₂ - a₂, b₃ - a₃⟩.

Operations work component by component:

Text
⟨1, 2, 3⟩ + ⟨4, 0, -1⟩ = ⟨5, 2, 2⟩
3·⟨1, 2, 3⟩ = ⟨3, 6, 9⟩

The length (or magnitude, or norm) is |v| = √(v₁² + v₂² + v₃²). A unit vector has length 1; to get the unit vector in the direction of v, divide by its length: v̂ = v / |v|.

Worked example: v = ⟨2, -3, 6⟩. Then |v| = √(4 + 9 + 36) = √49 = 7, and v̂ = ⟨2/7, -3/7, 6/7⟩.

The standard basis vectors are i = ⟨1, 0, 0⟩, j = ⟨0, 1, 0⟩, k = ⟨0, 0, 1⟩, so ⟨2, -3, 6⟩ = 2i - 3j + 6k.

Python Length and unit vector

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The dot product

The dot product of a = ⟨a₁, a₂, a₃⟩ and b = ⟨b₁, b₂, b₃⟩ is a number:

Text
a · b = a₁b₁ + a₂b₂ + a₃b₃ = |a| |b| cos θ

where θ (between 0 and π) is the angle between the vectors when they start at the same point. The two formulas agree, and together they let you compute angles:

Text
cos θ = (a · b) / (|a| |b|)

Worked example: a = ⟨1, 2, 2⟩, b = ⟨2, 0, -1⟩. Then a · b = 2 + 0 - 2 = 0. The vectors are perpendicular (orthogonal), because cos θ = 0.

Another: a = ⟨1, 1, 0⟩, b = ⟨0, 1, 1⟩. Then a · b = 1, |a| = |b| = √2, so cos θ = 1/2 and θ = 60°.

Key facts:

  • a · b = 0 exactly when a ⟂ b (for nonzero vectors).
  • a · a = |a|².
  • a · b = b · a, and a · (b + c) = a · b + a · c.
  • If a · b > 0 the angle is acute; if a · b < 0 it is obtuse.
Python Angle between two vectors

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Projections

The scalar projection of b onto a is the signed length of the shadow of b along a:

Text
comp_a b = (a · b) / |a|

The vector projection is that length times the unit vector of a:

Text
proj_a b = ((a · b) / (a · a)) a

Worked example: a = ⟨3, 0, 4⟩, b = ⟨1, 2, 3⟩. a · b = 3 + 0 + 12 = 15, a · a = 25. So proj_a b = (15/25)⟨3, 0, 4⟩ = ⟨1.8, 0, 2.4⟩. The leftover b - proj_a b = ⟨-0.8, 2, 0.6⟩ is orthogonal to a; check: 3(-0.8) + 0 + 4(0.6) = 0.

Python Decompose a vector into parallel and perpendicular parts

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Dot product at a glance

Result is a number Not a vector
Gives the angle cos θ = a·b / |a||b|
Zero means right angle
1 / 2

Direction angles

The angles α, β, γ a vector makes with the x, y and z axes are its direction angles. Their cosines are v₁/|v|, v₂/|v|, v₃/|v|, the components of the unit vector, so cos²α + cos²β + cos²γ = 1.

Application: work

If a constant force F moves an object through a displacement d, the work done is W = F · d. With F = ⟨2, 1, 3⟩ N and d = ⟨4, 0, 5⟩ m, W = 8 + 0 + 15 = 23 J. Only the part of the force along the motion counts.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. What is the length of ⟨1, 2, 2⟩?

    √(1 + 4 + 4) = √9 = 3.
  2. 2. For a = ⟨1, 2, 3⟩ and b = ⟨4, -5, 2⟩, a · b equals

    4 - 10 + 6 = 0, so the vectors are perpendicular.
  3. 3. If a · b < 0, the angle between a and b is

    a · b = |a||b|cos θ, and cos θ < 0 exactly when θ is between 90° and 180°.
  4. 4. The vector projection of b onto a is

    Scaling a by (a·b)/(a·a) gives the part of b along a.

Summary

  • A 3D vector has components ⟨v₁, v₂, v₃⟩; its length is √(v₁² + v₂² + v₃²).
  • The dot product a · b = Σ aᵢbᵢ = |a||b|cos θ is a number that measures alignment.
  • It gives angles, tests perpendicularity and computes projections and work.

Next: The Cross Product