Näitähän jokainen koodari tarvitsee jossain elämän vaiheessa. Kaikki kolme funktiota palauttavat boolean -arvon True, jos piste on kuvion sisäpuolella tai sen kehällä.
PointInRect: Piste suorakulmion sisällä. Parametrit Point(kysytty piste); Rect(Suorakulmio)
PtInPoly: Piste monikulmion sisällä. Parametrit const Points: (Taulukko monikulmion pisteistä); X,Y: (Kysytty piste)
PtInPoly löytyi täältä: http://www.delphi.about.com/
PointInCircle: Piste ympyrän sisällä. Parametrit PPointCoords, PCircleCoords: (Pisteen ja ympyrän koordinaatit); PRadius: (Ympyrän säde)
function PointInRect(Point: Tpoint; Rect: Trect): Boolean;
begin
if (Point.X > Rect.TopLeft.X) and
(Point.Y > Rect.TopLeft.Y) and
(Point.X < Rect.BottomRight.X) and
(Point.Y < Rect.BottomRight.Y) then
PointInRect := True
else
PointInRect := False;
end;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;function PointInCircle(PPointCoords, PCircleCoords: TRealPoint; PRadius: Word): Boolean; begin if Hypot(PPointCoords.X - PCircleCoords.X,PPointCoords.Y - PCircleCoords.Y) <= PRadius then Result := True else Result := False; end;
Aihe on jo aika vanha, joten et voi enää vastata siihen.