我有以下matlab代码:
clear all
close all
clc
np = 10; % number of points along cylinder height
nc = 15; % points in circumference
h = 5.; % cylinder height
r = 1.; % cylinder radius
t = linspace(0, 2*pi, nc); % angle in rad
dh = h/(np-1); % height difference between two points
for i = 1:np
for j = 1:nc
x(i,j) = r*cos(t(j));
y(i,j) = r*sin(t(j));
z(i,j) = (i-1) * dh;
end
end
% a colormap for reference, i am using sthing else in my code
f = sqrt(x.^2 + y.^2 + z.^2);
subplot(1,2,1)
surf(x,y,z,f)
axis equal
subplot(1,2,2)
mesh(x,y,z,f)
axis equal
这会生成一个圆柱体形状的网格。现在,我可以用这个脚本输入命令将这个网格文件转换为stl格式,surf2stl('test.stl',x,y,z,'ascii')
并可以用paraview打开它。
但在那种情况下,如果它是 stl,我会丢失颜色图(来自 matlab 脚本的 f 变量)。我想要的是有可能拥有带有阴影表面的 stl。或者,如果我可以将此网格导出为 VTK 文件格式,我更愿意,但我不知道如何。所以我正在寻找如何将 matlab 的冲浪或网格数据转换为 VTK 格式。(编辑:或第三个选项将matlab网格转换为stl,然后将stl转换为vtk并将标量f添加到vtk文件)。
我首先在 stackoverflow 中搜索了可能的重复项,但这不一样并且没有答案。