How to extract boundary of a set of 2D points

조회 수: 8 (최근 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 CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by