• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

IsAngleBetweenAngles

Status
Not open for further replies.
Level 7
Joined
Oct 21, 2008
Messages
234
IsAngleBetweenAngles(real match, real max, real min)
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 :wink: added some comments for those who want to study this function :wink:

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
 
Status
Not open for further replies.
Top