prime31 / Nez

Nez is a free 2D focused framework that works with MonoGame and FNA
MIT License
1.76k stars 355 forks source link

Mathf.AngleBetweenVectors() does not compute the angle between vectors #747

Open Diamond-Wolf opened 1 year ago

Diamond-Wolf commented 1 year ago

What it does is take the second vector, subtract it from the first, and compute the angle from 0 to the resulting vector via atan2. This is not correct e.g. when the vectors are 90 degrees apart. If you have vectors (0,1) and (1,0), it will subtract the two, then compute atan2(-1,1). This is 135 degrees, not 90. Changing the length of either vector will also change the resulting angle, even though the actual angle is not changing.

Cremetoertchen0815 commented 1 year ago

I believe this is a misunderstanding of the terminology. Vectors can be position vectors or direction vectors. This method calculates the angle between two position vectors by forming the direction vector and then calculating the angle. Maybe a bit confusing, but not false!