#14 adelka17
Tady je jen pro kontrolu cely program
program Usecky;
{$APPTYPE CONSOLE}
uses
SysUtils;
var i: Integer; //definovani promenych
Ax,Ay,Bx,By,Cx,Cy,Dx,Dy,a,b,t,s,xp,yp: Real;
PB: array[1..8] of Real; //pole aby se daly souradnice nacist
begin
{trochu matematiky - usecky zadane parametricky:
prvni usecka x=Ax+(Bx-Ax)*s, y=Ay+(By-Ay)*s, s=<0,1>
druha usecka x=Cx+(Dx-Cx)*t, y=Cy+(Dy-Cy)*t, t=<0,1>
aby se usecky protinaly uvnitr musi byt pro prusecik s,t v danem intervalu}
WriteLn ('--------------------- Prusecik usecek -----------------------');
WriteLn;
Write(' Zadej x-ove a y-ove souradnice bodu A,B,C,D: '); //sem zadas hodnoty x-ovych a y-ovych
for i := 1 to 8 do //hodnot bodu oddelenych mezerou
begin
Read(PB[i]); //nacitani techto bodu
end;
Writeln;
Ax := PBodu[1]; Ay := PBodu[2]; //prirazeni hodnot promenym Ax az Dy
Bx := PBodu[3]; By := PBodu[4];
Cx := PBodu[5]; Cy := PBodu[6];
Dx := PBodu[7]; Dy := PBodu[8];
a := (Cx-Ax)*(By-Ay)-(Bx-Ax)*(Cy-Ay); //vypocitani pomocnych hodnot
b := (Bx-Ax)*(Dy-Cy)-(Dx-Cx)*(By-Ay);
if b=0 then //podminka rovnobeznosti
WriteLn (' False (rovnobezky)') //vypsani, ze se neprotinaji (rovnobezky)
else
begin //vypocitaní parametru pro usecku CD
t := a/b; //kdyz se protinaji
xp := Cx+(Dx-Cx)*t; //x-ova souradnice pruseciku
yp := Cy+(Dy-Cy)*t; //y-ova souradnice pruseciku
if (Bx-Ax)=0 then //podminka aby se nedelilo nulou-usecka AB je "svisla"
s := (yp-Ay)/(By-Ay) //vypocitaní parametru pro usecku AB
else
s := (xp-Ax)/(Bx-Ax); //v pruseciku
if (t>=0)and(t<=1)and(s>=0)and(s<=1) then //podminka protnuti se uvnitr usecek
WriteLn (' True') //protinaji se uvnitr
else
WriteLn (' False (ruznobezky-vne)'); //protinaji se vne
end;
ReadLn;
ReadLn; //ceka na Enter a program ukonci
end.