I was recently working on an XNA project and needed to convert from an angle to a Vector2. There are a lot of resources showing how to go one way (angle->Vector2) or the other (Vector2->angle) but not many showing both. So, I figured it might be helpful to put it up here, even if I only use it for reference.
Angle -> Vector2
1 2 3 4 |
float myAngleInRadians = Math.PI; Vector2 angleVector = new Vector2( (float)Math.Cos(myAngleInRadians), -(float)Math.Sin(myAngleInRadians)); |
Now, the reason I make the Y value negative is because that’s how the screen coordinate system works. If you didn’t do this, the angle in radians would go clock-wise instead of counter-clockwise.
Vector2 -> Angle
Read the rest of this entry »