#### Archived

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

# Physics behind Billiard.....

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

## 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 on other sites
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 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 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 on other sites
Slight correction - in think there should be

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

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

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

##### 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 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.

1. 1
2. 2
JoeJ
20
3. 3
frob
16
4. 4
5. 5

• 10
• 10
• 11
• 13
• 9
• ### Forum Statistics

• Total Topics
632196
• Total Posts
3004718

×