2010/03/15

주어진 점이 다각형에 포함되는지 확인하기


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;





No comments :

Post a Comment