Home > Blockchain >  Calculating the angle between two vectors using a needle-like triangle
Calculating the angle between two vectors using a needle-like triangle

Time:10-06

I implemented a function (angle_between) to calculate the angle between two vectors. It makes use of needle-like triangles and is based on angle formula Assuming that a≥b, a≥c (only then is the formula valid) and b c≈a. If we ignore mu for a second and look at everything else under the square root it must all be positive since a is the longest side. And mu is c-(a-b) which is 0 ± a small error. If that error is zero you get zero which is btw. the correct result. If the error is negative the square root gives you nan and if the error is positive you get a small angle.

Notice that the same argument works when b c-a is non zero but smaller than the error.

  • Related