Does a circle overlap a square?

Click For Summary
SUMMARY

This discussion focuses on determining whether a circle overlaps with a square using mathematical calculations. The key approach involves calculating the shortest distance from the center of the circle to the boundary of the square and comparing it with the circle's radius. The conditions established are: if the distance exceeds the sum of the radius and half the diagonal of the square, there is no collision; if the distance is less than the side length of the square, a collision is confirmed; and if the distance falls between these two values, further checks are necessary. The discussion also suggests exploring collision detection techniques commonly used in game programming.

PREREQUISITES
  • Understanding of basic geometry concepts, specifically circles and squares.
  • Familiarity with vector mathematics and distance calculations.
  • Knowledge of collision detection algorithms in game programming.
  • Basic trigonometry to explore potential optimizations.
NEXT STEPS
  • Research "collision detection algorithms" to understand various methods used in game development.
  • Study "distance formulas in geometry" to solidify understanding of point-to-point distance calculations.
  • Learn about "vector mathematics" to apply vector operations in collision detection scenarios.
  • Investigate "trigonometric optimizations" for simplifying calculations involving circles and squares.
USEFUL FOR

This discussion is beneficial for game developers, mathematicians, and anyone interested in computational geometry or collision detection techniques.

TDC-Studio
Messages
1
Reaction score
0
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.
 
Physics news on Phys.org
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.
 
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
 

Similar threads

  • · Replies 62 ·
3
Replies
62
Views
10K
Replies
20
Views
4K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
3
Views
3K