Проверка пересечения двух четырёхугольников (array of TPoint)
function PtInTriang(const P, A, B, C: TPoint): Boolean;
function _PIT(const C1, C2, C3: TPoint): Boolean;
begin
Result := False;
if (P.x-C1.x)*(C1.y-C2.y) - (P.y-C1.y)*(C1.x-C2.x) >= 0 then
if (P.x-C2.x)*(C2.y-C3.y) - (P.y-C2.y)*(C2.x-C3.x) >= 0 then
if (P.x-C3.x)*(C3.y-C1.y) - (P.y-C3.y)*(C3.x-C1.x) >= 0 then
Result := True;
end;
begin
if (A.x-B.x)*(C.y-B.y) > (A.y-B.y)*(C.x-B.x)
then Result := _PIT(A, C, B)
else Result := _PIT(A, B, C);
end;
function PtinTetragon(P: TPoint; Points: array of TPoint): boolean;
begin
Result:= PtInTriang(P, Points[0], Points[1], Points[2]) or PtInTriang(P, Points[0], Points[2], Points[3]);
end;
function CrossTetragon(Points1: array of TPoint; Points2: array of TPoint): boolean;
var
b: boolean;
i: integer;
begin
b:= false;
for I := 0 to 3 do
if PtinTetragon(Points1[i],Points2) then
b:= true;
if not b then
for I := 0 to 3 do
if PtinTetragon(Points2[i],Points1) then
b:= true;
Result:= b;
end;
|