Ask Your Question
2

point inside rect

asked 2020-01-22 14:21:21 -0600

dineshlama gravatar image

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2020-01-23 02:38:19 -0600

LBerger gravatar image

you can use contains method too

edit flag offensive delete link more
1

answered 2020-01-23 01:02:56 -0600

Lucy8 gravatar image

updated 2020-01-23 01:05:23 -0600

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

edit flag offensive delete link more

Comments

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

dineshlama gravatar imagedineshlama ( 2020-01-23 01:51:11 -0600 )edit
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)

Lucy8 gravatar imageLucy8 ( 2020-01-23 02:12:40 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-01-22 14:21:21 -0600

Seen: 6,339 times

Last updated: Jan 23 '20