• Create Account

## Balls collision...

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1mattiasakerman  Members

122
Like
Likes
Like

Posted 16 December 1999 - 01:00 AM

Hello... Do anyone know where to find some good formulas and physics about balls/spheres colliding in 2D? This shouldn't be so hard.. But I can't find any information about it and I can't figure it out myself.

### #2SonicSilcion  Members

122
Like
Likes
Like

Posted 13 December 1999 - 02:53 AM

Just search this message board!
__On the top, right there's a search option. Click and enter "collision" for your search work and "Topics" for where to search, then start the search. There's one called "Collision physics", or something like that, that should be more than adequet. You can also check the other results if you still want more info.

-Good Luck!-
-SonicSilicon

### #3 Anonymous Poster_Anonymous Poster_*   Guests

Likes

Posted 15 December 1999 - 06:13 PM

Testing if 2 circles intersect is very easy, you just need to store the position of the center of each circle and the size of its radius. To test if 2 circles intersect, first add the 2 radiuses together, and if the distance between the 2 points is less than this, it intersects. To test if 2 circles intersect over a small period of time, you can create 2 lines from the start and end points of the circles, then you need to check if the lines ever come closer than the sum of the radiuses, i cant remember the exact formula off the top of my head, but im sure someone will know.

### #4TANSTAAFL  Moderators

1160
Like
Likes
Like

Posted 16 December 1999 - 01:00 AM

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;
};

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.