EDIT: I'm not sure if this will work. I translated it from some python code, but I'm not sure if divmod(radians, math.pi*2)[1]
is the same behaviour as System.Math.IEEERemainder(radians, Math.PI*2.0)
. Need to test...
EDIT2: I think using % is correct
EDIT3: Blah, it's not correct because it returns a negative value for negative numbers. Does anyone know how to get python divmod in C#?
How to calculate the angle between two angles:
public static double NormalizeAngle(double radians)
{
return fmod(radians,Math.PI*2.0); # this method doesn't exist, see above
}
public static double ArcLength(double radians1, double radians2)
{
radians1 = NormalizeAngle(radians1);
radians2 = NormalizeAngle(radians2);
return Math.Min(NormalizeAngle(radians1 - radians2, NormalizeAngle(radians2 - radians1));
}
How it works is it tries both ways around, all calculations mod 2pi, and it picks the one with a smaller distance.