【问题标题】:How can I make a cylindrical 3D contour plot in Matlab?如何在 Matlab 中制作圆柱形 3D 等高线图?
【发布时间】:2024-04-22 23:00:01
【问题描述】:

我有一个轴对称流,在 r 和 z 方向上有 m x n 个网格点,我想在 3D 圆柱图中绘制存储在大小为 mxn 的矩阵中的温度,如下面的链接所示(我的声誉不高足以将其作为图片包含在内)。

我已经设法使用轮廓在 2D(r,z 平面)中绘制它,但我想添加 theta 平面以进行可视化。我该怎么做?

【问题讨论】:

  • 我认为有些工作可以在图像编辑软件中完成。您需要制作一个圆柱图和两个矩形imagesc 温度图。将绘图导出到图像编辑软件并裁剪和倾斜(扭曲)温度图像,然后将其粘贴到圆柱图中。
  • 请分享您已经制作的代码\数据...
  • 共享代码将是模棱两可的,因为它包含许多冗余代码行。该问题可以近似为 'r = linspace(0,1,10); z = linspace(0,5,10); T = 10*兰特(10,10); contourf(r,z,T)' 给出一个 10 x 10 的网格,在 r,z 平面上具有 10x10 的数据点矩阵

标签: matlab contour cylindrical


【解决方案1】:

您可以通过多次致电surface() 来创建自己的。 关键思想是:对于每个表面:(1) theta=theta1, (2) theta=theta2, (3) z=zmax, (4) z=0, (5) r=rmax, 生成 3D 网格 (xx, yy,zz) 和该网格上的温度图。所以你必须考虑如何构建每个表面网格。
编辑:现在提供完整的代码。所有幻数和假数据都放在(几乎)代码的顶部,因此很容易将其转换为通用的 Matlab 函数。祝你好运!

% I have adjusted the range values to show the curved cylinder wall 
% display a variable temperature
r = 0:0.1:2.6; % you can also try r = 0:0.1:3.0
z = 0:0.1:10;  % you can also try z = 0:0.1:15;
[rr, zz] = meshgrid(r,z);

% fake temperature data
temp = 100 + (10* (3-rr).^0.6) .* (1-((zz - 7.5)/7.5).^6) ;

% visualize in 2D
figure(1);
clf;
imagesc(r,z,temp);
colorbar;

% set cut planes angles
theta1 = 0;
theta2 = pi*135/180;
nt = 40;  % angle resolution

figure(2);
clf;

xx1 = rr * cos(theta1);
yy1 = rr * sin(theta1);
h1 = surface(xx1,yy1,zz,temp,'EdgeColor', 'none');

xx2 = rr * cos(theta2);
yy2 = rr * sin(theta2);
h2 = surface(xx2,yy2,zz,temp,'EdgeColor', 'none');

% polar meshgrid for the top end-cap
t3 = linspace(theta1, (theta2 - 2*pi), nt);
[rr3, tt3] = meshgrid(r,t3);
xx3 = rr3 .* cos(tt3);
yy3 = rr3 .* sin(tt3);
zz3 = ones(size(rr3)) * max(z);
temp3 = zeros(size(rr3));
for k = 1:length(r)
    temp3(:,k) = temp(end,k);
end
h3 = surface(xx3,yy3,zz3,temp3,'EdgeColor', 'none');

% polar meshgrid for the bottom end-cap
zz4 = ones(size(rr3)) * min(z);
temp4 = zeros(size(rr3));
for k = 1:length(r)
    temp4(:,k) = temp(1,k);
end
h4 = surface(xx3,yy3,zz4,temp4,'EdgeColor', 'none');

% generate a curved meshgrid
[tt5, zz5] = meshgrid(t3,z);
xx5 = r(end) * cos(tt5); 
yy5 = r(end) * sin(tt5); 
temp5 = zeros(size(xx5));
for k = 1:length(z)
    temp5(k,:) = temp(k,end);
end
h5 = surface(xx5, yy5, zz5,temp5,'EdgeColor', 'none');

axis equal
colorbar
view(125,25);  % viewing angles

【讨论】:

    最近更新 更多