Thread: Angle from X,Y
View Single Post
  #7   Spotlight this post!  
Unread 10-04-2004, 20:58
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Red face Re: Angle from X,Y

:WHAP: Duh
Code:
unsigned int GetAngle(signed int X, signed int Y)
{
   signed int Angle = arctan(Y/abs(X));
 unsigned char OtherSide = IsNegetive(X);
 unsigned int Value = 0;
 
 if (OtherSide)
  Value = 180 - Angle + 360;
 else
  Value = Angle + 360;
 
 Value %= 360;
 return Value;
}
Unfortunately, you have to use a float for Angle because angles between -45 and 45 are as important as the others. I suppose I could flip X and Y around for that.

[Changed that tan to arctan]

Last edited by Astronouth7303 : 10-04-2004 at 21:01. Reason: Big boo-boo