Guides / Linear algebra

Vectors in 3-D: the dot product for angles, the cross product for normals, and |n| in every distance

Two products do the geometry of three dimensions. The dot product turns two vectors into a number that measures how much they point the same way, which gives angles, projections and perpendicularity. The cross product turns two vectors into a third one perpendicular to both, which gives areas and the normal of a plane. With a point and a normal, a plane is one equation, and the distance from any point to it is one dot product divided by one length. The mistakes come from the middle sign of the cross product, from dividing a projection by the wrong power of the length, and from forgetting that length in the distance.

Short answer

Dot product: u · v = u1v1 + u2v2 + u3v3 = |u| |v| cos θ; zero means perpendicular. Projection of u onto v: ((u · v)/(v · v)) v. Cross product: u × v = (u2v3 − u3v2, u3v1 − u1v3, u1v2 − u2v1), perpendicular to both, with length equal to the area of the parallelogram on u and v. Plane through P with normal n: n · (x − P) = 0. Distance from Q to the plane n · x = d: |n · Q − d|/|n|.

Why it works

The law of cosines applied to the triangle with sides u, v and u − v gives |u − v|2 = |u|2 + |v|2 − 2|u||v| cos θ. Expanding the left side as (u − v) · (u − v) gives the same thing with 2 u · v in place of the cosine term, so u · v = |u||v| cos θ. The projection follows: the part of u along the unit vector v/|v| has length (u · v)/|v|, and multiplying that length by the unit vector v/|v| divides by |v| a second time.

The cross product is defined so that dotting it with u or v gives a determinant with a repeated row, which is zero; that is why it is perpendicular to both. Its length is |u||v| sin θ, base times height. A plane is every point x for which x − P is perpendicular to the normal, which is the equation n · (x − P) = 0. For the distance, n · Q − d measures how far Q is off the plane in units of |n|, so dividing by |n| turns it into a length.

Example 1: an angle and a projection

For u = (2, 1, −2) and v = (1, 1, 0), find the angle between them and the projection of u onto v.

  1. u · v = 2 + 1 + 0 = 3Multiply matching entries and add.
  2. |u| = √9 = 3, |v| = √2The length is the square root of the dot product of a vector with itself.
  3. cos θ = 3/(3√2) = 1/√2, θ = 45°The cosine must land between −1 and 1; a value outside that range means a slip in the lengths.
  4. proj = (3/2)v = (1.5, 1.5, 0)u · v divided by v · v = 2, times v.
  5. u − proj = (0.5, −0.5, −2)Check: its dot product with v is 0.5 − 0.5 + 0 = 0, so what is left over is perpendicular to v, as it should be. The projection has length 3/√2 ≈ 2.121, which is |u| cos θ.

Example 2: a cross product and an area

For a = (1, 2, 0) and b = (3, −1, 2), find a × b and the area of the parallelogram they span.

  1. first: 2 · 2 − 0 · (−1) = 4a2b3 − a3b2: cover the first column and take the 2×2 determinant of what is left.
  2. second: 0 · 3 − 1 · 2 = −2a3b1 − a1b3: the order wraps around, which is the same as negating the covered-column determinant.
  3. third: 1 · (−1) − 2 · 3 = −7a1b2 − a2b1.
  4. a × b = (4, −2, −7)Check: a · (4, −2, −7) = 4 − 4 + 0 = 0 and b · (4, −2, −7) = 12 + 2 − 14 = 0.
  5. area = √69 ≈ 8.307The length of the cross product, √(16 + 4 + 49). The triangle on a and b has half that area, about 4.153.

Example 3: the plane through three points

Find the equation of the plane through P(1, 0, 2), Q(2, 1, 2) and R(1, 2, 3).

  1. Q − P = (1, 1, 0)An edge vector lying in the plane.
  2. R − P = (0, 2, 1)A second one, not parallel to the first.
  3. n = (1, −1, 2)The cross product of the two edges, (1 − 0, 0 − 1, 2 − 0), is perpendicular to both, so it is normal to the plane.
  4. (x − 1) − y + 2(z − 2) = 0n · (x − P) = 0, using a point that is on the plane.
  5. x − y + 2z = 5Check all three points: 1 − 0 + 4, 2 − 1 + 4 and 1 − 2 + 6 all equal 5.

Example 4: the distance from a point to a plane

Find the distance from Q(3, 1, 4) to the plane x − y + 2z = 5, and the point of the plane nearest to Q.

  1. n · Q − 5 = 3 − 1 + 8 − 5 = 5Plug Q into the left side and subtract the right side; the sign says which side of the plane Q is on.
  2. |n| = √(1 + 1 + 4) = √6The length of the normal vector.
  3. distance = 5/√6 ≈ 2.041Dividing by |n| turns the value of the equation into a length.
  4. Q − (5/6)nWalk from Q along the normal. The step is (n · Q − 5)/(n · n) = 5/6 copies of n.
  5. (13/6, 11/6, 7/3)Check: 13/6 − 11/6 + 14/3 = 5, so the point is on the plane, and its distance from Q is (5/6)√6 = 5/√6.

Common mistakes, and the exact line they happen on

1. The middle sign of the cross product

The second entry of a × b in Example 2.

  1. first entry: 4Right so far.
  2. second: 1 · 2 − 0 · 3 = 2This is the mistake. Writing a1b3 − a3b1 keeps the indices in order but flips the sign of the middle entry. The result (4, 2, −7) fails the check at once: its dot product with a is 4 + 4 = 8, not 0. The right entry is −2.

2. Dividing the projection by |v| instead of v · v

The projection of Example 1.

  1. u · v = 3, |v| = √2Right so far.
  2. proj = (3/√2)(1, 1, 0)This is the mistake. 3/√2 is the length of the projection, the component; multiplying it by v instead of by the unit vector v/|v| stretches the result by |v|. This vector has length 3, the length of u itself, and u minus it is not perpendicular to v. The right projection is (3/2)(1, 1, 0).

3. The distance without dividing by |n|

The distance of Example 4.

  1. n · Q − 5 = 5Right so far.
  2. distance = 5This is the mistake. The plane 2x − 2y + 4z = 10 is the same plane, but the same point would then give 10. A distance can't depend on how the equation is scaled, so it has to be divided by |n|. The right distance is 5/√6 ≈ 2.041.

Practice

  1. Find the angle between (1, −2, 2) and (2, 2, 1).

    Show answer

    The dot product is 2 − 4 + 2 = 0, so the vectors are perpendicular: 90°.

  2. Find the volume of the parallelepiped on (1, 0, 0), (0, 2, 0) and (1, 1, 3).

    Show answer

    The volume is |a · (b × c)|, the absolute value of the determinant with those rows. b × c = (6, 0, −2) and a · (b × c) = 6, so the volume is 6.

  3. Find the plane through (1, 2, 3) with normal (2, −1, 1).

    Show answer

    2x − y + z = 2 − 2 + 3 = 3.

  4. Find the distance from the origin to the plane 2x + y − 2z = 6.

    Show answer

    |0 − 6|/√(4 + 1 + 4) = 6/3 = 2.

  5. Where does the line (1, 1, 1) + t(1, 2, −1) meet the plane x + y + z = 7?

    Show answer

    Substituting gives 3 + 2t = 7, so t = 2 and the point is (3, 5, −1). Check: 3 + 5 − 1 = 7.