How could I calculate if the XY coordinate is in a specific area?
So let's imagine that I have a 10x10 grid (can be any size, but just say 10 for example), and with this grid, there are 3 points denoting the vertices of the triangle (again, there can be any number of points bounding an arbitrary shape).
So my question is, is there a way that gives exactly this information to determine programmatically if any given coordinate is inside this shape?
Let's say the coordinates are 3.2-7.3-5.5. Can I, while iterating over the given grid, select the cells that fall into these points?
source to share
Call P by the point you are checking and S 1, S 2, ..., S n n vertices shape.
Suppose that P ≠ S i for all i.
- Is P on the border?
- If 1 is not present, then arbitrarily choose the line L passing through P
- Select point F you know outside the polygon
- Follow the sequence of intersections of L with the shape from F until you press P (call the sequence F, ..., P)
- Count the sequence F, ..., P, store the value in M
- If M is even then P is in a polygon, otherwise P is not in a polygon
NOTE. By entering the starting point F, we will change the parity specified in the point in the description of the polygon algorithm on wikipedia
source to share