1
Programming / Re: Angle wrapping in code, "easy" problem, need to double check
« Last post by ejeffrey on Today at 06:10:28 pm »Quote
. any tips on angle-wrap-respecting code to determine if a supplied angle is inbetween (on the short side) another two supplied angles
If possible I would avoid this. Specifically the "on the short side." Instead, define this in terms of " counterclockwise from the first angle, before reaching the second." This gives a unique representation, allows you to define an arbitrary interval rather than restricting to things less than 180 degrees. Then "x is within the interval [a, b)" becomes:
(x - a) mod 360 < (x - b) mod 360.
If you still need the behavior you asked for then handle that as an input transformation: if (( b - a) mod 360) > 180) then swap(a, b)