Angle to Vector

Edit: See skatehead's post below before I embarrass myself any further.

This is useful if you want a player to shoot a bullet at, say, 45 degrees (pi/4 radians), you can figure out what force (expressed as a b2Vec2) to apply to the bullet so that it flies at that angle; ie, you can do bullet->ApplyImpulse(rad2vec(pi/4,10),b2Vec2(0,0)) to shoot a bullet at 10 m/s north-east.
Sorry if I'm missing something here, but can't you just use the sine and cosine of the angle?

i.e:

Code: Select all

b2Vec2 rad2vec(float r) {
   return b2Vec2(cos(r), sin(r));
}
Sure, make me look like an idiot. I knew there was something very basic I was missing. You have to give me credit for my creativity though :p

(Thanks)

Revised:

Code: Select all

b2Vec2 rad2vec(float r, float m = 1) {
   return b2Vec2(cos(r),sin(r))*m;
}
b2Vec2 deg2vec(float r, float m = 1) {
   return rad2vec(r*0.017453292519943295769236907684886f,m);
}
float vec2rad(b2Vec2 v) {
   return atan2(v.y,v.x);
}
float vec2deg(b2Vec2 v) {
   return vec2rad(v)*57.295779513082320876798154814105f;
}
Consider credit given. :P
No way would I have been able to figure that out. :D
How do you make the force stronger

Original thread: https://box2d.org/forum/viewtopic.php?t=354