• Status: Solved
• Priority: Medium
• Security: Public
• Views: 427

# How to identify x,y coordinates that lie within a closed polygon whose vertices are defined by x,y coordinates

I have a set of shapes in a field, each with known x,y coordinates, height and width.

I wish to select a subset of these shapes whose centres lie within a closed polygonal line with known coordinates to its vertices.

I program in  VBA and unfortunately am not multi-lingual. However, given the principles, I'd hope to progress to write it in vba.

Thanks!
Kelvin4

0
Kelvin4
• 2
3 Solutions

Sr. System AnalystCommented:
0

Middle School Assistant TeacherCommented:
You could use GDI objects.  Create a Region from your known vertices then hit-test with PtInRegion():
http://msdn.microsoft.com/en-us/library/dd183511(VS.85).aspx
http://msdn.microsoft.com/en-us/library/dd162883(VS.85).aspx
0

Sr. System AnalystCommented:
from page above:

Ray casting algorithm

The number of intersections for a ray passing from the exterior of the polygon to any point, if odd, shows the point lies inside the polygon. If the even, the point lies outside the polygon; this test also works in three dimensions.
One simple way of finding whether the point is inside or outside a simple polygon is to test how many times a ray starting from the point intersects the edges of the polygon. If the point in question is not on the boundary of the polygon, the number of intersections is an even number if the point is outside, and it is odd if inside.
0

Author Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.