The angle between vectors

The dot product (also called the scalar product) gives us the angle between any two vectors. It's one of the most important relationships between vectors. In this section we'll define the dot product and show how it gives the angle between vectors for two- and three-dimensional vectors.

The dot product gives the angle between two vectors of any dimension. It's a tricky concept, but it's true. You can calculate the angle between 27-dimensional vectors.

Here's the definition of the dot product for two-dimensional vectors like v1 = (x1, y1):

Notice the the result of the dot product is not another vector – it's just another number or a scalar. That's why we often call the dot product the scalar product. We can easily extend the definition of the dot product to vectors of any dimension, as long as the two have the same dimension.

Finally, the dot product can be thought of as a row vector (or a 1 × n matrix) multiplied by a column vector (an n × 1 matrix). Here's a picture of that for 2-D vectors:

The dot product is defined only for vectors of the same dimension.

Practice problems

Calculate the dot product of these vectors. Roll over or tap each problem for the solution.

You can think of matrix multiplication like taking lots of dot products

If matrix multiplication gets the best of you, it might help to think of it like taking a bunch of dot products, row vectors from the left matrix with column vectors with the right-hand matrix. Here's a 3-D matrix multiplication problem:

We'll think of the matrix on the left as a vertical list of row vectors (a column vector of row vectors ... but that's confusing), called a, b and c. The matrix on the right is a horizontal list of column vectors, x, y and z.

Now if we multiply the two matrices, we're just taking a series of dot products like this:

Now take a look at that matrix. The element in the second row, second column is just the dot product of the second row vector, b, and the second column vector, y. It's the same for each element in the result matrix. Here is the expanded result:

The connection between the dot product and the angle between vectors

Consider two vectors, a and b. Here they are:

The first thing we'll do is to translate them to the origin to make things easier. Remember that we can always do this because the only things about vectors that are important are their length and direction.

Now if we remember vector subtraction, we can construct the vector a - b. Let's also draw in angle θ between a and b:

We begin with the law of cosines, where |v1| is the length of vector v1, |v2| is the length of vector v2, and so on:

Now let's take a look at that left side, |v1 - v2|2. We can use the coordinates of the endpoints of v1 and v2, which are the coordinates of both ends of v1 = v2 to get

We're just using the distance formula with those coordinates. Now on the right we have the square of a square root, so the left side is just

Now for the right side of our original equation. If we remember that the square of the length of a vector is

we get

So we have |v1|2 = x12 + y12 and |v2|2 = x22 + y22. Now we can rewrite both sides, and expand the binomials on the left to get:

Notice that the squared terms containing purely x's or y's are represented on both sides of the equation, so we can eliminate them:

Finally, all of those -2's can be divided away

to give

Now all that remains is to recognize that x1x2 + y1y2 is just the definition of the dot product, so we've arrived at the relationship between the dot product of two vectors and the angle between them:

Using the dot product – some examples

Example 1

Find the angle between vectors v1 = (-1, 2) and v2 = (2, 5)

Solution: We begin by writing the dot-product equation and rearranging it to find the angle:

Solving for the angle, we get

Now we just have to fill in the information. The dot product is the product of the x-coordinates plus the product of the y's:

The lengths of the vectors are found using the distance formula:

And finally the angle:

Example 2

Find a vector of length 1 that is perpendicular to (1, 0, 1).

Solution: This kind of problem will have two main steps. First we'll find one vector that is perpendicular to (1, 0, 1), but we'll have to remember that there are an infinite number of such vectors – all of different length. The second step will be to adjust the length of that vector to one – to make it a unit vector. Here's a picture of this 3-dimensional vector, which lives in the x-z plane:

Recall that the angle between perpendicular vectors (one known and one unknown in this case) has to be 90˚, and that the cosine of 90˚ is zero, so we'll start there:

We can get rid of the denominator because for this expression to equal zero, all that is required is that the dot product be zero:

Now the dot product between v = (1, 0, 1) and an unknown vector (x, y, z) of the same dimension is:

So all that is required of this vector is that y = 0 and x = -z.

The vectors (3, 0, -3) and (4.5, 0, 4.5) would work just as well. They differ only in length, but they're perpendicular to (1, 0, 1). What we need to do now is to adjust the length of (1, 0, 1) to 1. First we need to find its current length:

Now to adjust the length we just divide each component of our vector by that length. You can check for yourself that the length of this new vector is 1.

The process of adjusting the length of a vector to 1, or making it a unit vector, is called normalization.

Finally, if (a, 0, -a) is perpendicular to (1, 0, 1), then so is (-a, 0, a). It also satisfies the requirement that x = -z, it just points in the opposite direction.

The diagram above shows our two vectors. They lie in the x-z plane. Notice that there are many other vectors perpendicular to (1, 0, 1) outside of that plane.

Normalization of a vector

To normalize a vector (set its length to one), calculate the length of the vector, then divide each component of the vector by that length.

Example 3

Find a vector of length 1 orthogonal to vectors v1 = (1, -1, 2) and v2 = (-1, 2, 2)

Solution: First, the word orthogonal replaces perpendicular when we're working in dimensions higher than three, and it's often used with three. It means the same thing: the angle between orthogonal vectors is 90˚, but we use a different word because it's difficult to visualize a 90˚ angle in higher dimensions.

Our vectors are

Here's a 3-D plot of these. The difference between this example and the last is that these vectors don't lie in one of the coordinate planes, so we'll have to approach finding orthogonal vectors differently.

Any two vectors can define a plane, as ours do. We seek a vector that's orthogonal to both, so we can write these two dot products:


If we add those two equations we can eliminate a to find a relationship between b and c

Now we have b = -4c, and we can plug that into either dot-product result to find a = -6c.

If we let c = 1, we have one of many versions of our desired vector, differing in length.

Notice that there are actually two vectors perpendicular to both v1 and v2, the negatives of each other.

Now we need to normalize our vectors, first by finding the length:

... then by dividing by that length to find two vectors in the same directions, but of length 1:

Finally, here is our picture again with the two orthogonal unit vectors sketched in.

Practice problems

For each problem calculate the unit vector orthogonal to each of the vectors given

1. (2, -3)

2. (1, 1, -1) and (1, -1, 1)

3. (1, 2, -1) and (-1, -1, 0)

4. (2, -2, 1) and (1, 0, 0)

5. (1, -1, -2, 1), (2, 3, 4, 1) & (-2, -1, 1, 2)

6. (2, 1, -2, -1), (1, 1, -1, 2) & (0, 1, 0, 1)

You can help

This site is a one-person operation and a labor of love. If you can manage it, I'd appreciate anything you could give to help defray the cost of keeping up the domain name, server, search service and my time.

Creative Commons License   optimized for firefox by Dr. Jeff Cruzan is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. © 2012, Jeff Cruzan. All text and images on this website not specifically attributed to another source were created by me and I reserve all rights as to their use. Any opinions expressed on this website are entirely mine, and do not necessarily reflect the views of any of my employers. Please feel free to send any questions or comments to