How to identify points that are located in a polygon when this polygon passes through the meridian?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposte (1)
Are Mjaavatten
il 5 Gen 2019
Modificato: Are Mjaavatten
il 5 Gen 2019
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 Commenti
Are Mjaavatten
il 6 Gen 2019
Modificato: Are Mjaavatten
il 6 Gen 2019
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')
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!