Formula for converting angle to vector?
Hi guys
Basic game math help needed.
I need a formula to convert an angle in to (x, y).
For example 135 deg = (1, 1) and 90 = (1, 0)
Basic game math help needed.
I need a formula to convert an angle in to (x, y).
For example 135 deg = (1, 1) and 90 = (1, 0)
Code:
double XComponentOfVector( const double p_direction, const double p_magnitude )
{
return ( sin( p_direction ) * p_magnitude );
}
...and...
Code:
double YComponentOfVector( const double p_direction, const double p_magnitude )
{
return ( cos( p_direction ) * p_magnitude );
}
Mark Bishop

Student and freelance OS X & iOS developer
sin and cos are what you want. If your angles are in degrees, remember to convert to radians first. Also note that 135 degrees in your example will be {0.707106781186548, 0.707106781186548}, not {1, 1}; if you want square coordinates rather than circular ones, you'll need to do something like divide both numbers by the larger of the two.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Question Regarding the Reflect Angle of a Transition  iBaby  3  4,237 
Apr 27, 2010 03:15 PM Last Post: JustinFic 

Fast Distance formula?  mikey  11  9,415 
Nov 23, 2009 10:43 AM Last Post: mikey 

Direction formula?  TimMcD  2  6,318 
Nov 11, 2009 11:42 PM Last Post: TimMcD 

ending location from angle and speed  Kazooless  5  5,337 
Apr 3, 2009 02:40 PM Last Post: Gillissie 

Angle between two points?  Graphic Ace  6  6,319 
Nov 8, 2008 12:11 PM Last Post: macnib 