Formula for converting angle to vector?

Nibbie
Posts: 1
Joined: 2011.07
Post: #1
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)

LOL
Quote this message in a reply
Moderator
Posts: 699
Joined: 2002.04
Post: #2
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
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #3
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Question Regarding the Reflect Angle of a Transition iBaby 3 3,588 Apr 27, 2010 03:15 PM
Last Post: JustinFic
  Fast Distance formula? mikey 11 7,563 Nov 23, 2009 10:43 AM
Last Post: mikey
  Direction formula? TimMcD 2 5,328 Nov 11, 2009 11:42 PM
Last Post: TimMcD
  ending location from angle and speed Kazooless 5 4,569 Apr 3, 2009 02:40 PM
Last Post: Gillissie
  Angle between two points? Graphic Ace 6 5,492 Nov 8, 2008 12:11 PM
Last Post: macnib