How to extract boundary of a set of 2D points

7 ビュー (過去 30 日間)
Wang Jack
Wang Jack 2020 年 7 月 27 日
回答済み: Cris LaPierre 2020 年 12 月 7 日
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 Center および File ExchangeLogical についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by