Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Determining if point is within a polygon

RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
03-27-2007 11:22
I'll simplify this question to just assume a 2D flat polygonal area.

Let's say I have a set of points (vectors). Together, they are the corners of a polygon (or just a funky 4 sided area). And I have them in the order they were defined, so that is the order they connect. And I can assume that the sides (lines) between them do not criss-cross.

How do you determine if a new point (i.e., a person's position) is within or outside this area?

I know that if the application were confined enough, I could make an object and use something like llVolumeDetect. But I'm trying to do this for arbitrary sizes and larger areas than an object can cover, and make it defined by points like this rather than by sensor arcs.

Thanks for any help.

Rj
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
03-27-2007 11:30
One of the best treatments available on the web is the Point in Polygon Strategies article from the Graphics Gems series.

If you intend to do a lot of work with such things, the bool "Real-Time Collision Detection" by Christer Ericson is the single best book I can think of, with excellent code samples and very accessible and easy to understand explanations.
_____________________
Ralph Doctorow
Registered User
Join date: 16 Oct 2005
Posts: 560
03-27-2007 12:09
I'm certainly not an expert, but isn't the standard scheme something like creating a vector passing through the midpoint of an edge, then seeing how many other edges it intersects?

If there are an even number of intersections you're outside, odd number you're inside.
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
03-28-2007 06:44
Thanks all for the ideas and the references.

For now, I think the bounding computations will work for my application (i.e., if they are outside the bounding area, then they are also outside the polygon). If I need to tune that better, I will look more into those other ideas (and the odd vs even line crossing).

Rj