To find the angle between two vectors, say vector a and vector b, you can use the formula derived from the dot product:
cos(θ) = (a • b) / (||a|| ||b||)
Where:
- θ = angle between the vectors
- a • b = dot product of vectors a and b
- ||a|| = magnitude (length) of vector a
- ||b|| = magnitude (length) of vector b
Here’s how you can calculate it step-by-step:
- First, calculate the dot product of vectors a and b. If a = (a1, a2, a3) and b = (b1, b2, b3), then:
- Next, calculate the magnitude of each vector:
- Now substitute these values into the cosine formula:
- Finally, take the inverse cosine (arccos) to find the angle θ:
a • b = a1 * b1 + a2 * b2 + a3 * b3
||a|| = √(a1² + a2² + a3²)
||b|| = √(b1² + b2² + b3²)
cos(θ) = (a • b) / (||a|| ||b||)
θ = cos-1((a • b) / (||a|| ||b||))
This will give you the angle between the two vectors in radians. Convert it to degrees if necessary by using:
degrees = radians * (180/π)