You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Matlab中生成仅显示正值区域的指定3D图形

解决方案

我有取值范围为[-1,1]的3D数据集,希望将所有正值区域以单一颜色显示,负值区域留空。目前我通过isosurface和patch函数生成了一张图形,使用的代码如下:

figure(1); clf;
p1=patch(isosurface(xx,yy,zz,real(u),0.));
set(p1,'FaceColor','r','EdgeColor','none'); daspect([1 1 1])
camlight;lighting phong; box on; axis image;
view(45,45);

现在想要生成类似目标图的效果(填充所有正值区域的表面,而非仅0值等值面)。


要实现完整显示正值区域的表面,需要同时绘制正负区域的交界面和正值区域在数据集边界上的封盖面,以下是两种可行的实现方式:

方法一:使用isosurface+isocaps(推荐)

这种方式能精准生成闭合的正值区域表面,代码如下:

figure(1); clf;
u_real = real(u);

% 生成正负区域交界的等值面(u=0)
p_surf = patch(isosurface(xx, yy, zz, u_real, 0));
set(p_surf, 'FaceColor', 'r', 'EdgeColor', 'none');

% 生成数据集边界上的正值区域封盖面
p_caps = patch(isocaps(xx, yy, zz, u_real, 0));
set(p_caps, 'FaceColor', 'r', 'EdgeColor', 'none');

% 统一显示参数
daspect([1 1 1]);
camlight; lighting phong; box on; axis image;
view(45, 45);
  • isosurface负责绘制u=0的等值面(正负区域的交界);
  • isocaps自动生成数据集边界上u>0区域对应的封盖,让整个正值区域表面闭合,匹配目标图效果。

方法二:掩码过滤负值区域

通过将负值区域设为NaN,再提取正值区域的最低等值面,代码如下:

figure(1); clf;
u_real = real(u);
% 掩码过滤负值区域
u_masked = u_real;
u_masked(u_real <= 0) = NaN;

% 提取正值区域的最低等值面
p = patch(isosurface(xx, yy, zz, u_masked, min(u_real(u_real>0))));
set(p, 'FaceColor', 'r', 'EdgeColor', 'none');

% 显示参数调整
daspect([1 1 1]);
camlight; lighting phong; box on; axis image;
view(45, 45);

内容的提问来源于stack exchange,提问作者rnp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 02:56:06