home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!bcm!rice!news.rice.edu!dougm
- From: dougm@titan.cs.rice.edu (Doug Moore)
- Newsgroups: comp.programming
- Subject: Re: How to decide if a point is inside a polygon?
- Message-ID: <DOUGM.92Aug28232651@titan.cs.rice.edu>
- Date: 29 Aug 1992 05:26:51 GMT
- References: <7121@bigbird.hri.com.hri.com> <schnitzi.714934670@eola.cs.ucf.edu>
- <1992Aug27.153902@is.morgan.com> <schnitzi.715017774@eola.cs.ucf.edu>
- <1992Aug28.134203@is.morgan.com> <schnitzi.715032142@eola.cs.ucf.edu>
- <thompson.715056569@malthus.econ.umn.edu>
- Sender: news@rice.edu (News)
- Organization: Rice University Computer Science, Houston, Texas
- Lines: 20
- In-Reply-To: thompson@atlas.socsci.umn.edu's message of 29 Aug 1992 02:49:29 GMT
-
- schnitzi@cs.ucf.edu (Mark Schnitzius) writes:
- >You are right; sorry, I misunderstod your earlier point. So how can we
- >get this to work for all cases? Just find a direction to extend the
- >infinite line that doesn't intersect any vertices?
-
- This is not hard to solve. From the point, extend a ray infinitely
- far in the +x direction. Count a side of the polygon if it intersects
- the ray with one of its endpoints strictly below the ray and the other
- on-or-above the ray. If the ray hits a vertex and both sides
- containing that vertex are below the ray, both are counted. If both
- sides are above, neither is counted. If one is above and one is
- below, exactly one is counted. If the segment lies on the ray, it is
- not counted.
-
- This algorithm is O(n), for an n-sided polygon. With O(n)
- preprocessing, inside/outside queries can be answered in O(log n) time
- per query.
-
- Doug Moore
- (dougm@cs.rice.edu)
-