I use math.acos() to calculate the angle between two vectors. The idea is to calculate the dot product of the two normalized vectors, and use arccos of the dot product to return the angle of the two vectors (in the range of 0 to pi).
Occasionally the two vectors, when normalized, have a same direction and their dot product should be 1. However, because of the numerical errors, it is actually 0.999999999998, ... or sometimes 1.0000000000002. The latter kills the math.acos() with an error ValueError: math domain error
I accidentally found this question asking about a similar problem, but was closed. Here I am re-asking, hope to get a better idea on how to avoid such errors.
In my case, I have to check if the two vectors have the same direction before doing dot production and arccos. This helps, but I am still wondering if there are better ways to do this.