The key thing to remember here is that you just need to distill this down into the possible cases. What are the different things that can happen?

- The circle can be outside the rectangle (no collision).

- The circle can touching one of the vertices of the rectangle only.

- The circle can be touching one of the sides of the rectangle.

- The circle can be touching any number of sides as well as any number of vertices.

- The rectangle can lie inside the circle.

- The circle can lie inside the rectangle.

Calculating every single one of those would take a lot of time, thinking, and waste a lot of cycles, but you would probably be able to figure out a way to do each step if your geometry is pretty good. But after doing them all you'd probably realize that there are a lot of redundant cases there.

- If the circle is touching just one vertex, that means that it's also touching two different line segments.

- if the circle is touching multiple sides or vertices, then you should only need to check the first side it's touching and then know there is collision.

- If the rectangle lies inside the circle, then that's equivalent to all 4 sides touching the circle.

So that simplifies us to:

- The circle can be outside the rectangle (no collision).

- The circle can be touching one of the sides of the rectangle.

- The circle can lie inside the rectangle.

We don't need to worry about checking for the first case, because we know if either of the last two cases are true then the first case can't be true. So that leaves just two.

- The circle can be touching one of the sides of the rectangle.

- The circle can lie inside the rectangle.

And to simplify even more, you know that the circle lies inside the rectangle, if it gets too close to a side then that means that it will intersect that side, so all you really need to do is see if the center of the circle lies inside the rectangle - its radius doesn't even matter.

Google should be able to tell you how to do circle/segment collision (essentially you see if the radius segment that is perpendicular to the line segment intersects the line segment), and also how to find whether or not a point lies inside a rectangle (compare 4 dot products for the perpendiculars of each line, basically).

Or, have a look here:

http://stackoverflow.com/questions/401847/circle-rectangle-collision-detection-intersectionhttp://local.wasp.uwa.edu.au/~pbourke/geometry/sphereline/http://stackoverflow.com/questions/2752725/finding-whether-a-point-lies-inside-a-rectangle-or-not