Results 1 to 10 of 10

Thread: Find point of intersection/overlaping?

  1. #1
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Find point of intersection/overlaping?

    If I have two QGraphicsItems of some kind, and they are moved to intersect/overlap eachother, is there an easy way to find the point (or region) of intersection?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Find point of intersection/overlaping?

    No really...
    You could use the shapes of the two items( QPainterPaths ) and implement an algorithm for contour intersection (to determine the shape of intersection). But for complex shapes, these algorithms are inaccurate and slow.

    Regards

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Find point of intersection/overlaping?

    Maybe you could approximate the intersection area by intersecting only the bounding rectangles of the two items. I don't know if that is enough, however.

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,713
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Find point of intersection/overlaping?

    All though I haven't done it my self yet, I know that the Graphics View frame work supports it from the box:
    http://doc.trolltech.com/4.2/graphic...rdinate-system
    QGraphicsItem supports collision detection through the QGraphicsItem::shape() function, and QGraphicsItem::collidesWith(), which are both virtual functions. By returning your item's shape as a local coordinate QPainterPath from QGraphicsItem::shape(), QGraphicsItem will handle all collision detection for you. If you want to provide your own collision detection, however, you can reimplement QGraphicsItem::collidesWith().
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Find point of intersection/overlaping?

    ll though I haven't done it my self yet, I know that the Graphics View frame work supports it from the box:
    http://doc.trolltech.com/4.2/graphic...rdinate-system
    Quote:
    QGraphicsItem supports collision detection through the QGraphicsItem::shape() function, and QGraphicsItem::collidesWith(), which are both virtual functions. By returning your item's shape as a local coordinate QPainterPath from QGraphicsItem::shape(), QGraphicsItem will handle all collision detection for you. If you want to provide your own collision detection, however, you can reimplement QGraphicsItem::collidesWith().
    Yes, but in that reimplementation he must compute the intersection shape, because Qt won't provide it.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,713
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Find point of intersection/overlaping?

    Yes, but in that reimplementation he must compute the intersection shape, because Qt won't provide it.
    But isn't that only in case he needs something special?
    Normal collision detection is provided by the frame work - at leaste that is they I dunderstand the docs.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  7. #7
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Find point of intersection/overlaping?

    Yes, yes, but in the end it comes down to actually computing the intersection of two shapes. Qt will only tell you if the collide.

  8. #8
    Join Date
    Feb 2006
    Posts
    209
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Find point of intersection/overlaping?

    The items will probably not intersect very much so I thought of this:

    1) Find smaller and smaller rects that contains the intersected parts
    2) choose the mid point of the rectangle as the point of intersection (yeah, not rocket science, but that migh suffice)

    Then I would start by usign bounding rects for the items, find their intersction, but what should I do in the next step to find smaller rects?

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Find point of intersection/overlaping?

    The items might not necessarily intersect in a point - might be an area, etc.
    But to find the intersection point from the intersection rectangle test each point in the intersection rectangle and see which one belongs to both items. This is your intersection point.

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

    Default Re: Find point of intersection/overlaping?

    The first question should be - "what do you need it for?" - maybe the intersection (which is computation intensive to get) is not needed after all.

Similar Threads

  1. QPainter clipping with precision behind the decimal point
    By Pieter from Belgium in forum Qt Programming
    Replies: 0
    Last Post: 14th March 2007, 13:30
  2. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  3. QT string Find problem
    By kingslee in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2006, 20:45
  4. Replies: 7
    Last Post: 1st August 2006, 21:15
  5. Replies: 17
    Last Post: 31st March 2006, 05:57

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.