Find the Angle Between Two Vectors

If you are a mathematician or graphics programmer, you may need to find the angle between two given vectors. This article will show you how to do that.

10 Second Summary

1. Identify the vectors. More ↓
2. Write down the cosine formula.
3. Calculate the length of each vector.
4. Calculate the dot product of the two vectors.
5. Plug your results into the formula.
6. Find the angle based on the cosine.

Steps

Finding the Angle Between Two Vectors

  1. Identify the vectors. Write down all the information you have concerning the two vectors. We'll assume you only have the vector's definition in terms of its dimensional coordinates (also called components).[1] If you already know a vector's length (its magnitude), you'll be able to skip some of the steps below.
    • Example: The two-dimensional vector <math>\overrightarrow{u}</math> = (2,2). Vector <math>\overrightarrow{v}</math> = (0,3). These can also be written as <math>\overrightarrow{u}</math> = 2i + 2j and <math>\overrightarrow{v}</math> = 0i + 3j = 3j.
    • While our example uses two-dimensional vectors, the instructions below cover vectors with any number of components.
  2. Write down the cosine formula. To find the angle θ between two vectors, start with the formula for finding that angle's cosine. You can learn about this formula below, or just write it down:[2]
    • cosθ = (<math>\overrightarrow{u}</math> • <math>\overrightarrow{v}</math>) / (||<math>\overrightarrow{u}</math>|| ||<math>\overrightarrow{v}</math>||)
    • ||<math>\overrightarrow{u}</math>|| means "the length of vector <math>\overrightarrow{u}</math>."
    • <math>\overrightarrow{u}</math> • <math>\overrightarrow{v}</math> is the dot product (scalar product) of the two vectors, explained below.
  3. Calculate the length of each vector. Picture a right triangle drawn from the vector's x-component, its y-component, and the vector itself. The vector forms the hypotenuse of the triangle, so to find its length we use the Pythagorean theorem. As it turns out, this formula is easily extended to vectors with any number of components.[1]
    • ||u||2 = u12 + u22. If a vector has more than two components, simply continue adding +u32 + u42 + ...
    • Therefore, for a two-dimensional vector, ||u|| = √(u12 + u22).
    • In our example, ||<math>\overrightarrow{u}</math>|| = √(22 + 22) = √(8) = 2√2. ||<math>\overrightarrow{v}</math>|| = √(02 + 32) = √(9) = 3.
  4. Calculate the dot product of the two vectors. You have probably already learned this method of multiplying vectors, also called the scalar product.[3] To calculate the dot product in terms of the vectors' components, multiply the components in each direction together, then add all the results.[4]
    • For computer graphics programs, see Tips before you continue.
    • In mathematical terms, <math>\overrightarrow{u}</math> • <math>\overrightarrow{v}</math> = u1v1 + u2v2, where u = (u1, u2). If your vector has more than two components, simply continue to add + u3v3 + u4v4...
    • In our example, <math>\overrightarrow{u}</math> • <math>\overrightarrow{v}</math> = u1v1 + u2v2 = (2)(0) + (2)(3) = 0 + 6 = 6. This is the dot product of vector <math>\overrightarrow{u}</math> and <math>\overrightarrow{v}</math>.
  5. Plug your results into the formula. Remember, cosθ = (<math>\overrightarrow{u}</math> • <math>\overrightarrow{v}</math>) / (||<math>\overrightarrow{u}</math>|| ||<math>\overrightarrow{v}</math> ||). Now you know both the dot product and the lengths of each vector. Enter these into this formula to calculate the cosine of the angle.
    • In our example, cosθ = 6 / (2√2 * 3) = 1 / √2 = √2 / 2.
  6. Find the angle based on the cosine. You can use the arccos or cos-1 function on your calculator to find the angle θ from a known cos θ value. For some results, you may be able to work out the angle based on the Understand-the-Unit-Circle.
    • In our example, cosθ = √2 / 2. Enter "arccos(√2 / 2)" in your calculator to get the angle. Alternatively, find the angle θ on the unit circle where cosθ = √2 / 2. This is true for θ = π/4 or 45º.
    • Putting it all together, the final formula is: angle θ = arccosine((<math>\overrightarrow{u}</math> • <math>\overrightarrow{v}</math>) / (||<math>\overrightarrow{u}</math>|| ||<math>\overrightarrow{v}</math> ||))

