How to return an array without points in the edge?

4 visualizaciones (últimos 30 días)
Riccardo Tronconi
Riccardo Tronconi el 30 de Ag. de 2021
Editada: Adam Danz el 8 de Sept. de 2021
Dear guys! How to determine points which are not on the edge?
I used this function:
[in,on] = inpolygon (kn, xq ,xv, yv);
But then how to remove from in points contained in on?

Respuestas (1)

Adam Danz
Adam Danz el 30 de Ag. de 2021
Editada: Adam Danz el 8 de Sept. de 2021
Use the logical outputs to the inpolygon function.
[in,on] = inpolygon (kn, xq ,xv, yv);
  • on indicates all data that are on the edges of the polygon.
  • ~on indicates all data that are inside and outside of the polygon but not on the edges.
  • in indicates all data that are in the polygon but not on the edges.
  • ~in & ~on indicates all data not in the polygon nor on the edges.
Demo:
L = linspace(0,2*pi,6);
xv = cos(L)';
yv = sin(L)';
rng default
xq = [randn(60,1); xv(1:2)];
yq = [randn(60,1); yv(1:2)];
[in,on] = inpolygon(xq,yq,xv,yv);
clf
plot(xv, yv, 'k-', 'LineWidth', 1, 'DisplayName', 'Polygon')
hold on
plot(xq(in),yq(in),'c*','DisplayName','in') %plot data IN polygon
plot(xq(on),yq(on),'ro','LineWidth',2,'DisplayName','on') %plot data on border
plot(xq(~in&~on),yq(~in&~on),'k.','DisplayName','out') %plot data outside of polygon
axis equal
legend()
To remove points points on the edge, you can replace thier values with NaN (1st line below) or remove them (2nd line below).
xq(on) = nan; yq(on) = nan; % replace with NaN
xq(on) = []; yq(on) = []; % -OR- remove

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by