Boundary function fails, R2016b

조회 수: 4 (최근 30일)
Jukka Koskinen
Jukka Koskinen 2016년 12월 1일
댓글: Jukka Koskinen 2016년 12월 12일
I try to make a concave hull type boundary around several overlapping shapes (four circles in this case) by the boundary function. The following code illustrates the problem. The boundary is drawn in black color (better seen in attached file). It doesn't look good... It seems that there is a bug in the function?
if true
clear all;
close all;
r_1 = 5;
r_2 = 3;
r_3 = 2;
r_4 = 2;
center_1 = [2 2];
center_2 = [2 -2];
center_3 = [5 5];
center_4 = [-3 5];
alpha = 0:(2*pi)/120:2*pi;
circle_1 = [center_1(1)+r_1*sin(alpha)' center_1(2)+r_1*cos(alpha)'];
circle_2 = [center_2(1)+r_2*sin(alpha)' center_2(2)+r_2*cos(alpha)'];
circle_3 = [center_3(1)+r_3*sin(alpha)' center_3(2)+r_3*cos(alpha)'];
circle_4 = [center_4(1)+r_4*sin(alpha)' center_4(2)+r_4*cos(alpha)'];
shape = [circle_1
circle_2
circle_3
circle_4];
k = boundary(shape(:,2), shape(:,1), 1);
figure(1)
plot(circle_1(:,1), circle_1(:,2), 'r')
hold on;
grid on;
plot(circle_2(:,1), circle_2(:,2), 'b')
plot(circle_3(:,1), circle_3(:,2), 'g')
plot(circle_4(:,1), circle_4(:,2), 'm')
plot(shape(k,1), shape(k,2), 'k')
axis([-10 10 -10 10])
end
  댓글 수: 3
Jukka Koskinen
Jukka Koskinen 2016년 12월 2일
편집: Jukka Koskinen 2016년 12월 2일
The function works fine, when I move circle_4 center one step to the right (coordinates [-2,5]). But when coordinates are [-3,5] the function doesn't work properly, as seen above.
It should look like this:
Adam
Adam 2016년 12월 2일
Ah, ok, I kind of just ignored the inner black lines thinking they wee just part of the things being bounded.

댓글을 달려면 로그인하십시오.

채택된 답변

Massimo Zanetti
Massimo Zanetti 2016년 12월 7일
Hi Jukka, if you look at the plot of the boundary without superimposing it to the circles you can see (see first image below) that the shrinking is extreme. You set it to the maximum value of 1 with k = boundary(shape(:,2), shape(:,1), 1);. Thus, the algorithm finds points also in the interior of the major circle.
To solve for this, just relax the shrinking factor by setting it to .5 (the default value). So, invoke k = boundary(shape(:,2), shape(:,1), .5);. The result is shown in the second image. I think that is the one you need. :)
  댓글 수: 1
Jukka Koskinen
Jukka Koskinen 2016년 12월 12일
Actually I contacted support and the answer was pretty same: relax the shrinking factory.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by