[Beginner] Constructing a rectangle object and detecting points inside
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Baptiste Labarthe
am 17 Apr. 2021
Kommentiert: Baptiste Labarthe
am 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 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!