A·B = |A| |B| cos(θ)

this comes from the definition of the inner product (dot product)

It can be derived using the law of cosines:

let a, b, c be vectors

define vector c = a - b

this forms a triangle, let θ be the angle between a and b, i.e. opposite side c

from the law of cosines

c² = a² + b² - 2abcos(θ)

from another property of the dot product, x·x = x²

we replace c², a², and b² to get

c·c = a·a + b·b - 2abcos(θ)

since c = a - b

c·c = (a -b)·(a - b)

c·c = (a·a - 2a·b + b·b)

plug this in

(a·a - 2a·b + b·b) = a·a + b·b - 2abcos(q)

clean it up by canceling a·a, and b·b to get:

-2a·b = -2abcos(θ)

divide by -2 to get the result

a·b = abcos(θ)