[Beginner] Constructing a rectangle object and detecting points inside
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Baptiste Labarthe
el 17 de Abr. de 2021
Comentada: Baptiste Labarthe
el 17 de Abr. de 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 comentarios
Respuesta aceptada
Cris LaPierre
el 17 de Abr. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!