RE: [Algorithms] collision reaction
Brought to you by:
vexxed72
From: Kimberly P. <kim...@3d...> - 2001-08-31 19:33:04
|
> > hi, > > I'm trying to simulate collision reaction between two balls > (circles) in 2d. > I want to simulate transfer of energy between the two balls. > I have a simple > simulation running, but it seems to gain energy. > > I probably have this all wrong, if so, could anyone tell me > where to find > information on how to solve this problem properly? > > this is the code I have so far, it's called when a collision > between two > balls is detected. > > > // get collision normal > Vector normal = pBall1->position - pBall2->position; > normal.Normalise(); > > // get dot product of ball1 velocity and collision normal > Vector normVel1 = pBall1->velocity.Normalised(); > float dot1 = (normVel1.x * normal.x) + (normVel1.y * normal.y); > > //calculate amount of energy transmitted from ball1 to ball2 > Vector transmit1 = normal * (pBall1->velocity*dot1).Magnitude()); > > // negate collision normal; > normal.x = -normal.x; > normal.y = -normal.y; > > // get dot product of ball2 velocity and collision normal > Vector normVel2 = pBall2->velocity.Normalised(); > float dot2 = (normVel2.x * normal.x) + (normVel2.y * normal.y); > > //calculate amount of energy transmitted from ball2 to ball1 > Vector transmit2 = normal * (pBall2->velocity*dot2).Magnitude()); > > //subtract transmitted energy from current velocities > pBall1->velocity-=transmit2; > pBall2->velocity-=transmit1; > > thanks, > > robert > > Here is a link to a site with a good discussion of the dynamics of two colliding objects. http://www.d6.com/users/checker/dynamics.htm Kim |