One way to notate a vector is with coordinates (x,y,z). For example, the vector v = (3,-2,5) corresponds to a vector that starts at the origin (0,0,0) and ends at the point (3,-2,5). When we talk about the angle between two vectors, we think of them as both extending from the origin.
The magnitude, or length, of a vector is calculated using Pythagoras’ theorem. The vector v = (x,y,z) has a magnitude |v| = sqrt(x^2 + y^2 + z^2).
The dot product, or scalar product, of two vectors is equal to the sum of the products of the corresponding coordinates in each vector. If a = (x,y,z) and b = (u,v,w), then the dot product is a·b = x*u + y*v + z*w. A property of the dot product is that, if θ is the angle between a and b, then a·b = |a||b|cos(θ).
We can find the angle by solving for cos(θ) in the dot product formula, and then using the inverse cosine, or arccos function to find θ. Putting it all together, θ = arccos( a·b / (|a||b|) ).
Let a = (-3,4,10) and b = (5,1,-1). Then |a| = 5.39, |b| = 5.20, a·b = -13.00 and θ = arccos(-13/(5.39*5.20)) = 118 degrees.