Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.03 KB | None | 0 0
  1. program intersection;
  2. const
  3.     eps = 0.000001;
  4.     maxLines = 500;
  5.     inputFilepath = 'input.txt';
  6.     outputFilepath = 'output.txt';
  7. type
  8.     Line = record
  9.                 a: Real;
  10.                 b: Real;
  11.             end;
  12. var
  13.     df: text;
  14.     i, j: integer;
  15.     a, b, c, d, xp, yp: real;
  16.     lines: array[1..maxLines] of Line;
  17.  
  18. begin
  19.     {Reading lines}
  20.     assign(df, inputFilepath);
  21.     reset(df);
  22.     i := 1;
  23.     while not eof(df) do begin
  24.         readln(df, a, b);
  25.         lines[i].a := a;
  26.         lines[i].b := b;
  27.         inc(i);
  28.     end;
  29.     close(df);
  30.  
  31.     {Writing intersections}
  32.     assign(df, outputFilepath);
  33.     rewrite(df);
  34.     for j:=2 to i-1 do begin
  35.         a := lines[j-1].a;
  36.         c := lines[j-1].b;
  37.         b := lines[j].a;
  38.         d := lines[j].b;
  39.  
  40.         if abs(a-b)<eps then
  41.             writeln(df, 'parallels')
  42.         else begin
  43.             xp := (d-c)/(a-b);
  44.             yp := a*xp+c;
  45.             writeln(df, xp:0:3, ',', yp:0:3);
  46.         end;
  47.     end;
  48.     close(df);
  49. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement