2d vector aid

I'm in need of a little help.

Generally I have no problem with vectors when it comes to 3d stuff, but I have no clue how 2d equivalents work.
Basically here's the outline:

I have this biped set up to fire a cube out of his hand, basically. Now, two problems are faced here:

Code:
         // Shoot bullet test
         b2Vec2 test = TheBiped->LHand->GetPosition();
         BulletBody *Bullet = new BulletBody (test, 3, 1, b2Color(1,1,1), -1, TheBiped->LHand->GetAngle() + DEG2RAD(90));
         b2Vec2 Vel = b2Cross(Bullet->PhysicsBody->GetPosition(), TheBiped->LHand->GetAngle());

         Bullet->PhysicsBody->SetLinearVelocity(Vel);
         //Bullet->PhysicsBody->ApplyImpulse (Vel, Bullet->PhysicsBody->GetLocalCenter());


You can see my poor attempts at doing a sort of linear velocity right off the bat. The other problem was the angles; I had to hack a + 90 degree turn on the cube because it was facing the wrong way, and I'm not sure if what I'm doing is correct.

In any case, what I want is a cube to fire from his hand in the direction that the hand is facing, and I don't know enough about 2d to accomplish this (back in 3d (euler angles, of course) I would use something like Angles_Vectors to get the forward vector from the angles, and multiply the origin by a scale amount in the forward direction and use that as the velocity)

Any ideas?

-P
The way I do it is to calculate a direction vector based on the angle's sin and cos, then multiply it by the desired velocity.
Any code snippets you can drop me? I'm intrigued and you might have exactly what I need.

EDIT:
Seems I got it!

Code:
         // Shoot bullet test
         b2Vec2 test = TheBiped->LHand->GetPosition();
         b2Vec2 Vel (sin(TheBiped->LHand->GetAngle()), -cos(TheBiped->LHand->GetAngle()));

         BulletBody *Bullet = new BulletBody (test, 3, 1, b2Color(1,1,1), -1, TheBiped->LHand->GetAngle() + DEG2RAD(90));
         b2Vec2 Temp (Vel.x * 50, Vel.y * 50);
         Bullet->PhysicsBody->SetLinearVelocity(Temp);


Thanks guy, very helpful 😀

-P
I don't have any code with me right now, but it looks like what you posted. I'm not sure what coordinate system you're using, but it looks like you're rotating everything 90 degrees clockwise. Normally, cos(angle) gives the X value and sin(angle) the Y value. (1,0) is angle 0. In your case, it's (0, -1).

Also, the cube shouldn't need a 90 degree rotation to be aligned with the hand. You could give the same angle to the cube and they should be facing the same direction. If they are not, it may be some bug in your display code.
It has to do with the angle of the hand. The hand is angled straight down. In any case, when I copied over the hand angles it was always 90 degrees off, so it was a simple fix in any case.

-P

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