How does one determine whether one or more points lie within an area whose boundary is given? For instance, in the following figure, three blue points lie within the area bounded in red, two red points lie within the area bounded in blue, and there are three points - two blue and one red - which do not lie within either of the indicated areas.
Asked
Active
Viewed 5,366 times
1
-
1Search Google for Point in Polygon algorithms and you'll find a few. – Jackson Pope Aug 18 '11 at 15:19
-
1possible duplicate of [C# Point in polygon](http://stackoverflow.com/questions/4243042/c-point-in-polygon) – Jens Aug 18 '11 at 15:21
-
Have you some math definition of your polygons? In other words: is tgere any formula that you have that can describe them? – Tigran Aug 18 '11 at 15:22
-
Thank you, Jens, it seems that I need – Topol-M Aug 18 '11 at 18:23
3 Answers
2
Draw a line from the point. check if it crosses any of the region edges and what side of the line it is.
If it crosses them odd number of times on each side it is in the region.

Daniel
- 30,896
- 18
- 85
- 139
-
Not really true in case of concave surfaces. If you immagine a point out of the polygon but inside a "cave" , drawed line will cross polygon but continue to be out of it – Tigran Aug 18 '11 at 15:45
-
@Tigran, but again, it will first cross the cave wall, and then cross the polygon wall again on the way out which makes it 2 crosses which is not an odd number. – Daniel Aug 18 '11 at 15:48
-
You can immagine that that immaginary line will cross 2 times on one side and 1 time exactly on vertex of the polygon. Just touching it... – Tigran Aug 18 '11 at 15:50
-
@Tigran, if its touching a vertex if will cross both lines that make that vertex. for that there should be a special case that is not too hard to think of. – Daniel Aug 18 '11 at 15:56
1
I don't know the "algorithm" to do this, but in C# (.NET framework) you could do it with Region.IsVisible
method of the class Region. You can create a custom region using GraphicPath constructor. A GraphicPath itself could be constructed by a Point array.

Ehsan88
- 3,569
- 5
- 29
- 52