%polygonal coordinates
close all
clear
clc
xv = [0 0 0 20 20 0 10 20 20 20 20 30 30 50 50 20 30 40 50]
yv = [0 0 50 10 0 0 0 0 0 10 50 50 10 10 0 0 0 0 0 ]
% plotting the points as polygonas
figure (1)
plot(xv, yv,'-')
hold on
%square axis
grid on
axis([-10 60 -10 60])
%specifying the N coordinate
% xq = [22 45];
% yq = [25 35];
[X] = ginput(2);
[X] = round(X);
xq = X(1:2);
yq = X(3:4);
%polygon and point plotting
[in,on] = inpolygon(xq,yq,xv,yv);
%Determine the number of points lying inside or on the edge of the polygon area.
numel(xq(in))
%Determine the number of points lying on the edge of the polygon area.
numel(xq(on))
%Determine the number of points lying outside the polygon area (not inside or on the edge).
numel(xq(~in))
%Plot the polygon and the query points. Display the points inside the polygon with a red plus. Display the points outside the polygon with a blue circle.
figure (1)
plot(xv,yv) % polygon
axis([-10 60 -10 60])
hold on
plot(xq(in),yq(in),'r+') % points inside
plot(xq(~in),yq(~in),'bo') % points outside
hold off