Hi,
I tried to change the color of points laying inside and on the edge of a parallelogram from cyan to blue (image1). I used the command inpolygon to do that, but not all the points on the edge of the parallelogram change to blue (image2). I also need to count the number of blue points inside the parallelogram. The syntax that I use is as follows :
clc;clear;% using equation to approximate Pd
% defining variables
U=7;V=9;R=4;L=60;Pdo=2.*R./L.*sqrt(1+(V/U).^2);Pd=min(1,Pdo);% creating polygon
xv=[0 10 60 50 0];yv=[0 0 40 40 0];rng default;% generate random points inside rectangle
xq = rand(10000,1).*60;yq = rand(10000,1).*40;[in,on] = inpolygon(xq,yq,xv,yv);count1=numel(xq,yq(in));count2=numel(xq,yq(on));count=count1+count2;disp(count);% numel(xq(on));numel(xq(~in));
figure%plotting
plot(xv,yv);axis equalgrid onhold on;plot(xq(in),yq(in),'bo') % points inside
plot(xq(~in),yq(~in),'co') % points outside
hold off
can anyone please spot the mistake that I have made?
Best Answer