home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!cs.ucf.edu!schnitzi
- From: schnitzi@cs.ucf.edu (Mark Schnitzius)
- Subject: Re: How to decide if a point is inside a polygon?
- Message-ID: <schnitzi.715017774@eola.cs.ucf.edu>
- Sender: news@cs.ucf.edu (News system)
- Organization: University of Central Florida
- References: <7121@bigbird.hri.com.hri.com> <schnitzi.714934670@eola.cs.ucf.edu> <1992Aug27.153902@is.morgan.com>
- Date: Fri, 28 Aug 1992 16:02:54 GMT
- Lines: 46
-
- berlin@is.morgan.com (Alexander Berlin) writes:
-
- >In article <schnitzi.714934670@eola.cs.ucf.edu>, schnitzi@cs.ucf.edu (Mark Schnitzius) writes:
- >|> mps@sparc68.hri.com (Mark Stockley) writes:
- >|>
- >|> >I am in need of an algorithm to compute whether or not a given
- >|> >point exists within or without a polygon. Any help or pointers to
- >|> >where to look would be much appreciated.
- >|>
- >|> If I remember right the trick is to extend a line from the point
- >|> infinitely in any direction (say, up). Count how many of the
- >|> polygon's edges this line passes through. If it passes through
- >|> an even number of polygon edges (including zero) the point is
- >|> outside of the polygon. An odd number indicates the point is
- >|> inside the polygon.
-
- >Correct, but a word of caution should be said.
- >When drawind the line in any direction, you want to avoid
- >crossing corners of the polygon. So, make sure no one of the given points
- >(that make polygon) belongs to the line.
-
- > A B
- > .___________.
- > \ /
- > \ Y. /
- > \ | /
- > X \ | /
- > .________\|/___________________
- > |
- > | C
- > |
-
- >In the above example X is outside triangle ABC, Y is inside it. Their lines
- >exactly the same crossings whith the edge. So instead of coming up with
- >additional complicated rules just make sure you don't hit the corners.
-
- Well, one solution to this problem is this: consider each vertice of the
- polygon as belonging to only _one_ of the line segments it is connected to.
- So in the above example, only consider point C to be on the line segment
- BC and not on AC. Then if the line you're drawing goes through point C,
- it is only considered to have gone through line segment BC and not AC.
- This simple fix should clear up any problems.
-
- Mark Schnitzius
- schnitzi@eola.cs.ucf.edu
- University of Central Florida
-