Detecting overlapping circles on canvas

I have a Canvas on which I draw concentric circles. Every circle is a class and is drawn by the Paint event controlled by a timer tick. X,Y and Width properties are maintained in the class. A randomizer controls the movement of the circles, so they wander freely over the Canvas. Every object is stored in an Array. So in the array I can loop over all objects and see their X,Y and Width properties.

What I want to do is to detect when an object is touching another object and fire some other methods when this occurs. Does anybody know how to do this?

There is a touch between 2 circles if the distance between their centers is less than or equal o the sum of theirs width / 2.

Hope this helps

1 Like

Yes ofcourse. Thx. But that is a very complex loop to verify every object against every other object. I’ll see what this means in response time. Thanks.

You might be able to limit how many comparisons you perform.

For example:
• divide the window bounds into 4 sections
1 2
3 4
• find the objects that are partially or entirely within a section
• compare those objects against each other

I tested… speed is no issue… it works