Point between the two polygons, how to find what it belongs to?
Which algorithm to use so that we can determine if the red point belongs to Area1 or Area2. my initial idea was to divide polygons into triangles using consecutive points and then use a known algorithm to determine if a point belongs to one of these triangles, however there is a problem shown in the picture. p4 p5 p6 are points in Region 1, but they make a triangle in Region 2.
source to share
For this you can use the idea of ββthe polygon filling algorithm. If you know the vertices of the polygon, you can trace a horizontal ray through the red point and count the vertices that it crosses. If the count is even, it is outside, otherwise it is inside.
If you imagine that you are exiting the left edge of that ray, the first intersection enters the polygon, the second exits, the third enters again ... and so on. So if the number is odd (1,3,5, ...) you hit the polygon when you hit the point, otherwise you are outside.
source to share