Results 1 to 3 of 3

Thread: Point in a Polygon

  1. #1
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Point in a Polygon

    Hello All,

    I would like to check if a point is located inside a polygon or not ?

    so I'm using

    bool QPolygon::containsPoint ( const QPoint & point, Qt::FillRule fillRule ) const

    but this method will ignore points that are located on the line of the polygon, so is there a way to include them ??

    Thanks
    Last edited by jesse_mark; 15th July 2013 at 20:04.

  2. #2
    Join Date
    Jun 2012
    Posts
    173
    Thanks
    48
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Point in a Polygon

    anyone can help with that ??
    i find this the way that contains works, as in this thread.
    but does anyone have an idea how we can solve this ??

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Point in a Polygon

    Quote Originally Posted by jesse_mark View Post
    but this method will ignore points that are located on the line of the polygon, so is there a way to include them ??
    Your starting assertion is not universally true.
    Qt Code:
    1. QPolygon poly;
    2. poly << QPoint(0, 0) << QPoint(0, 10) << QPoint(10, 10) << QPoint(0, 0);
    3. QPoint test(0, 5); // on the boundary
    4. qDebug() << poly.containsPoint(test, Qt::OddEvenFill); // true
    5. qDebug() << poly.containsPoint(test, Qt::WindingFill); // true
    6. test = QPoint(0, 10); // corner of poly
    7. qDebug() << poly.containsPoint(test, Qt::OddEvenFill); // false
    8. qDebug() << poly.containsPoint(test, Qt::WindingFill); // false
    9. test = QPoint(5, 5); // mathematically on the diagonal
    10. qDebug() << poly.containsPoint(test, Qt::OddEvenFill); // false
    11. qDebug() << poly.containsPoint(test, Qt::WindingFill); // false
    To copy to clipboard, switch view to plain text mode 
    There are edge cases where fixed precision or integer mathematics is involved.
    http://www.wikipedia.org/wiki/Point_in_polygon
    The algorithms in Qt are adequate for Qt's uses. If you need an alternate implementation with different idiosyncrasies then you will need to code it yourself or find an library that provides it.

Similar Threads

  1. Points in Polygon
    By jesse_mark in forum Qt Programming
    Replies: 2
    Last Post: 27th September 2012, 20:58
  2. Replies: 13
    Last Post: 25th January 2012, 05:52
  3. Draw polygon in QML
    By tuxit in forum Qt Quick
    Replies: 0
    Last Post: 27th July 2011, 15:13
  4. pixmap to polygon
    By mhoover in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2009, 09:02
  5. Rotating the polygon
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 4th September 2008, 00:41

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.