program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
type TRecCoord = record
X,Y:single;
end;
var
A,B,C,D,O,F:TRecCoord;
T:Boolean;
procedure Centr(P1,P2,P3:TRecCoord; out CNTR:TRecCoord);
var A1,B1,C1,A2,B2,C2:Single;
begin
A1:=2*(P1.X-P2.X); B1:=-2*(P1.Y-P2.Y);
C1:=P1.X*P1.X - P2.X*P2.X + P1.Y*P1.Y - P2.Y*P2.Y;
A2:=2*(P1.X-P3.X); B2:=-2*(P1.Y-P3.Y);
C2:=P1.X*P1.X - P3.X*P3.X + P1.Y*P1.Y - P3.Y*P3.Y;
CNTR.X:=(C1*B2-C2*B1)/(A1*B2-A2*B1);
CNTR.Y:=(A1*C2-A2*C1)/(A1*B2-A2*B1);
end;
function L(P1,P2:TRecCoord):Single;
begin
Result:=Sqrt(Sqr(P2.X-P1.X)+Sqr(P2.Y-P1.Y));
end;
function PR(P1,P2,P3,P4:TRecCoord; out TP:TRecCoord):Boolean;
var k1,k2:Single;
begin // P1P2 and P3P4
Result:=false;
if (P2.X-P1.X = 0) and (P4.X-P3.X = 0) then Exit;
if P2.X-P1.X = 0 then begin
TP.X:=P1.X;
TP.Y:=((P4.Y-P3.Y)/(P4.X-P3.X))*(TP.X-P3.X)+P3.Y;
Result:=true; Exit;
end;
if P4.X-P3.X = 0 then begin
TP.X:=P3.X;
TP.Y:=((P2.Y-P1.Y)/(P2.X-P1.X))*(TP.X-P1.X)+P1.Y;
Result:=true; Exit;
end;
k1:=(P2.Y-P1.Y)/(P2.X-P1.X);
k2:=(P4.Y-P3.Y)/(P4.X-P3.X);
if k1 <> k2 then begin
TP.X:=(k1*P1.X-k2*P3.X+P3.Y-P1.Y)/(k1-k2);
TP.Y:=k1*(TP.X-P1.X)+P1.Y;
Result:=true;
end;
end;
begin
Writeln('Write coordinate A(X1,Y1) B(X2,Y2) C(X3,Y3) D(X4,Y4)');
Writeln;
Writeln('X1 Y1 X2 Y2 X3 Y3 X4 Y4');
Writeln;
Readln(A.X,A.Y,B.X,B.Y,C.X,C.Y,D.X,D.Y);
Writeln;
T:=L(A,B) + L(C,D) = L(A,D) + L(B,C);
if T then
Begin
if PR(A,B,C,D,F) then
begin
if L(A,B) > L(C,D) then Centr(A,B,F,O)
else Centr(C,D,F,O);
end
else
begin
if PR(A,D,B,C,F) then
begin
if L(A,D) > L(B,C) then Centr(A,D,F,O)
else Centr(B,C,F,O);
end
else
begin
PR(A,C,B,D,O);
end;
end;
Writeln('Yes'+#13#10+Format('oX = %8.2f',[O.X])+#13#10+Format('oY = %8.2f',[O.Y]));
End
else Writeln('No');
Readln;
end.