MATLAB Answers

How to identify points that are located in a polygon when this polygon passes through the meridian?

조회 수: 6(최근 30일)
Hemming
Hemming 2019년 1월 4일
편집: Are Mjaavatten 2019년 1월 6일
I have a polygon presented by a series of longitude and latitude degrees. The longitude of this polygon is presented by degrees of [0 360] and it passes through the meridian. Also, I have two points and I need to check whether these points are located in this polygon.
For example, the longitude and latitude of this polygon is
PGlon = [5 5 355 355 5]; PGlat = [30 40 40 30 30];
and the points are
Xlon = [0 10]; Xlat = [35 45];
The positions of the polygon and points are as this figure (the first point is located inside this polygon).
I know that the function "inpolygon" may help to solve this problem, and I do
in_flag = inpolygon(Xlat,Xlon,PGlat,PGlon);
But this function cannot recognize whether the polygon crosses the meridian, so both points are identified to be outside the polygon.
Is there any useful way to handle this problem? Thanks!

답변(1개)

Are Mjaavatten
Are Mjaavatten 2019년 1월 5일
편집: Are Mjaavatten 2019년 1월 5일
It seems that you are using the mapping toolbox, Then you can use ingeoquad:
ingeoquad([35,45],[0,10],[30 40], [355 5])
Your call to inpolygon checks if the points are inside a band spanning 350 degrees, which is not what you want. Use negative values for longitudes > 180:
inpolygon([35 45],[0 10],[30 40 40 30],[5 5 -5 -5])
  댓글 수: 2
Are Mjaavatten
Are Mjaavatten 2019년 1월 6일
Just create a polygon from the border points. inpolygon will work for any polygon, even if it is not convex. Example:
xb = [0 1 1 0.5 0];
yb = [0 0 1 0.5 1];
figure;
patch(xb,yb,[1,1,1]*0.9);
inside = inpolygon(x,y,xb,yb);
hold on
plot(x(inside),y(inside),'*r')
plot(x(~inside),y(~inside),'ok')

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by