1. Computing

Is Point in Polygon?

From , former About.com Guide

This solution checks how many times you cross a line to pass from point X,Y to the edge of the polygon...

~~~~~~~~~~~~~~~~~~~~~~~~~
function PtInPoly
   (const Points: Array of TPoint; X,Y: Integer):
   Boolean;
var Count, K, J : Integer;
begin
  Result := False;
  Count := Length(Points) ;
  J := Count-1;
  for K := 0 to Count-1 do begin
   if ((Points[K].Y <=Y) and (Y < Points[J].Y)) or
      ((Points[J].Y <=Y) and (Y < Points[K].Y)) then
   begin
    if (x < (Points[j].X - Points[K].X) *
       (y - Points[K].Y) /
       (Points[j].Y - Points[K].Y) + Points[K].X) then
        Result := not Result;
    end;
    J := K;
  end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» TButton with multiline Caption
« Create an Auto-Run CD

Top Related Searches delphi tips tpoint auto run delphi lt array

©2013 About.com. All rights reserved.