Answered by:
Create Vector from Angle
Question

I have an angle of rotation in radians. Is there an easy way to convert this to a vector, as I have a 2D sprite ship I want to be able to rotate, and move in the direction of the rotation?
Simon
Thursday, November 2, 2006 5:36 AM
Answers

Do you mean something like this?
public Vector2(float angle)
{
X = (float)Math.Sin(angle);
Y = (float)Math.Cos(angle);
}
??Thursday, November 2, 2006 10:38 AM 
Just so you know the XNA framework, uses 0 radians as up. For example when drawing a sprite, and you want to rotate it, in the SpriteBatch.Draw method.Thursday, November 2, 2006 8:17 PM
All replies

Can you precise what kind of movement you are tolking to? Because "the direction of rotation" has two meaningful values only  clockwise and counterclockwise, relatively to rotation axis.Thursday, November 2, 2006 6:30 AM

Do you mean something like this?
public Vector2(float angle)
{
X = (float)Math.Sin(angle);
Y = (float)Math.Cos(angle);
}
??Thursday, November 2, 2006 10:38 AM 
I will try that. I have a ship which I want to rotate about its axis, and then move it in the direction it is pointing using the rotation angle. So if that code will do it, then I will give it a shot.
Simon
Thursday, November 2, 2006 3:46 PM 
MattDavey wrote: Do you mean something like this?
public Vector2(float angle)
{
X = (float)Math.Sin(angle);
Y = (float)Math.Cos(angle);
}
??The idea is correct but you have to switch your trig functions to :
X = (float)Math.Cos(angle);
Y = (float)Math.Sin(angle);and remember the the north direction (meaning up) is 0 radians and west direction (left) is PI / 2.
Thursday, November 2, 2006 6:17 PM 
Hmm i was always under the impression that 0 degrees was down in computer world  in which case my code was correct. I suppose your choice makes more sense but i've just always used 0deg = down.Thursday, November 2, 2006 8:01 PM

Just so you know the XNA framework, uses 0 radians as up. For example when drawing a sprite, and you want to rotate it, in the SpriteBatch.Draw method.Thursday, November 2, 2006 8:17 PM