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?
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!