• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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