View Full Version : Point in a Polygon
jesse_mark
15th July 2013, 17:26
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
jesse_mark
30th July 2013, 20:32
anyone can help with that ??
i find this the way that contains works, as in this (https://bugreports.qt-project.org/browse/QTBUG-28566) thread.
but does anyone have an idea how we can solve this ??
ChrisW67
31st July 2013, 00:49
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.
QPolygon poly;
poly << QPoint(0, 0) << QPoint(0, 10) << QPoint(10, 10) << QPoint(0, 0);
QPoint test(0, 5); // on the boundary
qDebug() << poly.containsPoint(test, Qt::OddEvenFill); // true
qDebug() << poly.containsPoint(test, Qt::WindingFill); // true
test = QPoint(0, 10); // corner of poly
qDebug() << poly.containsPoint(test, Qt::OddEvenFill); // false
qDebug() << poly.containsPoint(test, Qt::WindingFill); // false
test = QPoint(5, 5); // mathematically on the diagonal
qDebug() << poly.containsPoint(test, Qt::OddEvenFill); // false
qDebug() << poly.containsPoint(test, Qt::WindingFill); // false
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.