home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!ames!olivea!inews.Intel.COM!inews!pinkas
- From: pinkas@skywalker.intel.com (Israel Pinkas)
- Newsgroups: comp.graphics
- Subject: Re: Point inside a triangle
- Message-ID: <PINKAS.92Nov15155005@skywalker.intel.com>
- Date: 15 Nov 92 23:50:05 GMT
- References: <7bv1svg@rpi.edu>
- Sender: news@inews.Intel.COM (USENET News System)
- Organization: Software Technologies, INTeL Corporation, Santa Clara, CA
- Lines: 42
- In-Reply-To: bohn@ptolemy2.rdrc.rpi.edu's message of 15 Nov 92 23:01:12 GMT
- Nntp-Posting-Host: skywalker
-
- bohn@ptolemy2.rdrc.rpi.edu (Jan Helge Bhn) writes:
-
- Does anyone have any suggestions on how to check if a point is located
- inside a triangle, accurately and fast.
-
- Maybe not fast, but accurate:
-
- The area of a polygon is:
-
- n-1
- ---
- \
- > x y - x y
- / i i+1 i i-1
- ---
- i=1
-
- when x = x and y = y
- n 1 n 1
-
- For triangles, this reduces to:
-
- A = x y + x y + x y - x y - x y - x y
- 1 2 2 3 3 1 1 3 2 1 3 2
-
-
- The sign of A will determine whether the triangle is clock-wise or counter
- clock-wise.
-
- In the case of a point outside the triangle, determine the sign of the
- area. Then substitute the new point for each of the vertices of the
- triangle. If the sign changes, the point is outside the triangle.
-
- Intuitively, I feel that you should only need to perform the test twice.
- If someone can prove it, I'd like to see it.
-
- -Israel Pinkas
- --
- Israel Pinkas pinkas@stps18.intel.com 408-765-4210
-
- "Everybody's askaird of death, until it hits you ...
- then you don't care" -Archie Bunker
-