From: "John Hutchings" Newsgroups: borland.public.delphi.graphics References: <3bcf3315_2@dnews> Subject: Re: Detecting whether a point lies within a polygon Date: Fri, 19 Oct 2001 06:20:44 +1000 Lines: 54 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 210.84.172.172 Message-ID: <3bcf3982_1@dnews> X-Trace: dnews 1003436418 210.84.172.172 (18 Oct 2001 13:20:18 -0700) Path: dnews Xref: dnews borland.public.delphi.graphics:42906 Mike, This works for me function PointInPolygonTest( x,y: Integer ;aList: Array of TPoint): Boolean; // The code below is from Wm. Randolph Franklin // with some minor modifications for speed. It returns 1 for strictly // interior points, 0 for strictly exterior, and 0 or 1 for points on // the boundary. var L, I, J : Integer; Function xp(aVal:Integer):Integer; Begin Result:= PPoint(@aList[aVal]).X; end; Function yp(aVal:Integer):Integer; Begin Result:= PPoint(@aList[aVal]).Y; end; begin Result:=False; L:= Length(aList) ; If L=0 then exit; J:=L-1; for I:=0 to L-1 do begin if ((((yp(I)<=y) and (y wrote in message news:3bcf3315_2@dnews... > Hi, > > Can anyone help be with detecting whether the screen coord that a user has > clicked on lies within a defined polygon > (I`ll know all the screen coords of the points defining the polygon). > An algorithm would be good, or any links to useful techy sites. > > Thanks, > > Mike