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 个评论
KSSV
KSSV 2022-3-11
You can use it n number of times if your polygon is different every time.
Jan
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
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.

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by