[VB.NET]
Given:
[1] One (x,y) coordinate pair (Double values)
and
[2] One array of (x,y) coordinate pairs (structs containing 2 Doubles) that together define a closed polygon that does NOT intersect itself
I need to determine whether [1] falls within the area defined by [2].
Is there anything out there I can use for this? I need something free. Sample code or good pseudo code, please.
Thanks very much!
The simplest technique is to first determine the artifical centroid of polygon (based upon average x and y values). It may not be the true centroid, since it might fall outside the polygon. Then work two areas calculations simulaneously, one set of calculations is the sum of the area of a set of triangles based upon your reference point and 2 points along the polygon. The other set is based upon the artificial centroid. As you work around the perimeter of the polygon (2 points at a time), you're summing the areas of the triangles. This will essentially give you two different calculations for area of the polgyon.
If the reference point's calculated sum is less than or equal to that of the centroid, then it's within the polygon.
A more involved approach takes complex shapes into account and allows for "inversion" of the shape. The technique is the same, it's just how you deal with inversions while summing the intermediate values.
Sorry I don't have any reference material with me