let us, for a moment, consider a ball, and how we would represent one in a C++ struct or class...
personally, i would do it this way...
struct Coordinate2d
{
double x;
double y;
};
struct Ball
{
Coordinate2d Position;
Coordinate2d Velocity;
double Radius;
};
there could be more, but this simple model will let us do most of the physics we want to, (minus the really icky stuff dealing with spin and rotational effects)
we will further simplify our model by saying that there are no frictional effects.
and so, based on two balls with current positions, and current velocities, we know the following.
at time t, the position of a ball is
x=x0+dx*t, y=y0+dy*t, where x0,y0 is the original position, dx, dy representing the velocity of the ball, and t the time elapsed.
also, we know that the balls collide when the distance between them is the sum of their radiuses.
the distance formula: a*a+b*b=c*c
where a is the difference in x positions, and b is the difference in y positions, and c is the distance
so, for two balls, BallA, and BallB, here are some more equations:
(BallA.Radius+BallB.Radius)*((BallA.Radius+BallB.Radius)=( (BallA.Position.x+BallA.Velocity.x * t)-(BallB.Position.x+BallB.Position.x * t) ) * ( (BallA.Position.x+BallA.Velocity.x * t)-(BallB.Position.x+BallB.Position.x * t) ) + ( (BallA.Position.y+BallA.Velocity.y * t)-(BallB.Position.y+BallB.Position.y * t) ) * ( (BallA.Position.y+BallA.Velocity.y * t)-(BallB.Position.y+BallB.Position.y * t) )
now, you do a lot of expansion, and a lot of plugging and chugging, then you have to solve for t using the quadratic equation. if the solution for t is imaginary, then a collision will never occur. if there is a negative solution, ignore it. only a positive, real solution matters. if you have a positive, real solution, then the collision will occur at that time.
when a collision occurs, assuming a totally elastic collision, impart all of the momentum on one ball on the opposite ball, and the job is done.