#### Archived

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

# Balls collision...

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

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
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.

##### Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 10
• 16
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632929
• Total Posts
3009276
• ### Who's Online (See full list)

There are no registered users currently online

×