The angle between two vectors measures how closely the vectors point in the same direction. If the angle is small, the vectors are
strongly aligned. If the angle is close to \(90^\circ\), they are perpendicular. If the angle is larger than \(90^\circ\), they
point generally in opposite directions. The standard way to compute this angle is by using the dot product formula.
Dot product formula for the angle
For nonzero vectors
\(A\)
and
\(B\),
the angle
\(\theta\)
between them satisfies
Main formula.
\[
\begin{aligned}
\cos\theta &= \frac{A\cdot B}{|A||B|}
\end{aligned}
\]
Once the cosine is known, the angle itself is found by inverse cosine:
\[
\begin{aligned}
\theta &= \cos^{-1}\!\left(\frac{A\cdot B}{|A||B|}\right)
\end{aligned}
\]
This formula works in both 2D and 3D. The only requirement is that neither vector can be the zero vector, because division by
\(|A||B|\) would otherwise be impossible.
How to compute the dot product
In 2D, if
\(A = (A_x, A_y)\)
and
\(B = (B_x, B_y)\),
then
\[
\begin{aligned}
A\cdot B &= A_xB_x + A_yB_y
\end{aligned}
\]
In 3D, if
\(A = (A_x, A_y, A_z)\)
and
\(B = (B_x, B_y, B_z)\),
then
\[
\begin{aligned}
A\cdot B &= A_xB_x + A_yB_y + A_zB_z
\end{aligned}
\]
The magnitude formulas are
\[
\begin{aligned}
|A| &= \sqrt{A_x^2 + A_y^2} \quad \text{in 2D} \\
|A| &= \sqrt{A_x^2 + A_y^2 + A_z^2} \quad \text{in 3D}
\end{aligned}
\]
and similarly for
\(|B|\).
What the sign of the dot product tells us
The sign of the dot product immediately gives information about the angle:
| Condition |
Angle type |
Interpretation |
| \(A\cdot B > 0\) |
Acute |
The vectors point generally in the same direction |
| \(A\cdot B = 0\) |
Right |
The vectors are perpendicular |
| \(A\cdot B < 0\) |
Obtuse |
The vectors point generally in opposite directions |
This is useful because you can often classify the angle before even calculating the inverse cosine.
Worked 3D example
Consider the sample vectors
\(A = \langle 1,2,3\rangle\)
and
\(B = \langle 4,5,6\rangle\).
Step 1. Compute the dot product.
\[
\begin{aligned}
A\cdot B &= 1\cdot 4 + 2\cdot 5 + 3\cdot 6 \\
&= 4 + 10 + 18 \\
&= 32
\end{aligned}
\]
Step 2. Compute the magnitudes.
\[
\begin{aligned}
|A| &= \sqrt{1^2 + 2^2 + 3^2} = \sqrt{14} \\
|B| &= \sqrt{4^2 + 5^2 + 6^2} = \sqrt{77}
\end{aligned}
\]
Step 3. Compute the cosine of the angle.
\[
\begin{aligned}
\cos\theta &= \frac{32}{\sqrt{14}\sqrt{77}}
\end{aligned}
\]
Step 4. Take the inverse cosine.
\[
\begin{aligned}
\theta &= \cos^{-1}\!\left(\frac{32}{\sqrt{14}\sqrt{77}}\right)
\end{aligned}
\]
Numerically, this gives about
\(12.9^\circ\),
so the angle is acute.
2D orientation note
In 2D, there is an extra geometric detail that is often useful: whether vector
\(B\)
is reached from vector
\(A\)
by a clockwise or counterclockwise rotation. The calculator can report that orientation as a visual aid for the graph, while still
using the dot product to compute the actual angle size.
Why the calculator clamps the cosine value
Because computers use floating-point arithmetic, the computed value of
\(\dfrac{A\cdot B}{|A||B|}\)
can sometimes become slightly larger than 1 or slightly smaller than -1 due to rounding, even though the true mathematical value
must stay in the interval \([-1,1]\). To avoid errors when calling inverse cosine, calculators usually clamp the value back into
that valid range before applying
\(\cos^{-1}\).
Physical interpretation
In mechanics, the angle between forces or between a force and a displacement can matter a lot. For example, work depends on
\(F\cdot d = |F||d|\cos\theta\).
When \(\theta\) is small, most of the force acts along the displacement. When \(\theta = 90^\circ\), the force does no work in that
direction. This is one reason the angle-between-vectors formula appears so often in physics.
Important restriction
The angle is undefined if either vector is zero. A zero vector has no direction, so the phrase “angle between the vectors” loses its
meaning. That is why the calculator rejects zero-vector input.
Summary
| Quantity |
Formula |
Meaning |
| Dot product in 2D |
\(A\cdot B = A_xB_x + A_yB_y\) |
Alignment measure in the plane |
| Dot product in 3D |
\(A\cdot B = A_xB_x + A_yB_y + A_zB_z\) |
Alignment measure in space |
| Angle formula |
\(\cos\theta = (A\cdot B)/(|A||B|)\) |
Links dot product to direction difference |
| Angle itself |
\(\theta = \cos^{-1}((A\cdot B)/(|A||B|))\) |
Actual angle between the vectors |
| Acute test |
\(A\cdot B > 0\) |
Vectors point generally together |
| Right-angle test |
\(A\cdot B = 0\) |
Vectors are perpendicular |
| Obtuse test |
\(A\cdot B < 0\) |
Vectors point generally opposite |