绘制内部有孔的多边形
Draw polygon with hole inside
我需要绘制一个矩形多边形,里面有一个矩形孔。我找到了这段代码,但我无法理解如何修改以满足我的要求。
figure()
p = [0 0; 0 1; 1 1; 1 0]; %ccw
pp = [0 0; 1 0; 1 1; 0 1]; %cw
ph = p + [1.2 0];
# add hole
ph(end+1,:) = nan;
ph = [ph; (pp-[0.5 0.5])*0.5+[1.7 0.5]];
po = polygon2patch (ph);
patch (po(:,1), po(:,2), 'b', 'facecolor', 'c');
axis image
polygon2patch
function certainly seems useful, but maybe for only drawing two rectangles, you could also use just two patch
命令,简单地将内部矩形,即孔,设置为白色前景色,如下所示:
outer = [0 0; 2 0; 2 1; 0 1];
inner = [0.4 0.2; 1.6 0.2; 1.6 0.8; 0.4 0.8];
patch(outer(:, 1), outer(:, 2), 'c');
patch(inner(:, 1), inner(:, 2), 'w');
axis equal;
这将产生这样的输出:
希望对您有所帮助!
我需要绘制一个矩形多边形,里面有一个矩形孔。我找到了这段代码,但我无法理解如何修改以满足我的要求。
figure()
p = [0 0; 0 1; 1 1; 1 0]; %ccw
pp = [0 0; 1 0; 1 1; 0 1]; %cw
ph = p + [1.2 0];
# add hole
ph(end+1,:) = nan;
ph = [ph; (pp-[0.5 0.5])*0.5+[1.7 0.5]];
po = polygon2patch (ph);
patch (po(:,1), po(:,2), 'b', 'facecolor', 'c');
axis image
polygon2patch
function certainly seems useful, but maybe for only drawing two rectangles, you could also use just two patch
命令,简单地将内部矩形,即孔,设置为白色前景色,如下所示:
outer = [0 0; 2 0; 2 1; 0 1];
inner = [0.4 0.2; 1.6 0.2; 1.6 0.8; 0.4 0.8];
patch(outer(:, 1), outer(:, 2), 'c');
patch(inner(:, 1), inner(:, 2), 'w');
axis equal;
这将产生这样的输出:
希望对您有所帮助!