# Circle Collision detection

## 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 this post

##### 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 this post

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

#### Share this post

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

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now

• ### Forum Statistics

• Total Topics
627722
• Total Posts
2978804

• 10
• 9
• 21
• 14
• 12