[Beginner] Constructing a rectangle object and detecting points inside
24 ビュー (過去 30 日間)
古いコメントを表示
Baptiste Labarthe
2021 年 4 月 17 日
コメント済み: Baptiste Labarthe
2021 年 4 月 17 日
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 件のコメント
採用された回答
Cris LaPierre
2021 年 4 月 17 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!