# Circle Collision detection

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

## Recommended Posts

Hello, I am trying to figure out collision detection with a circle. I found out the formula for getting distance between two points. The way is very basic and it only happens if the two points are exactly on each other. How would I go about checking all the points of the circle? I think that checking all the points would be a waste of processor time. Is there another way I could detect if one point on one circle is in another circle, or rectanlge or triangle?

##### Share on other sites
Circle-Circle Intersection on Mathworld - It should explain how to.

It's very easy actually, you first find the distance between the two centerpoints.
dy = y' - y //dif y-axisdx = x' - x //dif x-axisdist2 = dx*dx + dy*dy //Pythagoras algorithm

You now have the distance squared, but that doesn't matter. For speed you just square the radii also.
sumr = r + r' //allowed distance (radius + radius')if(dist2 < sumr*sumr) collision = true

##### Share on other sites
Ok i got the circles to work, what about circles and squares, and triangles.

##### Share on other sites
(Finite) Line-Circle Intersection is a topic I posted to ask how it could be implemented.
As you can read in the last reply, I confirmed jyk's method was working, so that's the first step of having Circle-Rectangle/Triangle collision. The obvious next step would be using that (Finite) Line-formula for each of the edges in those primitives. Repeat 4 time for Rectangles, and 3 times for Triangles.

Perhaps there is a faster way, but this sure works for me.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 13
• 12
• 15
• 11
• 12
• ### Forum Statistics

• Total Topics
634153
• Total Posts
3015844
×