Dot Product and the Angle Between Two Vectors

Calculates the dot product of two plane vectors as x₁x₂ + y₁y₂, and the angle between them (in degrees) from cos θ = dot product ÷ (|a||b|).

The dot product of two plane vectors is a single number: multiply matching components and add. Simple as it looks, it measures how much the two vectors point the same way, which is precisely what lets you recover the angle between them.

ab=x1x2+y1y2\vec{a} \cdot \vec{b} = x_1 x_2 + y_1 y_2

The angle comes from dividing the dot product by the two magnitudes.

cosθ=abab\cos\theta = \dfrac{\vec{a} \cdot \vec{b}}{|\vec{a}||\vec{b}|}

Example

Let a=(3,1)\vec{a} = (3, 1) and b=(1,2)\vec{b} = (1, 2). The dot product is 3×1+1×2=53 \times 1 + 1 \times 2 = 5. The magnitudes are a=10|\vec{a}| = \sqrt{10} and b=5|\vec{b}| = \sqrt{5}, so

cosθ=510×5=550=12\cos\theta = \dfrac{5}{\sqrt{10} \times \sqrt{5}} = \dfrac{5}{\sqrt{50}} = \dfrac{1}{\sqrt{2}}

and therefore θ=45\theta = 45^\circ.

Notes