home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.graphics
- Path: sparky!uunet!tessi!eaglet!slipknot!robert
- From: robert@slipknot.rain.com (Robert Reed)
- Subject: Re: Point inside a triangle
- Message-ID: <BxxoH3.BAH@slipknot.rain.com>
- Reply-To: robert@slipknot.rain.com.UUCP (Robert Reed)
- Organization: Home Animation Ltd.
- References: <1992Nov17.132302.6345@sophia.smith.edu> <BxvnnI.90x@slipknot.rain.com> <1992Nov18.003415.9990@cis.uab.edu>
- Date: Wed, 18 Nov 1992 22:43:50 GMT
- Lines: 49
-
- In article <1992Nov18.003415.9990@cis.uab.edu> sloan@cis.uab.edu (Kenneth Sloan) writes:
- |In article <BxvnnI.90x@slipknot.rain.com> robert@slipknot.rain.com.UUCP (Robert Reed) writes:
- |>
- |>A trivial modification to the algorithm as I suggested it would correct for
- |>this. If the boundaries of any polygon are to be considered interior, then if
- |>a bounding edge is collinear with the test point, it is sufficient to test
- |>whether the point is within the interval of the edge. If it is not, the edge
- |>is trivially rejected as before. If it is, the algorithm can be prematurely
- |>terminated with a TRUE result.
- |
- |Your "trivial modification" is virtually *all* of Professor O'Rourke's
- |algorithm! By the time you make this trivial modification to your
- |algorithm, you might just as well throw away your algorithm.
-
- Hardly. My test is:
-
- if (t[n].y == t[n+1].y) {
- if (t[n].y == p.y) {
- if (t[n].x < t[n+1].x) {
- l = t[n].x;
- r = t[n+1].x;
- }
- else {
- r = t[n].x;
- l = t[n+1].x;
- }
- if (p.x >= l && p.y <= r)
- return (TRUE);
- }
-
- /* discard point t[n+1] */
- }
-
- Note that most of this code gets executed only in the rare case that point p is
- collinear with a triangle edge which is horizontal. I forget which one was
- "O'Rourke's Algorithm" so I can't address how much of that this is.
-
- Given the explanation of the LeftOfOrOn algorithm, it may be slightly more
- efficient in the case of triangles, substituting three cross products for at
- most two intersection tests, but it certainly doesn't scale to polygons of more
- than three points.
- ________________________________________________________________________________
- Robert Reed Home Animation Ltd. 503-656-8414
- robert@slipknot.rain.com 5686 First Court, West Linn, OR 97068
-
- Outside of a dog, a book is a man's best friend;
- and inside a dog, it's too dark to read.
- -- Grouch Marx
- ________________________________________________________________________________
-