Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Project1;
- Uses
- System.SysUtils;
- Var
- ArrX, ArrY : Array of Real;
- I, N, J : Integer;
- X, Y : Real;
- Iscorrect, GotInto : Boolean;
- Const
- Min = 3;
- Begin
- Writeln ('The polygon is given by the coordinates of its vertices. Determine if the given point belongs to the area of the polygon.');
- Writeln ('Input number of vertices:');
- Repeat
- Iscorrect := True;
- Try
- Readln (N);
- Except
- Writeln ('Please, enter a positive integer number:');
- IsCorrect := False;
- End;
- If (IsCorrect And (N < Min)) Then
- Begin
- Writeln('There must be more than 2 vertices.');
- IsCorrect := False;
- End;
- Until (Iscorrect);
- SetLength (ArrX, N);
- SetLength (ArrY, N);
- Dec (N);
- For I := 0 To N Do
- Begin
- Writeln ('Enter coordinates for point ', I + 1, ':');
- Repeat
- Iscorrect := True;
- Try
- Readln (ArrX[I]);
- Except
- Writeln ('Please, enter a number:');
- IsCorrect := False;
- End;
- Until (Iscorrect);
- Repeat
- Iscorrect := True;
- Try
- Readln (ArrY[I]);
- Except
- Writeln ('Please, enter a number:');
- IsCorrect := False;
- End;
- Until (Iscorrect);
- End;
- Writeln ('Input point coordinates:');
- Repeat
- Iscorrect := True;
- Try
- Readln (X);
- Except
- Writeln ('Please, enter a number:');
- IsCorrect := False;
- End;
- Until (Iscorrect);
- Repeat
- Iscorrect := True;
- Try
- Readln (Y);
- Except
- Writeln ('Please, enter a number:');
- IsCorrect := False;
- End;
- Until (Iscorrect);
- GotInto := False;
- Inc (N);
- J := N - 1;
- For I := 0 To N Do
- Begin
- If ((((ArrY[I] <= Y) and (Y <= ArrY[J])) or ((ArrY[J] <= Y) and (Y <= ArrY[I]))) and (((ArrY[J] - ArrY[I]) <> 0) and
- (X >= ((ArrX[J] - ArrX[I]) * (Y - ArrY[I]) / (ArrY[J] - ArrY[I]) + ArrX[I])))) then
- GotInto := Not (GotInto);
- Inc (J);
- If (J = N) then
- J := 0;
- End;
- If (GotInto) then
- Writeln ('Point belongs to area!')
- Else
- Writeln ('Point does not belong to area.');
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement