如果我在 Matlab 中获得了一个轮廓
[f, v] = isosurface(x, y, z, v, isovalue)
有没有一种干净的方法来对表面应用变换并将结果很好地绘制为光滑的表面?变换T
是非线性的。
我试图将转换应用T
到f
andvert
和 usepatch
但不能完全让它工作。
如果我在 Matlab 中获得了一个轮廓
[f, v] = isosurface(x, y, z, v, isovalue)
有没有一种干净的方法来对表面应用变换并将结果很好地绘制为光滑的表面?变换T
是非线性的。
我试图将转换应用T
到f
andvert
和 usepatch
但不能完全让它工作。
诀窍是将转换应用于您的vertices
,但保留相同的faces
数据。这样,面总是连接相同的点,而不管它们的新位置。
由于没有样本数据,我以 Matlab 示例为起点。这来自 Matlabisosurface
页面(对本示例进行了轻微修改):
%// Generate an isosurface
[x,y,z,v] = flow;
fv = isosurface(x,y,z,v,-3) ;
figure(1);cla
p1 = patch(fv,'FaceColor','red','EdgeColor','none');
%// refine the view
grid off ; set(gca,'Color','none') ; daspect([1,1,1]) ; view(3) ; axis tight ; camlight ; lighting gouraud
这个输出:
目前还没有原创。请注意,我使用了单结构输出类型fv
而不是 2 个单独的数组[f,v]
。这并不重要,只是为了简化对补丁对象的下一次调用的选择。
我需要检索顶点坐标:
%// Retrieve the vertices coordinates
X = fv.vertices(:,1) ;
Y = fv.vertices(:,2) ;
Z = fv.vertices(:,3) ;
然后,您可以应用您的转换。我在这个例子中选择了一个简单的,但是任何转换函数都是有效的。
%// Transform
X = -X.*Y.^2 ;
Y = Y.*X ;
Z = Z*2 ;
然后我为将显示转换后的对象的补丁重建一个新结构。
这是重要的一点:
%// create new patch structure
fvt.vertices = [X Y Z] ; %// with the new transformed 'vertices'
fvt.faces = fv.faces ; %// but we keep the same 'faces'
然后我以相同的方式显示它(为了更好的视图,角度略有不同):
%// Plot the transformed isosurface
figure(2);cla
pt = patch( fvt ,'FaceColor','red','EdgeColor','none');
%// refine the view
grid off ; set(gca,'Color','none') ; daspect([1,1,1]) ; view(-3,4) ; axis tight ; camlight ; lighting gouraud
这产生了这个数字:
(如果您将所有代码片段粘贴到一个文件中,它应该会运行并为您提供相同的输出。)