How to extract boundary of a set of 2D points

7 次查看(过去 30 天)
There is my code
LL1_x=(-0.1:.01:0.1)';
LL1=[LL1_x,-0.1*ones(length(LL1_x),1)];
LL2_y=(-0.1:.01:0.1)';
LL2=[0.1*ones(length(LL1_x),1),LL2_y];
LL3=[LL1(:,1),LL1(:,2)+0.2];
LL4=[LL2(:,1)-0.2,LL2(:,2)];
LL=[LL1;LL2;LL3;LL4]*1.6;
k = boundary(LL);
plot(LL(:,1),LL(:,2),'o');hold on
plot(LL(k,1),LL(k,2),'-')
This function works normally in most cases, but in this particular time, I didn't get the desired result. What's wrong?

回答(1 个)

Cris LaPierre
Cris LaPierre 2020-12-7
I can't describe why it picked those two points to go haywire on, and why it only appears at certain multiples (not when multiplying by 1-1.4. Appears with 1.5, 1.6, but not 1.7).
I was able to fix the issue by adding a sortrows around the vector concatenation that creates LL.
LL1_x=(-0.1:.01:0.1)';
LL1=[LL1_x,-0.1*ones(length(LL1_x),1)];
LL2_y=(-0.1:.01:0.1)';
LL2=[0.1*ones(length(LL1_x),1),LL2_y];
LL3=[LL1(:,1),LL1(:,2)+0.2];
LL4=[LL2(:,1)-0.2,LL2(:,2)];
figure
LL=sortrows([LL1;LL2;LL3;LL4]*1.6);
k = boundary(LL);
plot(LL(:,1),LL(:,2),'o');
hold on
plot(LL(k,1),LL(k,2),'-')
hold off

类别

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

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by