Help me with the math of two spheres colliding
I'm making a flash game, where I want two circular objects to collide in a half-way realistic fashion, like pool-balls.
As I understand it, when two equal-mass balls collide, assuming a perfectly elastic collision, then the two balls will switch momentum along an axis formed by their relative positions.
So what I have for variables is:
x1 y1 : the position of ball 1
x2 y2 : the position of ball 2
sx1 sy1 : the velocity of ball 1
sx2 sy2 : the velocity of ball 2
I want to be able to calculate what sx1 and sy1 should be after a collision. (And likewise for sx2 and sy2, but it would be the same method for both balls)
So, by subtracting x1 and y1 from x2 and y2, I get
tx ty : the position of ball 2, relative to ball 1
I need to represent sx1 and sx2 with two vectors, one parallel to [tx,ty] and one perpendicular.
sx1 = tx*A + ty*B
sy1 = ty*A - tx*B
A is the parallel and B is the perpendicular.
If I can solve for A and B, then I can replace the A from ball1 with the A from ball2, and vice-versa, and my new values would be:
sx1 = tx*A2 + ty*B1
sy1 = ty*A2 - tx*B1
Is this a good approach?
Plus it's been a few years since I've done serious math, so I don't remember all the tricks to isolate A and B. So far I've got this far:
sx1=tx*A - ty*sy1/tx + ty^2*A/tx
You can download the example files for the book here. Specifically, you want file ch19_13.fla. That file demonstrates collisions between same-mass objects.
Good luck.
posted by thinman at 3:16 PM on June 10, 2007