Reputation: 1669
So lets imagine that I have a grid of 10x10 (can be any size, but just for the sake of example say 10), and with that grid there is 3 points marking vertexes of a triangle (again can be any amount of points delimiting any arbitrary shape).
So my question is.. Is there a way given just this information to determine programatically if any given coordinate is within that shape?
Lest say the coordinates are 3,2-7,3-5,5. Can I while iterating over the given grid pick out the cells that fall within these points?
Upvotes: 3
Views: 1376
Reputation: 5167
Call P the point that you are checking, and S1,S2,...,Sn the n vertices of the shape.
Assume that P ≠ Si for all i.
NOTE: By introducing the starting point F, we change the parity mentioned in the point in polygon algorithm description on wikipedia
Upvotes: 2