I am trying to calculate the smallest difference between two angles.
This is my current code (a slight change to what I found online):
float a1 = MathHelper.ToDegrees(Rot);
float a2 = MathHelper.ToDegrees(m_fTargetRot);
float dif = (float)(Math.Abs(a1 - a2);
if (dif > 180)
dif = 360 - dif;
dif = MathHelper.ToRadians(dif);
It works great, except at the edge of the circle. For example, if the current angle is 355 and the target angle is 5, it calculates the difference at -350, not 10, since 365 degrees is 5 degrees.
Any ideas on what I can do to make this work?
source
share