Advertisement
Vladislav8653

laba_2_1_delphi

Nov 16th, 2022
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.60 KB | None | 0 0
  1. Program Project1;
  2. Uses
  3.   System.SysUtils;
  4. Var
  5.     ArrX, ArrY : Array of Real;
  6.     I, N, J : Integer;
  7.     X, Y : Real;
  8.     Iscorrect, GotInto : Boolean;
  9. Const
  10.     Min = 3;
  11. Begin
  12.     Writeln ('The polygon is given by the coordinates of its vertices. Determine if the given point belongs to the area of the polygon.');
  13.     Writeln ('Input number of vertices:');
  14.     Repeat
  15.         Iscorrect := True;
  16.         Try
  17.             Readln (N);
  18.         Except
  19.             Writeln ('Please, enter a positive integer number:');
  20.             IsCorrect := False;
  21.         End;
  22.         If (IsCorrect And (N < Min)) Then
  23.         Begin
  24.             Writeln('There must be more than 2 vertices.');
  25.             IsCorrect := False;
  26.         End;
  27.     Until (Iscorrect);
  28.     SetLength (ArrX, N);
  29.     SetLength (ArrY, N);
  30.     Dec (N);
  31.     For I := 0 To N Do
  32.         Begin
  33.             Writeln ('Enter coordinates for point ', I + 1, ':');
  34.             Repeat
  35.                 Iscorrect := True;
  36.                 Try
  37.                     Readln (ArrX[I]);
  38.                 Except
  39.                     Writeln ('Please, enter a number:');
  40.                     IsCorrect := False;
  41.                 End;
  42.             Until (Iscorrect);
  43.             Repeat
  44.                 Iscorrect := True;
  45.                 Try
  46.                     Readln (ArrY[I]);
  47.                 Except
  48.                     Writeln ('Please, enter a number:');
  49.                     IsCorrect := False;
  50.                 End;
  51.             Until (Iscorrect);
  52.         End;
  53.  
  54.     Writeln ('Input point coordinates:');
  55.     Repeat
  56.         Iscorrect := True;
  57.             Try
  58.                 Readln (X);
  59.             Except
  60.                 Writeln ('Please, enter a number:');
  61.                 IsCorrect := False;
  62.             End;
  63.     Until (Iscorrect);
  64.     Repeat
  65.          Iscorrect := True;
  66.             Try
  67.                 Readln (Y);
  68.             Except
  69.                 Writeln ('Please, enter a number:');
  70.                 IsCorrect := False;
  71.             End;
  72.     Until (Iscorrect);
  73.     GotInto := False;
  74.     Inc (N);
  75.     J := N - 1;
  76.     For I := 0 To N Do
  77.         Begin
  78.             If ((((ArrY[I] <= Y) and (Y <= ArrY[J])) or ((ArrY[J] <= Y) and (Y <= ArrY[I]))) and (((ArrY[J] - ArrY[I]) <> 0) and
  79.             (X >= ((ArrX[J] - ArrX[I]) * (Y - ArrY[I]) / (ArrY[J] - ArrY[I]) + ArrX[I])))) then
  80.                 GotInto := Not (GotInto);
  81.             Inc (J);
  82.             If (J = N) then
  83.                 J := 0;
  84.         End;
  85.     If (GotInto) then
  86.         Writeln ('Point belongs to area!')
  87.     Else
  88.         Writeln ('Point does not belong to area.');
  89.     Readln;
  90. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement