Hi guys,

I want to develop a Billiards game in Java.

I want know methods for detecting Ball-to-Ball collision & further how to deal on a collision?

Please help me guys.

Thank you.

Printable View

- 05-09-2011, 02:16 PMprashantCollision Detection for Billiards game
Hi guys,

I want to develop a Billiards game in Java.

I want know methods for detecting Ball-to-Ball collision & further how to deal on a collision?

Please help me guys.

Thank you. - 05-09-2011, 02:27 PMoliver_watkins
Is this developing in Java2D?

tricky. Maybe create some Ball objects which render to Ovals in the Graphics2D context.

You would have a thread for each ball. Each update of the trajectory should update the painting of the component.

In order to detect 'hits' with other balls, you would have to convert to ellipses to area objects and then see if there are any conflicts.

area1.intersect(area2);

If there are then you need to do a whole lot of trigonomtry maths to figure out the new path. - 05-21-2011, 03:52 AMaltosaxplayer88
All I can say is arrays.

- 06-02-2011, 04:45 AMrdjava
This kind of collision can be called the Circle to Circle Collision, where the distance of both circle's centers are equal or less than the sum of both radii.

the distance formula is the equation to use

D = Math.sqrt( Math.pow(x1 - x2) + Math.pow(y1 - y2) );

this is actually not a great way to do this equation

so you just make it so you don't use Math objects

((x1 - x2) * (x1 - x2)) + ((y1 + y2) * (y1 + y2)) <= ((radius1 + radius2) * (radius1 + radius2))

However, you may want to also look at 2D elastic collisions for accurate collision with 2D physics