Defining the Angle Formula

  1. Understand the purpose of this formula. This formula was not derived from existing rules. Instead, it was created as a definition of two vectors' dot product and the angle between them.[5] However, this decision was not arbitrary. With a look back to basic geometry, we can see why this formula results in intuitive and useful definitions.
    • The examples below use two-dimensional vectors because these are the most intuitive to use. Vectors with three or more components have properties defined with the very similar, general case formula.
  2. Review the Law of Cosines. Take an ordinary triangle, with angle θ between sides a and b, and opposite side c. The Law of Cosines states that c2 = a2 + b2 -2abcos(θ). This is derived fairly easily from basic geometry.[6]
  3. Connect two vectors to form a triangle. Sketch a pair of 2D vectors on paper, vectors <math>\overrightarrow{a}</math> and <math>\overrightarrow{b}</math>, with angle θ between them. Draw a third vector between them to make a triangle. In other words, draw vector <math>\overrightarrow{c}</math> such that <math>\overrightarrow{b}</math> + <math>\overrightarrow{c}</math> = <math>\overrightarrow{a}</math>. This vector <math>\overrightarrow{c}</math> = <math>\overrightarrow{a}</math> - <math>\overrightarrow{b}</math>.[7]
  4. Write the Law of Cosines for this triangle. Insert the length of our "vector triangle" sides into the Law of Cosines:
    • ||(a - b)||2 = ||a||2 + ||b||2 - 2||a|| ||b||cos(θ)
  5. Write this using dot products. Remember, a dot product is the magnification of one vector projected onto another. A vector's dot product with itself doesn't require any projection, since there is no difference in direction.[8] This means that <math>\overrightarrow{a}</math> • <math>\overrightarrow{a}</math> = ||a||2. Use this fact to rewrite the equation:
    • (<math>\overrightarrow{a}</math> - <math>\overrightarrow{b}</math>) • (<math>\overrightarrow{a}</math> - <math>\overrightarrow{b}</math>) = <math>\overrightarrow{a}</math> • <math>\overrightarrow{a}</math> + <math>\overrightarrow{b}</math> • <math>\overrightarrow{b}</math> - 2||a|| ||b||cos(θ)
  6. Rewrite it into the familiar formula. Expand the left side of the formula, then simplify to reach the formula used to find angles.
    • <math>\overrightarrow{a}</math> • <math>\overrightarrow{a}</math> - <math>\overrightarrow{a}</math> • <math>\overrightarrow{b}</math> - <math>\overrightarrow{b}</math> • <math>\overrightarrow{a}</math> + <math>\overrightarrow{b}</math> • <math>\overrightarrow{b}</math> = <math>\overrightarrow{a}</math> • <math>\overrightarrow{a}</math> + <math>\overrightarrow{b}</math> • <math>\overrightarrow{b}</math> - 2||a|| ||b||cos(θ)
    • - <math>\overrightarrow{a}</math> • <math>\overrightarrow{b}</math> - <math>\overrightarrow{b}</math> • <math>\overrightarrow{a}</math> = -2||a|| ||b||cos(θ)
    • -2(<math>\overrightarrow{a}</math> • <math>\overrightarrow{b}</math>) = -2||a|| ||b||cos(θ)
    • <math>\overrightarrow{a}</math> • <math>\overrightarrow{b}</math> = ||a|| ||b||cos(θ)



Tips

  • For a quick plug and solve, use this formula for any pair of two-dimensional vectors: cosθ = (u1 • v1 + u2 • v2) / (√(u12 • u22) • √(v12 • v22)).
  • If you are working on a computer graphics program, you most likely only care about the direction of the vectors, not their length. Take these steps to simplify the equations and speed up your program:[9][10]
    • Normalize-a-Vector so the length becomes 1. To do this, divide each component of the vector by the vector's length.
    • Take the dot product of the normalized vectors instead of the original vectors.
    • Since the length equal 1, leave the length terms out of your equation. Your final equation for the angle is arccos(<math>\overrightarrow{u}</math> • <math>\overrightarrow{v}</math>).
  • Based on the cosine formula, we can quickly find whether the angle is acute or obtuse. Start with cosθ = (<math>\overrightarrow{u}</math> • <math>\overrightarrow{v}</math>) / (||<math>\overrightarrow{u}</math>|| ||<math>\overrightarrow{v}</math>||):
    • The left side and right sides of the equation must have the same sign (positive or negative).
    • Since the lengths are always positive, cosθ must have the same sign as the dot product.
    • Therefore, if the dot product is positive, cosθ is positive. We are in the first quadrant of the unit circle, with θ < π / 2 or 90º. The angle is acute.
    • If the dot product is negative, cosθ is negative. We are in the second quadrant of the unit circle, with π / 2 < θ ≤ π or 90º < θ ≤ 180º. The angle is obtuse.

Related Articles

Sources and Citations