logo search
Простая замкнутая ломаная кривая

п.2 Function Peres, на языке Turbo Pascal

Function Peres (A, B, C, D: tochka): boolean;

Var O: tochka;

k1, k2, b1, b2: real;

s1, s2: Boolean;

Begin

{Проверка 1-го случая}

if (A.x=C.x)and(A.y=C.y) and (B.x=D.x)and(B.y=D.y) then Peres:=False

else

if (A.x=D.x)and(A.y=D.y) and (B.x=C.x)and(B.y=C.y) then Peres:=False

else

{Проверка 2-го случая}

If (A.x=C.x)and(A.y=C.y) then if Prin(D,A,B) or Prin(B,C,D) then Peres:=true else Peres:=False

else

If (A.x=D.x) and (A.y=D.y) then if Prin(C, A, B) or Prin (B,C,D) then Peres:=true else Peres:=False

else

If (B.x=C.x)and(B.y=C.y) then if Prin(D,A,B) or Prin(A,C,D) then Peres:=true else Peres:=False

else

If (B.x=D.x)and(B.y=D.y) then if Prin(C,A,B) or Prin(A,C,D) then Peres:=true else Peres:=False

else { общей случай }

If A.x=B.x then begin if C.x=D.x then if Prin(A,C,D) or

Prin(B,C,D) or

Prin(C,A,B) or

Prin(D,A,B) then Peres:=true else Peres:=false

else begin

k2:=(C.y-D.y)/(C.x-D.x);

b2:=C.y-k2*C.x;

O.x:=A.x;

O.y:=k2*O.x+b2;

if Prin(O,C,D) and Prin(O,A,B) then Peres:=true

else Peres:=False

end end

else if C.x=D.x then begin

k1:=(A.y-B.y)/(A.x-B.x);

b1:=A.y-k1*A.x;

O.x:=C.x;

O.y:=k1*O.x+b1;

if Prin(O,C,D) and Prin(O,A,B) then Peres:=true

else Peres:=False

end

else begin

k1:=(A.y-B.y)/(A.x-B.x);

k2:=(C.y-D.y)/(C.x-D.x);

if k1=k2 then {} if Prin(A,C,D) or

Prin(B,C,D) or

Prin(C,A,B) or

Prin(D,A,B) then Peres:=true

else Peres:=false

else begin

b1:=A.y-k1*A.x;

b2:=C.y-k2*C.x;

O.x:=(b1-b2)/(k2-k1);

if k1=0 then O.y:=b1

else if k2=0 then O.y:=b2

else O.y:=(b1/k1-b2/k2)/(1/k1-1/k2);

if Prin(O,C,D) and Prin(O,A,B)

then Peres:=true

else Peres:=false

end

end

End;