Is there a way to use inpolygon more than once ?
2 ビュー (過去 30 日間)
古いコメントを表示
I am trying to use inpolygon more than once in my code, but each time when i run the program is identifying points in only one polygon.Is there a way to use inpolygon more than once ?
2 件のコメント
Jan
2022 年 3 月 11 日
Yes, of course. Most likely your code conatins a bug, e.g. if you run a loop over i and use j as index of the data. If you post the relevant part of the code, we can try to find the problem.
回答 (1 件)
Prahlad Gowtham Katte
2022 年 3 月 16 日
Hello
We can use the inpolygon function more than once in a script file. The following code shows inpolygon being used more than once for 2 different polygons.
%Co-ordinates for 1st
polygon
xv = [0.5;0.2;1.0;0;0.8;0.5];
yv = [1.0;0.1;0.7;0.7;0.1;1];
%Points to be checked with 1st polygon
xq = [0.1;0.5;0.9;0.2;0.4;0.5;0.5;0.9;0.6;0.8;0.7;0.2];
yq = [0.4;0.6;0.9;0.7;0.3;0.8;0.2;0.4;0.4;0.6;0.2;0.6];
%Points to be checked with 2nd polygon
xq2 = xq+1;
yq2 = yq+0.5;
%Co-ordinates for 2nd polygon
xv2=xv+1;
yv2=yv+1;
%Getting the indicators for inside and on the edge points
[on,in]=inpolygon(xq,yq,xv,yv);
[on2,in2]=inpolygon(xq,yq,xv2,yv2);
figure
plot(xv,yv) % 1st polygon
hold on
plot(xv2,yv2) % 2nd polygon
plot(xq(in&~on),yq(in&~on),'r+') % points strictly inside
plot(xq(on),yq(on),'r*') % points on edge
plot(xq(~in),yq(~in),'ro') % points outside
%2nd polygon
plot(xq2(in2&~on2),yq2(in2&~on2),'g+') % points strictly inside
plot(xq2(on2),yq2(on2),'g*') % points on edge
plot(xq2(~in2),yq2(~in2),'go') % points outside
hold off
For more information related to inpolygon please refer to the following link
Hope it helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Elementary Polygons についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!