home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!rpi!bu.edu!bass.bu.edu!kiki
- From: kiki@bass.bu.edu (Keith Baccki)
- Newsgroups: comp.graphics
- Subject: Re: Point inside a triangle
- Message-ID: <102078@bu.edu>
- Date: 16 Nov 92 01:42:31 GMT
- References: <7bv1svg@rpi.edu>
- Sender: news@bu.edu
- Reply-To: kiki@bass.bu.edu (Keith Baccki)
- Followup-To: comp.graphics
- Organization: Boston University
- Lines: 43
-
- In article <7bv1svg@rpi.edu> bohn@rdrc.rpi.edu writes:
- >
- >Does anyone have any suggestions on how to check if a point is located
- >inside a triangle, accurately and fast.
-
-
- The method I used as part of a line clipping algorithm for
- clipping lines to an arbitrary triangle is as follows:
-
- - Select a point known to be inside the triangle
-
- x = (v1.x + v2.x + v3.x)/3
- y = (v1.y + v2.y + v3.y)/3
-
- - Now draw a line from that point to the point in question
- and perform a line intersection test with each edge of
- the triangle. NOTE: You must only accept intersections
- within the extents of the line *segments* in question,
- NOT the whole lines.
-
-
- i.e. /\ C
- / \ Line AB intersects edge C, but segment
- /A. .\ AB doesn't -> Extent test on both segments
- /____B_\ shows that the point of intersection is
- within C, but not segment AB.
-
- - If there are no segment intersections, the line is inside.
-
- - Whether the line is on a triangle edge or not can be
- decided with more code.
-
-
- Criticisms? Alternatively, you could go the inward normal route as
- you've pointed out, but I thought this method was a little less dep-
- endent on the manner in which you define your triangle edges, etc.
- Hope this helps.
-
-
- Keith Baccki
-
- kiki@bass.bu.edu
-
-