# point inside rect

I have a rectangle of size l*b where one edge is present at p0 and opposite at p1. How do i check if a point/pixel pi is inside this rectangle or not?

edit retag close merge delete

Sort by » oldest newest most voted

you can use contains method too

more

you should compare your point x and y coordinates with rectangle points, so if the p0 is the top-left vertex of the rectangle and p1 bottom-right then

 1. p0 x coordinate < point x < p1 x coordinate
2. p0 y coordinate < point y < p1 y coordinate


if those conditions are satisfied then the point is inside the rectangle

more

the rectangle is present at some angle with x axis i.e it is not parrallel to any axix.

1

in this case, I suggest creating a contour from that rectangle points which seems possible (see here ) and then use pointPolygonTest. pointPolygonTest function determines whether the point is inside a contour, outside, or lies on an edge (or coincides with a vertex). It returns positive (inside), negative (outside), or zero (on an edge) value, correspondingly. (see here)

Official site

GitHub

Wiki

Documentation