Inaccurate Evaluation of points inside holed polygons
michelegatto1 opened this issue · 2 comments
I'm facing an issue trying to detect which of my query points, coming from a Digital Terrain Model, are inside the polygons of a lithological shapefile. Specifically, The issued polygon is holed and the attached image shows what happens (see lower part).
How could I solve it?
Hi @michelegatto1, I believe this is just a 'conventions' issue --- you look to be using a NaN
-delimited polygon format (via MATLAB
's polyshape
) but inpoly
is based on the more general node-edge
topological layout. If you convert:
% apparently saved in MATLAB's 'polyshape' format
load 'Issue1/Issue1_polygon.mat'
load 'Issue1/query_points.mat'
% un-pack NaN-delimited polygons into topological
% node-edge format for inpoly
[pp,ee] = getnan2(issue1_polygon.Vertices);
[in,on] = inpoly2(query_points,pp,ee);
figure;
patch('faces',ee,'vertices',pp,'edgecolor','k','facecolor','w');
axis equal; hold on;
plot(query_points(in,1),query_points(in,2),'b.');
plot(query_points(on,1),query_points(on,2),'r.');
where the getnan2
can be found here: https://github.com/dengwirda/mesh2d/blob/master/geom-util/getnan2.m. You should get the expected output:
Adding the option to convert NaN
-delimited inputs automatically within inpoly
seems a reasonable improvement, so I've tagged this as an option for future releases.
It's great! Now it works fine. Thanks a lot