[gameprogrammer] Re: Diff Between 2 Angles

What about:

angleDif = (angle1 - angle2) MOD 360 

if angleDif < 0 then angleDif += 360

?? does that work?

C

-----Original Message-----
From: gameprogrammer-bounce@xxxxxxxxxxxxx
[mailto:gameprogrammer-bounce@xxxxxxxxxxxxx]On Behalf Of Robbert de
Groot
Sent: 29 September 2005 16:49
To: gameprogrammer@xxxxxxxxxxxxx
Subject: [gameprogrammer] Re: Diff Between 2 Angles


if (angle < 0) {
   angle  = -angle;
   negate = -1;
}
else {
   negate = 1;
}

while (angle > 360) {
   angle -= 360;
}

if (angle > 180) {
   return negate * (angle - 180);
}
return negate * angle;


--- Stephen <stephen@xxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> I've got a really simple problem that I'm almost ashamed to ask
> about!  
> I've written a 3D pseudo-realtime strategy game called Lazer Squad
> 3D 
> (www.carlylesmith.karoo.net/lazersquad3d/).  One problem I always
> think 
> I've solved, but then comes back to bite me, is how to get the 
> difference between two angles.  This seems easy on the face of it,
> but 
> then along comes two angles and my formula gets it all wrong. 
> (This is 
> degrees, BTW, not rads).
> 
> The main problem is when dealing with negative angles, angles >
> 360, and 
> also getting the shortest distance (i.e. not the long way round). 
> For 
> example, the difference between -359 and 359 should be 2 degrees. 
> The 
> difference between 90 and -270 should be zero.  Etc.. etc.. Can
> anyone 
> help please?
> 
> Thanks in advance,
> 
> Steve Smith
> 
> 
> 
> 
> 
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> 
> 
> 



        

        
                
__________________________________________________________ 
Find your next car at http://autos.yahoo.ca


---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html





---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: