Maths: Angle Difference

Zwiebelchen

You can change this now in User CP.
Reaction score
60
I'm looking for a function that returns the angle difference between two degree values A and B that both range from -180 to +180.

There are two important things about this:
- the function should always return the lowest angle difference (so no values above/below +/-180 degrees)
- the function should return the right algebraic sign ... positive values = counterclockwise, negative values = clockwise

maybe i'm just tired, but I simply can not figure out how to do it properly.
Can someone help?
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Hmm ... I came up with this now:
JASS:
            set delta = A-B
if delta > bj_PI then //190 --> -170
                set delta = delta - 2*bj_PI
elseif delta < -bj_PI then //-190 --> 170
                set delta = delta + 2*bj_PI
endif

Dunno if it works for all cases, but it looks promising. Am I missing something?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top