PDA

View Full Version : need help on how to detect overlapping circles



aya_lawliet
8th October 2011, 21:25
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:

wysota
9th October 2011, 17:21
Are you asking about an algorithm?

aya_lawliet
9th October 2011, 17:37
yes, please.

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

wysota
9th October 2011, 17:55
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.

aya_lawliet
10th October 2011, 06:35
Thank you very much wysota, for the formula. I will try that.

aya_lawliet
20th October 2011, 07:18
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 :)

wysota
20th October 2011, 08:47
Just be aware that collidingItems will be much slower as it doesn't understand the concept of circles. It has to compare polygons.