I would like to plot a polygon with multiple holes in it, like this:
P = [
0.5, 0.8;
1.0, 0.0; % outer boundary
0.0, 0.0;
0.5, 0.8;
%{
%}
0.5, 0.3;
0.3, 0.1; % inner boundary I
0.7, 0.1; % (hole)
0.5, 0.3;
%{
%}
0.5, 0.6;
0.3, 0.4; % inner boundary II
0.7, 0.4; % (hole)
0.5, 0.6;
];
figure, clf, hold on
patch(P(:,1),P(:,2), 'r', 'linestyle', 'none')
However, patch
doesn't quite work the way I expected it to. When I change the last hole to this:
% ...
0.45, 0.6; % <- slightly offset in X-direction
0.3, 0.4;
0.7, 0.4;
0.45, 0.6; % <- slightly offset in X-direction
% ...
this happens:
This technique works nicely with a single hole, but can I also apply the same technique for multiple holes? Or do I have to resort to splitting it up, as shown here?
NOTE: Eventually, I'll be plotting hundreds of (possibly partially transparent) polygons in 3D space, and I want to be able to "look through" the holes. Therefore, solutions with a "white overlay" polygon are not what I'm looking for.