Программа:
Pascal:
const e = 0.0001;
var
AX1, AY1, AX2, AY2, BX1, BY1, BX2, BY2: integer;
x, y: real;
begin
write('AX1 = '); readln(AX1);
write('AY1 = '); readln(AY1);
write('AX2 = '); readln(AX2);
write('AY2 = '); readln(AY2);
write('BX1 = '); readln(BX1);
write('BY1 = '); readln(BY1);
write('BX2 = '); readln(BX2);
write('BY2 = '); readln(BY2);
if (abs(AX2 - AX1) < e) and (abs(BX2 - BX1) < e) or (abs((BX2 - BX1) * (AY2 - AY1) - (BY2 - BY1) * (AX2 - AX1)) < e) then
writeln('Отрезки параллельны.')
else
if (abs(AX1 - AX2) < e) and (abs(BY2 - BY1) < e) then
x := AX1;
y := BY1;
end
else if (abs(AY1 - AY2) < e) and (abs(BX1 - BX2) < e) then
x := BX1;
y := AY1;
x := -((BX2 - BX1) * (AX1*AY2 - AX2*AY1) - (AX2 - AX1) * (BX1*BX2 - BX2*BY1)) / ((AY1 - AY2) * (BX2 - BX1) - (AX2 - AX1) * (BY1 - BY2));
y := ((-x) * (BY1 - BY2) - (BX1*BY2 - BX2 * BY1)) / (BX2 - BX1);
end;
if ((x >= AX1) and (x <= AX2)) or ((x <= x) and (x >= AX2)) then
write('Отрезки пересекаются в точке (', x:0:1, '; ', y:0:1, ')')
else writeln('Отрезки не пересекаются.');
end.
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
Программа:
Pascal:
const e = 0.0001;
var
AX1, AY1, AX2, AY2, BX1, BY1, BX2, BY2: integer;
x, y: real;
begin
write('AX1 = '); readln(AX1);
write('AY1 = '); readln(AY1);
write('AX2 = '); readln(AX2);
write('AY2 = '); readln(AY2);
write('BX1 = '); readln(BX1);
write('BY1 = '); readln(BY1);
write('BX2 = '); readln(BX2);
write('BY2 = '); readln(BY2);
if (abs(AX2 - AX1) < e) and (abs(BX2 - BX1) < e) or (abs((BX2 - BX1) * (AY2 - AY1) - (BY2 - BY1) * (AX2 - AX1)) < e) then
writeln('Отрезки параллельны.')
else
begin
if (abs(AX1 - AX2) < e) and (abs(BY2 - BY1) < e) then
begin
x := AX1;
y := BY1;
end
else if (abs(AY1 - AY2) < e) and (abs(BX1 - BX2) < e) then
begin
x := BX1;
y := AY1;
end
else
begin
x := -((BX2 - BX1) * (AX1*AY2 - AX2*AY1) - (AX2 - AX1) * (BX1*BX2 - BX2*BY1)) / ((AY1 - AY2) * (BX2 - BX1) - (AX2 - AX1) * (BY1 - BY2));
y := ((-x) * (BY1 - BY2) - (BX1*BY2 - BX2 * BY1)) / (BX2 - BX1);
end;
if ((x >= AX1) and (x <= AX2)) or ((x <= x) and (x >= AX2)) then
write('Отрезки пересекаются в точке (', x:0:1, '; ', y:0:1, ')')
else writeln('Отрезки не пересекаются.');
end;
end.