Mail Archives: djgpp/1998/11/04/13:00:19
In article <Pine DOT SUN DOT 3 DOT 91 DOT 981104164758 DOT 28192B-100000 AT is>,
djgpp AT delorie DOT com wrote:
>
> On Wed, 4 Nov 1998, a j wrote:
>
> > can anyone explain how you detect if a point is
> > inside or outside a triangle.. in a simple 2D x-y co-ord system.
>
> Draw a line from the point in any direction. If it crosses the sides of
> the triangle an odd number of times, the point is inside; otherwise, it's
> outside.
>
> Depending on whether you care, there are some borderline cases when the
> point is exactly on one of the sides.
>
> > or offer some C code.. or a reference for places to get this info.
>
> I think I posted a general solution (good for any polygon, not just a
> triangle) a year or so ago. Try searching the DJGPP forum archives at
> http://www.delorie.com/djgpp/mail-archives/ for words like "polygon".
>
I believe the subject, and that algorithm, is covered nicely in Sedgewicks
"Algorithms". He also has methods for the peculiar cases. I could be in
error on the book involved, don't have it here.
--
Chuck Falconer (Charles_Falconer AT NOSPAMapsnet DOT com)
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
- Raw text -