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
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  3,409 
Apr 27, 2010 03:15 PM Last Post: JustinFic 

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

Direction formula?  TimMcD  2  5,010 
Nov 11, 2009 11:42 PM Last Post: TimMcD 

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

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