#### Archived

This topic is now archived and is closed to further replies.

# How to get the velocities after collided

This topic is 6199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

There are two balls(B1 and B2). balls'' radius is R. Vector V10 is the original velocity of B1, and Vector V20 is the original velocity of B2, After collided, the velocities become V11 and V21 . Is there any sample function to get them?

##### Share on other sites
Please post such problems to the Maths and Physics forum.

Thanks,

Timkin

##### Share on other sites
Is this not a basic physics question on inelastic collisions? research then ask....Geez

##### Share on other sites
If two objects undergo an elastic 1D collision, then the impulse experienced by each one is equal to the difference between their momentums (is that the right word?). In 2D, the impulse will be the projection of that vector onto the vector of collision.

The following code is tested, but unoptimised. It is intended for educational purposes only, and you should probably rewrite it once you understand it.
  typedef struct{ float PosX, PosY; float VelX, VelY; float Mass;} Object2D;void DoCollision(Object2D* Obj1, Object2D* Obj2){// The Impulse expected from a direct collision would be... float DImpulseX = (Obj2->VelX*Obj2->Mass - Obj1->VelX*Obj1->Mass); float DImpulseY = (Obj2->VelY*Obj2->Mass - Obj1->VelY*Obj1->Mass);// Normalise this impulse vector. float DImpulseL = sqrt(DImpulseX*DImpulseX + DImpulseY*DImpulseY); DImpulseX /= DImpulseL; DImpulseY /= DImpulseL;// DiffVec (Difference Vector) is the vector from Obj2 to Obj1. float DiffVecX = Obj2->PosX - Obj1->PosX; float DiffVecY = Obj2->PosY - Obj1->PosY;// Normalise the difference vector float DiffVecL = sqrt(DiffVecX*DiffVecX + DiffVecY*DiffVecY); DiffVecX /= DiffVecL; DiffVecY /= DiffVecL;// Take the dot product of the unit vectors float UnitDot = (DiffVecX*DImpulseX + DiffVecY*DImpulseY);// The impulse is then equal to: float ImpulseX = DiffVecX * UnitDot * DImpulseL; float ImpulseY = DiffVecY * UnitDot * DImpulseL;// Apply the impulse Obj1->VelX += ImpulseX / Obj1->Mass; Obj1->VelY += ImpulseY / Obj1->Mass; Obj2->VelX -= ImpulseX / Obj2->Mass; Obj2->VelY -= ImpulseY / Obj2->Mass;}

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002221
×