Unexpected output form intersect (polyxpoly)
3 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Elementary Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!