Loading editor...

10. Dot product

A Bezier curve is nothing but a weighted sum of its anchor points, where the weights are the basis polynomials (for degree two) that are non-negative and add up to 1 for every .

In this chapter we study one of the most important operations in linear algebra - the dot product. It takes two vectors and returns a single number, and hidden inside that number is both the geometry of angles and the mechanics of matrix-vector multiplication.


10.1 Getting started: definition and obvious properties

A dot product is a function of two vectors of the same dimensionality. Its output is a single scalar number, defined as:

It can also be seen as a matrix multiplication of a row vector with a column vector:

The dot product of two vectors p and q is usually denoted by the expression .

10.1.1 Properties

  • It is commutative: . This is easy to see, since .
  • It is linear. This gives us where c is a real number, and .
  • Combining commutativity and linearity, it is bilinear. For vectors p, q, r, s we can expand a dot product of sums term by term: .

10.2 Viewing trigonometry through the lens of linear algebra

Recall that the norm (or L2-norm) of a vector is basically how long the vector is, denoted by the notation . In other words, . Thus, scaling a vector by c scales its length by c as well. Also recall that a unit vector is just a vector whose norm is 1.

Now note that the dot product of a vector with itself is equal to the squared length of that vector:

This lets us express any vector as a scaled version of a unit vector: where is a vector in the same direction as but with length 1.

This naive-looking formula is quite powerful! It reduces a vector of any length to a single number related to its length, which lets us view trigonometric problems through the lens of linear algebra. Let's look at an example.


Consider a triangle with sides a, b, c such that the sides a, b have length 1 and the angle between them is . Here and are two unit vectors sitting on the unit circle, and , joins the tip of b to the tip of a. Its length is exactly the length of side c. Applying the law of cosines and viewing lengths as norms gives us:

In general, if and are two vectors of the same dimensionality with angle between them, we can pull the norms out using bilinearity:

where are the unit vectors corresponding to and . In other words, the dot product of two vectors is the product of their lengths times the cosine of the angle between them - and for unit vectors it is just the cosine of that angle.

This property is not limited to 2D. The proof above only used the law of cosines and the algebraic properties of the dot product (commutativity, bilinearity), so it holds for vectors of any dimension. See the Law of cosines for details.


10.3 When is the dot product zero?

Since , the sign of the dot product is the sign of :

  • The dot product is zero exactly when the two vectors are perpendicular (). This holds in any dimension, not just 2D.
  • It is positive when the angle between them is less than 90°, and negative when it is greater than 90°.

Let's see this for two 2-dimensional unit vectors A and B. We keep A fixed along the x-axis and rotate B:

Here points along the x-axis and starts at 60°. The readout shows their dot product , which equals since both are unit vectors.

  • and watch the dot product shrink - it passes through zero the moment B becomes perpendicular to A, then turns negative as the angle exceeds 90°.
  • and the dot product climbs back up toward 1 (the maximum, reached when the vectors point the same way).

10.4 Dot product as a projection

Given vectors p and q, one often wants the vector obtained by projecting p onto q. This is shown in the figure below.

We start with and .

Dropping p perpendicularly onto the line of q gives , shown in gold.

  • This projected vector has the same direction as q.
  • Its length is the length of p times the cosine of the angle between p and q, which works out to . So the projection vector itself is:

where is the unit vector in the direction of .

The last expression can be re-written even more elegantly as

where is the transpose of . We will study exactly what this means in the next chapter.


10.5 Dot product in matrix-vector multiplication

You may or may not have realized it, but the dot product can be found lurking inside any weighted sum, aka matrix-vector multiplication. Let's take a simple example:

Suddenly the row of a matrix becomes relevant! So far we have only been looking at a matrix as an array of column vectors. Seeing each entry of the output as a dot product between a row of the matrix and the input vector gives us yet another perspective on matrix-vector multiplication. We will explore this row-based view in detail next.

In the next chapter we will study the matrix transpose - the operation that turns rows into columns and columns into rows - and see how it makes the projection formula above fall out cleanly.


← 9. Bezier curves · 11. Matrix transpose →