www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/04/10:00:22

Date: Wed, 4 Nov 1998 16:51:20 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: a j <aj664 AT hotmail DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: point detection in triangles
In-Reply-To: <19981104121444.28324.qmail@hotmail.com>
Message-ID: <Pine.SUN.3.91.981104164758.28192B-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

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".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019