#### Archived

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

# collision detection with circle

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

## Recommended Posts

How do I detect a collision with two circles? How do I tell what angle they hit?

##### Share on other sites
quote:
Original post by G a m e D e v
How do I detect a collision with two circles? How do I tell what angle they hit?

If the circles have radiuses r1 and r2, then they hit when their centres are a distance (r1 + r2) apart. You can work out the distance using Pythagoras''s theorem, i.e.

dist = sqrt((x1 - x2)2 + (y1 - y2)2)

where they are at (x1, y1) and (x2, y2)

And they are overlapping, i.e. they have hit, when

dist < r1 + r2

The vector

(x1 - x2)
(y1 - y2)

gives the direction between the circles. There are various angles you can measure, e.g. the angle between this direction and the x axis is given by

angle = arctan ((y1 - y2) / (x1 - x2))

Alternately you can just use the vector as this gives you the direction in a format that can be easily used elsewhere. E.g .the force between the circles if they bounce apart will be along this direction.

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

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631776
• Total Posts
3002299
×