IsAngleBetweenAngles(real match, real max, real min)
by Zacharias
by Zacharias
This is a function to check if an angle is between two other angles. It returns true if max>match>min.
The function it self is not complex, but full of math added some comments for those who want to study this function
JASS:
function IsAngleBetweenAngles takes real Match, real Max, real Min returns boolean
// note: all operations do only modify the interval of match, min and max
// set match, max, min to interval [0,2*PI)
set Match = ModuloReal(Match,2*bj_PI)
set Max = ModuloReal(Max,2*bj_PI)
set Min = ModuloReal(Min,2*bj_PI)
// bring min under match, even if min gets negative
// min e (-2*PI,2*PI)
loop
exitwhen Match >= Min
set Min = Min - 2*bj_PI
endloop
// bring max over min (max is positive (modulo))
// max > min, max e [0,2*PI)
loop
exitwhen Max > Min
set Max = Max + 2*bj_PI
endloop
// as min is over -2*PI, max cant get negative through the following function
loop
exitwhen (Max-Min) < 2*bj_PI
set Max = Max - 2*bj_PI
endloop
// result:
// max > min
// min e (-2*PI,2*PI)
// max e [0,2*PI)
// match e [0,2*PI)
return (Max>=Match)
endfunction