Is there a way to use inpolygon more than once ?
조회 수: 3 (최근 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에서 Graph and Network Algorithms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!