# Thread: need help on how to detect overlapping circles

1. ## need help on how to detect overlapping circles

Hi,

I need help on how to detect overlapping rectangles..

Basically, what I want to do is, I have a gameboard with a lot of circles that can be dragged. If 4 of the circles overlaps one another, then I will turn those four circles into a rectangle. If I drag a circle and drop it at some point intersecting another 3 circles, then the 4 circles will automatically turn into rectangles.

I need help in how to determine if 4 circles, in a gameboard of many circles, overlaps or intersects one another. Can anyone kindly please help me on how to do it? Or could you please point me to any direction? I am limited to using QML and javascript if that is possible.

Thank you very very much in advance for any help that will be provided. C:

3. ## Re: need help on how to detect overlapping circles

I just hope that it can be implemented using QML and javascript. thank you.

4. ## Re: need help on how to detect overlapping circles

Two circles partially or fully overlap if the distance between their centres is less or equal to the sum of radiuses of both circles. Euclidean distance between two points is calculated as a square root of a sum of squares of distances of the centres in each direction: d = sqrt( |x2-x1|^2 + |y2-y1|^2 ).

Thus if you want four circles to overlap the above condition has to apply to each pair of the tested group of circles.

5. ## The following user says thank you to wysota for this useful post:

aya_lawliet (10th October 2011)

6. ## Re: need help on how to detect overlapping circles

Thank you very much wysota, for the formula. I will try that.

7. ## Re: need help on how to detect overlapping circles

Hi all,

I want to thank wysota for the formula, your help is very much appreciated.

BTW, I have found another solution to this problem, by using QGraphicsItem::collidingItems.

Since QDeclarativeItem( elements of QML ) class inherits QGraphicsItem, I can use the collidingItems method to determine the items that collides with a certain QML element.

I created a separate qt class, that uses QGraphicsItem::collidingItems. And I exposed this class to QML. I passed the QML element as parameter to the c++ function and it returns the items that collides with the QML element.

I am just happy to share my findings I hope this will be able to help someone

8. ## Re: need help on how to detect overlapping circles

Just be aware that collidingItems will be much slower as it doesn't understand the concept of circles. It has to compare polygons.

9. ## The following user says thank you to wysota for this useful post:

aya_lawliet (20th October 2011)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.