How do I identify points within a user defined shape?
4 views (last 30 days)
Show older comments
Mariam Shahab on 11 Oct 2022
Commented: David Hill on 13 Oct 2022
I have the folliwing code:
% genertae random data
xrange = [0 100];
yrange = [0 100];
% generating randomly placed points
points = rand(npoints, 2);
% normalizing the xy locations according to the parameters
points(:,1) = points(:,1)*diff(xrange) + xrange(1);
points(:,2) = points(:,2)*diff(yrange) + yrange(1);
plot(points(:,1),points(:,2), 'b+','linewidth',2, 'markersize',12);
[x,y] = ginput(1); % these 5 points can be used to make any kind of shape (preferable small in size) on the plot
h1 = text(x,y,int2str(i), ...
'Color', [1 0 0], ...
%plotting a line between all points
plot([a ; a(1)],[b ; b(1)], 'b-');
I want to find a way to identify all those points that lie within a user defined shape. A few examples of user defined shapes would be like:
I will appreciate if someone can kindly help me out. Thanks!
David Hill on 11 Oct 2022
David Hill on 13 Oct 2022
p=polyshape([2 5 5 2],[2 2 6 2]);
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!