Skip to main content
gamedev.net
🔒 Locked

Simple Angle Algorithm

Started by Sir Sapo Oct 27, 2005 at 5:07 PM 1 replies 1.5k views
Original Post
Sir Sapo
Sir Sapo
Hey everyone, I've been trying to write a function,like the one below, that takes 2 angles as parameters, and then returns a boolean that says whether turning clockwise is a faster way to reach the target than turning counterclockwise. bool turnClockWise(int currentangle , int targetangle) I've attempted this with about 4 different approaches, but each time they failed to work properly, and I'm asking you guys for help. Does anyone know of an algorithm that will solve this problem?
My Current Project Angels 22 (4E5)
Zipster
Zipster
Off the top of my head:
while(source < 0.0f)  source += 360.0f;while(target < 0.0f)  target += 360.0f;while(source >= 360.0f)  source -= 360.0f;while(target >= 360.0f)  target -= 360.0f;if(source > target)  if(source - target < 180.0f)     result = CW;  else     result = CCW;else if(target - source < 180.0f)  result = CCW;else  result = CW;

The mapping into the standard [0, 360) range is important, because an angle of -5 and 356 are only 1° apart, however the math doesn't know that. Same with 10 and 371, etc.
Sir Sapo
Sir Sapo
Thanks, that really helped me out, rate++.
My Current Project Angels 22 (4E5)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.