Results 1 to 7 of 7

Thread: need help on how to detect overlapping circles

  1. #1
    Join Date
    Jan 2011
    Location
    Pearl of the Orient Seas
    Posts
    40
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default 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:

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: need help on how to detect overlapping circles

    Are you asking about an algorithm?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2011
    Location
    Pearl of the Orient Seas
    Posts
    40
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: need help on how to detect overlapping circles

    yes, please.

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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    aya_lawliet (10th October 2011)

  6. #5
    Join Date
    Jan 2011
    Location
    Pearl of the Orient Seas
    Posts
    40
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default Re: need help on how to detect overlapping circles

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

  7. #6
    Join Date
    Jan 2011
    Location
    Pearl of the Orient Seas
    Posts
    40
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows Symbian S60 Maemo/MeeGo

    Default 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. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    aya_lawliet (20th October 2011)

Similar Threads

  1. Replies: 0
    Last Post: 14th November 2010, 14:36
  2. Replies: 1
    Last Post: 9th August 2010, 20:44
  3. editable rectangles
    By parmar ranjit in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2008, 10:59
  4. Rendering rectangles speed issue
    By macbeth in forum Qt Programming
    Replies: 11
    Last Post: 15th March 2007, 02:30
  5. Replies: 4
    Last Post: 17th January 2006, 18:46

Bookmarks

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.