How to Find the Angle Between Two Vectors in 2D and 3D (With Examples)
By Dr. Muhammad Amjad Khadim (PhD Mathematics) · Updated November 2026
Finding the angle between two vectors is one of those skills that turns up everywhere once you know it. A physics student needs it to split a force into components. A games programmer needs it to decide whether an enemy is in front of the player or behind. An A level or Calc 3 student needs it on almost every vectors paper. The good news is that there is really only one formula to learn, and it works the same way in two dimensions, three dimensions, or any number of dimensions.
In this guide I will walk you through that formula, explain why it works (so you never have to memorise it blindly), and then solve several examples step by step, including 2D vectors, 3D vectors, an obtuse angle and a classic cube-diagonal question. If you just want the answer to a homework question quickly, you can also use the angle between two vectors calculator on our calculators page and then come back here to check the working.
1. The formula for the angle between two vectors
2. Where the formula comes from
3. Step-by-step method
4. Worked examples in 2D and 3D
5. Using the cross product instead
6. Special cases: 0°, 90° and 180°
7. Common mistakes students make
8. Frequently asked questions
1. The Formula for the Angle Between Two Vectors
If a and b are two non-zero vectors and θ is the angle between them, then
so θ = cos−1[ (a · b) / (|a| |b|) ]
Here a · b is the dot product of the two vectors and |a|, |b| are their magnitudes (lengths). In components, for 3D vectors a = (a1, a2, a3) and b = (b1, b2, b3):
- a · b = a1b1 + a2b2 + a3b3
- |a| = √(a1² + a2² + a3²)
- |b| = √(b1² + b2² + b3²)
For 2D vectors you simply drop the third component. The angle you get from cos−1 always lies between 0° and 180° (0 and π radians). That is exactly what we want, because the angle between two vectors is defined as the smaller angle you get when you place them tail to tail.
2. Where the Formula Comes From
It helps a lot to see why this formula is true. Put the two vectors tail to tail and join their tips. You now have a triangle whose sides are |a|, |b| and |a − b|. The cosine rule from trigonometry says
|a − b|² = |a|² + |b|² − 2|a||b| cos θ
Now expand the left-hand side using the dot product. Because the dot product distributes like ordinary multiplication,
|a − b|² = (a − b)·(a − b) = |a|² − 2 a·b + |b|²
Compare the two lines. The |a|² and |b|² terms cancel, and you are left with a · b = |a||b| cos θ. Divide both sides by |a||b| and the formula drops out. So the angle formula is really just the cosine rule written in vector language. If your cosine rule is a little rusty, our article on trigonometric identities with proofs is a good refresher.
This also tells you something useful about the sign of the dot product. Since |a| and |b| are always positive, the sign of a · b is the sign of cos θ:
| Value of a · b | cos θ | Type of angle |
|---|---|---|
| Positive | Between 0 and 1 | Acute (0° ≤ θ < 90°) |
| Zero | 0 | Right angle (θ = 90°) |
| Negative | Between −1 and 0 | Obtuse (90° < θ ≤ 180°) |
So before you even reach for a calculator, the sign of the dot product tells you whether the answer should be acute or obtuse. That is a great built-in check on your working.
3. Step-by-Step Method
- Write both vectors in component form. If they are given as i, j, k, convert 3i − 2j + k into (3, −2, 1). If they are given as two points, subtract to get the vector first.
- Compute the dot product a · b by multiplying matching components and adding.
- Compute both magnitudes |a| and |b|.
- Divide to get cos θ = a · b / (|a||b|). Keep it as an exact fraction or surd for as long as you can.
- Take the inverse cosine and give the answer in degrees or radians as the question asks. Check your calculator mode.
4. Worked Examples
Example 1: Angle between two 2D vectors
Find the angle between a = (3, 4) and b = (5, 12).
Dot product: a · b = 3×5 + 4×12 = 15 + 48 = 63.
Magnitudes: |a| = √(9 + 16) = 5 and |b| = √(25 + 144) = 13.
Cosine: cos θ = 63 / (5 × 13) = 63/65 ≈ 0.9692.
Angle: θ = cos−1(0.9692) ≈ 14.25°.
The dot product is positive, so we expected an acute angle, and the two vectors both point up and to the right, so a small angle makes sense.
Example 2: Angle between two 3D vectors
Find the angle between a = i + 2j + 3k and b = 4i − j + 2k.
Dot product: a · b = (1)(4) + (2)(−1) + (3)(2) = 4 − 2 + 6 = 8.
Magnitudes: |a| = √(1 + 4 + 9) = √14 and |b| = √(16 + 1 + 4) = √21.
Cosine: cos θ = 8 / (√14 √21) = 8/√294 ≈ 8/17.146 ≈ 0.4666.
Angle: θ = cos−1(0.4666) ≈ 62.19° (about 1.085 radians).
Example 3: An obtuse angle
Find the angle between a = (1, −2, 2) and b = (−2, 1, −2).
a · b = −2 − 2 − 4 = −8. Both vectors have magnitude 3, since √(1 + 4 + 4) = 3. So cos θ = −8/9 ≈ −0.8889 and θ ≈ 152.73°.
The negative dot product warned us the angle would be obtuse. The vectors point in roughly opposite directions, which you can see from the signs of their components.
Example 4: Perpendicular vectors
Show that a = 2i + j − 2k and b = i + 2j + 2k are perpendicular.
a · b = 2 + 2 − 4 = 0. Since the dot product is zero and neither vector is zero, cos θ = 0 and θ = 90°. You do not even need the magnitudes here. This "dot product equals zero" test is the fastest way to check for perpendicular (orthogonal) vectors, and it is also the first step in finding the projection of one vector on another.
Example 5: The cube diagonal (a classic exam question)
A unit cube has one corner at the origin. Find the angle between the main diagonal of the cube and one of its edges.
The diagonal from (0, 0, 0) to (1, 1, 1) is d = (1, 1, 1). An edge along the x-axis is e = (1, 0, 0). Then d · e = 1, |d| = √3 and |e| = 1, so cos θ = 1/√3 and θ ≈ 54.74°.
A nice follow-up: the angle between the main diagonal (1, 1, 1) and the face diagonal (1, 1, 0) is cos−1(2/√6) ≈ 35.26°. Notice that 54.74° + 35.26° = 90°, which makes sense because the edge and the face diagonal both lie on the base, and the diagonal rises out of it.
Example 6: Vectors given as points
Points A(1, 0, 2), B(3, 1, 0) and C(2, 3, 1) form a triangle. Find angle BAC.
Angle BAC is the angle between AB and AC, both starting at A. AB = B − A = (2, 1, −2) and AC = C − A = (1, 3, −1). Then AB · AC = 2 + 3 + 2 = 7, |AB| = 3 and |AC| = √11. So cos θ = 7/(3√11) ≈ 0.7035 and θ ≈ 45.30°.
5. Using the Cross Product Instead
There is a second formula, based on the cross product of two vectors:
sin θ = |a × b| / (|a| |b|)
This works in 3D, but it has a weakness. Sine is positive for both acute and obtuse angles, so sin θ = 0.5 could mean 30° or 150°. The dot-product formula does not have this problem, which is why it is the standard method. The cross product version is still handy when you already need a × b for something else, such as the area of a triangle.
Programmers often combine the two: θ = atan2(|a × b|, a · b). This is more accurate than cos−1 when the angle is very close to 0° or 180°, where rounding errors in cos−1 become noticeable. For a full side-by-side comparison of the two products, see dot product vs cross product.
6. Special Cases You Should Recognise
- θ = 0°: the vectors point in the same direction, so one is a positive multiple of the other, for example (2, 4, 6) and (1, 2, 3).
- θ = 90°: the dot product is zero; the vectors are orthogonal.
- θ = 180°: the vectors point in opposite directions, so one is a negative multiple of the other.
- Angle with an axis: the angles a vector makes with the x, y and z axes are found by dotting it with i, j and k. Their cosines, a1/|a|, a2/|a| and a3/|a|, are called the direction cosines. They are just the components of the unit vector in the direction of a, and their squares always add up to 1.
7. Common Mistakes Students Make
- Calculator in the wrong mode. If you get θ = 1.085 and expected degrees, your calculator is in radians. Both answers are correct; just give the one the question asks for.
- Forgetting to square negative components. (−3)² is 9, not −9. Magnitudes are never negative.
- Rounding too early. Keep cos θ as an exact fraction like 8/√294 until the last step, otherwise your final angle can be off by a degree or more.
- Using a zero vector. The angle is undefined if either vector is zero, because you would be dividing by zero.
- Mixing up directions. As in Example 6, both vectors must point away from the common vertex.
- Answering an angle between lines with an obtuse value. The angle between two lines is usually taken as acute, so if you get 120° between two direction vectors, the angle between the lines is 60°. Our guide to slope and direction vectors explains why.
8. Frequently Asked Questions
Can the angle between two vectors be more than 180°?
No. By definition it is the smaller angle between them, so it always lies from 0° to 180°. Angles beyond 180° appear only when you measure a rotation in a fixed direction, for example anticlockwise in 2D, which needs the atan2 function rather than the dot product.
Does the formula work in 4 or more dimensions?
Yes. The dot product and magnitude are defined the same way in any dimension, so the formula carries over exactly. This is how "cosine similarity" is computed in data science and search engines, where vectors can have thousands of components.
How do I find the angle between two vectors without a calculator?
If cos θ comes out as a standard value such as 1/2, √2/2, √3/2, 0 or −1/2, you can read off 60°, 45°, 30°, 90° or 120° from the standard table. Otherwise you will need a calculator or tables for the inverse cosine.
What is the angle between a vector and itself?
Zero. a · a = |a|², so cos θ = |a|²/|a|² = 1 and θ = 0°.
Should I give the answer in degrees or radians?
Follow the question. School and A level papers usually expect degrees to one decimal place, while university calculus courses often expect radians. If you need to switch between them, a quick angle converter such as the ones on PakMath's free unit converters will do it instantly.
Practise and Go Further
Try these on your own, then check them with our vector calculators:
- a = (2, −1, 1), b = (1, 1, 2). (Answer: 60°)
- a = (1, 0, −1), b = (0, 1, 1). (Answer: 120°)
- a = (4, 3), b = (−3, 4). (Answer: 90°)
If you want exam-style practice, work through our 50 vector algebra MCQs with answers. For a more formal treatment, Paul Dawkins' dot product notes at Lamar University and the Wolfram MathWorld entry on the dot product are both excellent references.
The key idea to take away is simple: the dot product measures how much two vectors agree in direction, and dividing by their lengths turns that into a pure cosine. Once that clicks, every angle question on a vectors paper becomes routine.
Comments
Post a Comment