0

I have a set of points (std::pair of double) on a 2D plan and I want to apply a mask (wich is a closed contour : square, circle, polygon...) to it. If a point is contained by the mask (or under the mask), it does not appear, otherwise it appears.

For example, if the mask is a rectangle with (m_x,m_y) the coordinates of its top-left corner and m_width and m_height its width and height, a point would be contained in the mask (and should not appear) if :

if (x >= m_x && x <= m_x + m_width && y >= m_y && y <= m_y + m_height) 
        return true;

For simple shapes (rectangle, circle) it is not that difficult, but how would you do it/what would you use to consider more difficult shapes like polygons ? Is Qt (5.6) doing that ? Or should I use something like OpenCv ?

EDIT 1

Qt can do it with the QPolygonF class (thanks Aurélien) but do you know if the std is doing that ? We implemented our data libraries without any other library than the std, if we can continue it would be great, if not it's not a problem.

Pierre
  • 1,162
  • 12
  • 29
ElevenJune
  • 423
  • 1
  • 4
  • 21

1 Answers1

3

You can use the QPolygonF class.

There is a QPolygonF::containsPoint method.

Edit

I don't know any std way to do that, but it's simple to implement :

Point in Polygon Algorithm

http://www.codeproject.com/Tips/84226/Is-a-Point-inside-a-Polygon

Community
  • 1
  • 1
Aurelien
  • 1,032
  • 2
  • 10
  • 24
  • There is also `QPainterPath` that can combine multiple shapes (including ellipses) and also has `contains` method. – Pavel Strakhov May 18 '16 at 14:01
  • See http://stackoverflow.com/questions/1119627/how-to-test-if-a-point-is-inside-of-a-convex-polygon-in-2d-integer-coordinates You can implement it yourself. Be careful of that special cases – Cristi May 26 '16 at 04:59