1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Does a circle overlap a square?

  1. Dec 18, 2008 #1
    Hello,

    We are trying to calculate if a circle, of a given x, y co-ordinate and radius, will overlap a square, of a given x, y co-ordinate and length.

    We think we can identify points around the circumference and see if these points, with an x and y value, will be within the square. However this requires numerous calculations and we want to achieve a definitive yes or no in one calculation.

    Thank you for giving this some thought.
     
  2. jcsd
  3. Dec 18, 2008 #2

    Hootenanny

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Welcome to Physics Forums,

    HINT: Try calculating the shortest distance from the centre of the circle to the boundary of the square. How does this compare with the radius of the circle?

    As an aside, all homework or textbook style questions should be posted in the Homework forum. I'll move this thread there now.
     
  4. Dec 19, 2008 #3
    let c be the center of the circle
    let s be the center of the square.
    let r be the radius of the circle
    let x be the length of a side of the square.
    let d be half the diagonal of the square.

    if |c-s| > r + d you can rule out a collision.
    if |c-s| < x you certainly have a collision.
    if x < |c-s| < r + d you *might* have a collision.

    The last one is a bit tricky. If you point a vector from c towards s, you can use that to get the quarter of the circle which points towards the square, and check each of those points individually. It sucks, I know, but at least you only check 1/4 of the total points.

    Since both the circle and the square are very simple shapes, there might be some trig that can figure this out without checking individual points on the circle. If it is, it eludes me at the moment.

    You might want to google "collision detection" and read up. This is a very common type of problem in game programming.

    k
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?