home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.programming
- Path: sparky!uunet!sun-barr!ames!haven.umd.edu!darwin.sura.net!cs.ucf.edu!schnitzi
- From: schnitzi@cs.ucf.edu (Mark Schnitzius)
- Subject: Re: Deciding point-in-polygon: A new idea
- Message-ID: <schnitzi.715279970@eola.cs.ucf.edu>
- Sender: news@cs.ucf.edu (News system)
- Organization: University of Central Florida
- References: <1992Aug31.083543.27938@olymp.informatik.uni-bonn.de>
- Date: Mon, 31 Aug 1992 16:52:50 GMT
- Lines: 46
-
- hermann@uran.informatik.uni-bonn.de (Hermann Stamm) writes:
- >|
- >| Compute the area of the polygon in question (this is a well
- >| known and simple procedure). Now consider the polygon formed
- >| by adding the point in question as another vertice, anywhere
- >| in the original list of vertices. If the area of this new
- >| polygon is greater than the original, the point is outside
- >| the polygon. If less, it is inside.
- >|
- >| My question: will it work?
- >|
- >This will not work! The area can be smaller even if the added
- >point lies outside the polygon, but there is a more simple
- >proof, that this can't be right:
-
- >The area of Polygon (x1,y1),(x2,y2), ... , (xn,yn) is given by
-
- > A=x[n]*y[1]-y[n]*x[1];
- > for(i=1; i<n; i++)
- > A+=(x[i]*y[i+1]-y[i]*x[i+1]);
- > A/=2;
-
- >If you are allowed to insert the new point (x,y) where you like, then
- >insert (x,y) always between (x1,y1) and (x2,y2).
-
- >The only change in the above sum will then depend only on
- >(x1,y1), (x2,y2) and (x,y), and thus will be computable in constant time,
- >but you can't look at the whole input in constant time, and the rest of the
- >lines can either force (x,y) to lie inside or not. contradiction!
-
- Confession: I knew it wouldn't work when I posted it, but I wanted to
- see if anyone could come up with a way to make it work. Since then, I
- came to the realization that this idea WILL work if you add the stipulation
- that the point must be added in such a way that it will not make any new
- line crossings, and I believe it is always possible to do so. Like you
- said, the only change in sum will depend on (x1,y1), (x2,y2), and (x,y),
- so after you find the place to add the point (which is where the complex-
- ity comes in), you only need to check to see if
-
- (x1*y2-x2*y1) > (x1*y-x*y1)+(x*y2-x2*y)
-
- If this inequality is true, the point is inside the polygon.
-
- Mark Schnitzius
- schnitzi@eola.cs.ucf.edu
- Univ. of Central Florida
-