Points and Regions

Hi guys,

I have a graphics question, that might not necessarily have anything to do with Flash, but I thought the people here might be able to help anyways. This is strictly a theory question, and may come up in a Flash project.

I have an image, lets say 100x100, and i have regions [polygons] being drawn on the image from a database of coordinates and these regions also become an image map. Now I have no problem with this, but I do have a set of points that also have co-ordinates, that I have to display, if their region is clicked on.

Lets take a simple example: I have a region mapped by 4 points:
(0,0) (0,10) (10,0) (10,10)
Now, it’s easy to test whether a point will fall into this region.
A point, (5,5) will, and a point (11,11) will not. The test is simple… the region is a rectangle, test X ranges and Y ranges.

My problem is that my regions are not rectangles. They are complicated shapes that follow no pattern. Lets say one of these regions is a triangle with co-ordinates:
(0,0) (10,0) (5,10)
Which will look like:

…(0,0) _________ (10,0)
…--------/
…------/
…—/
…/ (5,10)

Now, it is clear that a point (4,10) or (6,10) will not fall into this region. But what about a point (4,9) or (4,6) … will that? And the shape can be anything, a star, a decagon, anything. Is there an algorithm anyone can provide (or get me started on) or a class that can check regions for points?

Thanks guys
GLOG