A: ()
B: ()
The dot product of two vectors is also equal to the product of their magnitudes times the cosine of the angle between them: \[\textbf{A} \cdot \textbf{B}=\|\textbf{A}\|\|\textbf{B}\| cos(\theta)\] If we solve for \(\theta\) we get: \[\theta=cos^{-1} \left(\frac{\textbf{A} \cdot \textbf{B}}{\|\textbf{A}\|\|\textbf{B}\|}\right)\] \[=cos^{-1} \left(\frac{1.000}{(1.414)(3.606)}\right)\] \[=\underline{\underline{66.907^{\circ}}}\]
Things to try:
Note: If you know the two vectors are unit vectors (that they have a length of 1), you can avoid having to calculate or divide by their magnitudes. You also know that the dot product will range from -1 to 1 so to avoid having to do the inverse cosine (an expensive operation compared to the dot product), you can compare directly to the dot product. For example, if you want to check whether two unit vectors are less than 60\(^{\circ}\) apart, you can simply check whether the dot product is greater that 0.5 because \(cos^{-1}(0.5)=60^{\circ}\) and \(cos^{-1}(1.0)=0\).
Note: Be careful implementing this with floating point math. At 0\(^{\circ}\) or 180\(^{\circ}\) inverse cosine can occasionally return NaN. Because of floating point math, dividing my the magnitudes sometimes yields values slightly below -1 or slightly above 1, when it really should be exactly -1 or 1. Since the domain of inverse cosine is -1 to 1, clamping the input is necessary. Just another thing to be aware of when implementing graphics math with floating point values!