Unexpected output form intersect (polyxpoly)

조회 수: 3 (최근 30일)
Benjamin Bernard
Benjamin Bernard 2020년 1월 26일
편집: Benjamin Bernard 2020년 1월 27일
I am getting an unexpected output when I try to apply intersect to the following two polygons:
A = [2 6 4 2 -1 0;
0 -1 2 4 6 2];
B = [0 6 6 0;
0 0 6 6];
C = intersect(A, B)
Namely, C contains the point [-1; 6], which it should not contain. What baffles me is that [6; -1] is correctly excluded, even though the two shapes are symmetric about the positive diagonal. The same mistake happens if I initialize A and B using the polyshape command:
A = polyshape([2 6 4 2 -1 0], [0 -1 2 4 6 2]);
B = polyshape([0 6 6 0], [0 0 6 6]);
Does anybody have an idea what is wrong?

답변 (1개)

Turlough Hughes
Turlough Hughes 2020년 1월 26일
When you're using intersect to do what you have described you need to ensure you have inputs of either two polyshapes, a polyvec, or a polyshape and a linsegment as described here. Your input was two arrays and so you ended up doing a set intersection which has it's own seperate documention.
Try the following:
A = polyshape([2 6 4 2 -1 0], [0 -1 2 4 6 2]);
B = polyshape([0 6 6 0], [0 0 6 6]);
C = intersect(A,B);
figure(), plot(A)
hold on, plot(B)
plot(C,'FaceAlpha',0,'LineWidth',3,'EdgeColor','red')
  댓글 수: 2
Turlough Hughes
Turlough Hughes 2020년 1월 26일
Did the plot above work for you?
Benjamin Bernard
Benjamin Bernard 2020년 1월 27일
편집: Benjamin Bernard 2020년 1월 27일
MATLAB correctly identifies it as a polyshape intersection, not a set intersection, if I step through the execution of the code. As I have mentioned in my original post, yesterday I had the same problem regardless of whether I initialized A and B as a polyshape object or not. Yet somehow your suggested code (which is identical to my second code fragment in my OP), works today even though the output was erroneous yesterday. Still at a complete loss as to why it is the case..

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

카테고리

Help CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by