[Beginner] Constructing a rectangle object and detecting points inside
24 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Baptiste Labarthe
il 17 Apr 2021
Commentato: Baptiste Labarthe
il 17 Apr 2021
Hello,
On a 2D environnement, I would like to create a rectangle object.
This being done, I would like to be able to detect from a vector of points (x,y), which one are inside the rectangle area and which one are outside.
Could someone help me please? :D
0 Commenti
Risposta accettata
Cris LaPierre
il 17 Apr 2021
Independently, I'd suggest the rectangle and inpolygon functions. However, to find the points inside the rectangle, I'd use patch instead of rectangle, since it gives you access to the x and y values of the shape.
x=4*rand(1,10)+1;
y=2*rand(1,10)+2;
% view data
scatter(x,y)
hold on
p = patch([2,4,4,2],[2 2 4 4],nan);
axis([1 6 1 5])
% find data points inside rectangle
in=inpolygon(x,y,p.Vertices(:,1),p.Vertices(:,2));
% replot data inside shape, this time filled in
scatter(x(in),y(in),'filled')
hold off
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!