简体   繁体   English

如何删除3D Matlab图的背面

[英]How can I remove the back faces of a 3D matlab plot

When plotting a 3d graph in matlab, the back faces of the bounding box are filled in white: 在Matlab中绘制3D图形时,边界框的背面用白色填充:

在此处输入图片说明

These can easily all be removed with 这些可以很容易地全部删除

ax = gca;
ax.Color = [0, 0, 0, 0];

How can I remove just the rear sides? 我怎样才能只取下背面? (everything but the floor) (除了地板上的所有东西)

Using the undocumented Axes.Backdrop property, you can sort of get this behaviour. 使用未记录的Axes.Backdrop属性,您可以得到这种行为。 Axes.Backdrop.Face.VertexData contains a list of the vertices of the backdrop. Axes.Backdrop.Face.VertexData包含背景顶点的列表。 We can find and keep the floor with: 我们可以找到并保持地板:

ax = gca;
face = ax.Backdrop.Face;

% can be replaced with conditions on other axes and limits
point_on_face = face.VertexData(3,:) == ax.ZLim(1);
is_target_face = all(reshape(point_on_face, 4, []));
target_face_verts = logical(kron(is_target_face, ones(1, 4)));

% discard all but the first quad (the floor)
face.VertexData = face.VertexData(:,target_face_verts);

However, when the axes are rotated, these quads are redrawn, making this not an effective solution. 但是,当轴旋转时,将重新绘制这些四边形,这不是有效的解决方案。

We can go further by adding an event listener: 我们可以通过添加事件监听器来进一步:

function h = set_walls(ax, varargin)
  function update()
    face = ax.Backdrop.Face;
    data = face.VertexData;
    if empty(data); return; end
    keep_verts = false(1, size(data, 2));
    for side = varargin'
      side = side{:};
      switch side
        case 'xmin'; point_on_face = data(1,:) == ax.XLim(1);
        case 'xmax'; point_on_face = data(1,:) == ax.XLim(2);
        case 'ymin'; point_on_face = data(2,:) == ax.YLim(1);
        case 'ymax'; point_on_face = data(2,:) == ax.YLim(2);
        case 'zmin'; point_on_face = data(3,:) == ax.ZLim(1);
        case 'zmax'; point_on_face = data(3,:) == ax.ZLim(2);
        otherwise; error('Unknown face');
      end
      is_target_face = all(reshape(point_on_face, 4, []));
      keep_verts = keep_verts | logical(kron(is_target_face, ones(1, 4)));
    end
    face.VertexData = data(:,keep_verts);
  end
  h = addlistener(ax, 'MarkedClean', @(x, y) update);
end

This flickers, but it works. 这会闪烁,但可以。 The function can be used as set_walls(gca, 'zmin') 该函数可用作set_walls(gca, 'zmin')

移除背景

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM