# Thread: Collision Detection for Billiards game

1. Member
Join Date
Dec 2008
Posts
19
Rep Power
0

## Collision 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?

Thank you.

2. Member
Join Date
May 2011
Location
Munich
Posts
15
Rep Power
0
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.

3. All I can say is arrays.

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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•