function inside = point_in_polygon ( px, py, vx, vy )

%*****************************************************************************80
%
%% point_in_polygon is true if a point is inside a polygon.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 September 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real PX, PY: the coordinates of the point.
%
%    real VX(N), VY(N): the coordinates of the polygon vertices.
%
%  Output:
%
%    logical INSIDE, is TRUE if the point is inside the polygon.
%
  n = length ( vx );

  inside = false;

  vx1 = vx(1);
  vy1 = vy(1);
  xints = px - 1.0;

  for i = 1 : n

    vx2 = vx(mod(i,n)+1);
    vy2 = vy(mod(i,n)+1);

    if ( min ( vy1, vy2 ) < py )
      if ( py <= max ( vy1, vy2 ) )
        if ( px <= max ( vx1, vx2 ) )
          if ( vy1 ~= vy2 )
            xints = ( py - vy1 ) * ( vx2 - vx1 ) / ( vy2 - vy1 ) + vx1;
          end
          if ( vx1 == vx2 || px <= xints )
            inside = ~ inside;
          end
        end
      end
    end

    vx1 = vx2;
    vy1 = vy2;

  end

  return
end

