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 behavior as System.Math.IEEERemainder(radians, Math.PI*2.0) . Need to check ...
EDIT2: I think using% is correct
EDIT3: Blah, this is not true because it returns a negative value for negative numbers. Does anyone know how to get divmod in python 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, he tries to get around both ways, all mod 2pi calculations, and he chooses one with a shorter distance.
source share