【问题标题】:Visualize volume under surface可视化表面下的体积
【发布时间】:2018-05-01 20:17:50
【问题描述】:

我想可视化由 2 变量函数生成的曲面下的 3D 体积。到目前为止,我可以生成表面,但我不知道如何实际可视化体积。

funCube = @(x,y)2.6207.*(sin(x)+cos(x)).*cos(y);
funCylinder = @(x, y) 3.078677852.*cos(y);

cubePlot = ezsurf(funCube, [0, 0.26, 0, 0.26], 120);
hold on;
cylinderPlot = ezsurf(funCylinder, [0, 0.26, 0, 0.26], 120);

【问题讨论】:

  • 不确定这是否是您的意思,但一种方法是,如果您有一个网格,并且您使用 1 标记网格上的所有点,以便在函数“内部”和 0对于在外面,您可以创建一个等值面(默认值为 0.5),这将为您提供一个 3D 补丁对象。

标签: matlab visualization matlab-figure volume surface


【解决方案1】:

这是使用填充多边形(patch 对象)的解决方案。这个想法是,除了表面之外,我们还创建了 5 个多边形来形成“4 个墙壁和一个地板”,而表面本身则充当“天花板”。

结果:

我会说它给人的印象是音量很好。

function q47361071
%% Definitions:
% Define a surface equation: z = f(x,y)
funCube = @(x,y)2.6207.*(sin(x)+cos(x)).*cos(y);
% Evaluate the surface equation at a grid of points:
X = 0:0.01:0.26; Y = X; 
[YY,XX] = meshgrid(X,Y);
ZZ = funCube(XX,YY);
%% Visualization:
figure(); surf(XX,YY,ZZ); hAx = gca; hold(hAx,'on'); view([-50 35]);
draw5Poly(hAx,XX,YY,ZZ); 
end

function draw5Poly(hAx,XX,YY,ZZ)
P = {[XX(1,1),   YY(1,1),  0; [XX(:,1)     YY(:,1)     ZZ(:,1)    ]; XX(end,1),YY(end,1),    0],...
     [XX(1,end), YY(1,end),0; [XX(:,end)   YY(:,end)   ZZ(:,end)  ]; XX(end,1),YY(end,end),  0],... 
     [XX(1,1),   YY(1,1),  0; [XX(1,:).'   YY(1,:).'   ZZ(1,:).'  ]; XX(1,end),YY(1,end),    0],...
     [XX(end,1), YY(end,1),0; [XX(end,:).' YY(end,:).' ZZ(end,:).']; XX(end,end),YY(end,end),0],...
     [XX(1,1),YY(1,1),0; XX(1,end),YY(1,end),0; XX(end,end),YY(end,end),0; XX(end,1),YY(end,1),0]};

for indP = 1:numel(P)
  patch(hAx, P{indP}(:,1),P{indP}(:,2),P{indP}(:,3),'k', 'FaceColor', 'y', 'FaceAlpha', 0.7);
end

end

您可能会注意到,辅助函数 draw5Poly 专为您只需要在每个轴上显示 一个 这样的体积的场景而设计。如果您对两个表面/体积执行此操作,则可能很难理解所有“墙壁”是否都是黄色 - 因此您可能希望将 FaceColor 作为函数的输入(因此您可以用不同的颜色绘制不同的体积)。

【讨论】:

  • 这正是我所需要的。非常感谢!
猜你喜欢
  • 1970-01-01
  • 2018-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多