Jump to content
• Advertisement

#### Archived

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

# Physics behind Billiard.....

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

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hi, Do you have an idea on how to calculate the velocity and the angle on wich to colliding balls leave after it? I would like to use this for a billiard game. Everything is nearly finished but that. I searched the internet but haven''t found something usefull. Any idea or formular? thanks PS: Don''t know if it was asked before, first time in this forum

#### Share this post

##### Share on other sites
Advertisement
Here''s the code I use in my game (a 2D shooter):

  vect2_t d;v2_dir(&ship1->position, &ship2->position, &d);vect2_t dv = ship1->velocity;v2_sub(&dv, &ship2->velocity);// calculating the impulse as a projection of// ship velocities on the line going through their centres// At least this is what I think I''m doingfloat k = v2_dot(&d, &dv);// projecting it backvect2_t r = d;v2_mul(&r, k);// Adding the impulse (mass = 1, so forget it) to the ship velocitiesv2_sub(&ship1->velocity, &r);v2_add(&ship2->velocity, &r);

Ships are defined as

  struct ship_t{	vect2_t position;	vect2_t velocity;// and so on};

where vect2_t is a 2D vector

  struct vect2_t{	float x;	float y;};

and vector operations used are

  // ugly, but simplevoid v2_add(vect2_t *v1, vect2_t *v2){	v1->x += v2->x;	v1->y += v2->y;}void v2_sub(vect2_t *v1, vect2_t *v2){	v1->x -= v2->x;	v1->y -= v2->y;}void v2_mul(vect2_t *v, float a){	v->x *= a;	v->y *= a;}// make unit vector showing the direction from v1 to v2void v2_dir(vect2_t *v1, vect2_t *v2, vect2_t *d){	float dx = v2->x - v1->x;	float dy = v2->y - v1->y;	float l = sqrt(dx * dx + dy * dy);	d->x = dx / l;	d->y = dy / l;}// dot productfloat v2_dot(vect2_t *v1, vect2_t *v2){	return v1->x * v2->x + v1->y * v2->y;}

It all will work only if the masses of both objects are equal.

#### Share this post

##### Share on other sites
You could use Baraff's paper (use Google), but it covers a lot more than what you want...

Do you know about linear momentum? If you don't, you should Google some info before tackling this problem. The (simplified) equation for collision between spheres is

j = -(1 + coef) * DotProduct(sphere2.speed - sphere1.speed, Normal) / Length(Normal) / (1 / sphere1.mass + 1 / sphere2.mass)

where
coef is the restitution coefficient (user-defined), between 0 and 1
Normal is the vector defined as sphere2.center - sphere1.center

then,

sphere1.speed += j / sphere1.mass * Normal / Length(Normal)
sphere2.speed -= j / sphere2.mass * Normal / Length(Normal)

Very roughly speaking.

Cédric

[edited by - cedricl on December 3, 2002 2:59:36 PM]

#### Share this post

##### Share on other sites
And here''s the equations I used in my code:

Initial data:

v1x, v1y - x and y components of first ball velocity
v2x, v2y - x and y components of second ball velocity

x1, y1 - coordinates of first ball
x2, y2 - coordinates of second ball

m1 - mass of first ball
m2 - mass of second ball

Calculations:

dx = x2 - x1
dy = y2 - y1

rx = dx / (sqrt(dx * dx + dy * dy))
ry = dy / (sqrt(dx * dx + dy * dy))

k = (rx * (v2x - v1x) + ry * (v2y - v1y)) / (m1 + m2)

Updating velocities:

v1x += rx * m2 * k;
v1y += ry * m2 * k;
v2x -= rx * m1 * k;
v2y -= ry * m1 * k;

Actually it appears to be equivalent to equations posted by cedricl, so you can choose either (there''s no restitution coefficient in mine).

#### Share this post

##### Share on other sites
Slight correction - in think there should be

k = 2 * (rx * (v2x - v1x) + ry * (v2y - v1y)) / (m1 + m2)

instead of

k = (rx * (v2x - v1x) + ry * (v2y - v1y)) / (m1 + m2)

#### Share this post

##### Share on other sites
How much do the balls get faster/slower as before?

#### Share this post

##### Share on other sites
collisions are elastic... no speed is lost... granted ball a hits ball b and stops...

If barbie is so popular, why do you have to buy her friends?

#### Share this post

##### Share on other sites
quote:
Original post by llama_beast
collisions are elastic... no speed is lost... granted ball a hits ball b and stops...

I think he means how much does each one increase/decrease by. Because in elastic collisions, momentum and energy in the system does not change, but the speed, momentum and energy(kinetic) of each ball does change.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633409
• Total Posts
3011722
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!