【问题标题】:MATLAB - Isosurface function, irregular coordinates (Input grid is not a valid MESHGRID)MATLAB - 等值面函数,不规则坐标(输入网格不是有效的 MESHGRID)
【发布时间】:2015-03-20 15:34:14
【问题描述】:

我有一个来自物理模型的数据文件,它显示了物体周围某种材料的密度。数据文件位于球坐标中,并被重新调整为其原始尺寸(Theta、Phi、R 和密度)。 Sph2cart 用于从球坐标转换为笛卡尔 (x,y,z) 坐标。为了可视化对象周围的不同密度,我在 MATLAB 中找到了等值面函数(例如:http://www.mathworks.com/matlabcentral/answers/110977-3d-density-plot-multiple-isosurfaces-on-the-same-plot)。

这是我目前拥有的代码:

input = importdata( 'denNa20.dat' );
input(1,:)=[]; 

theta = reshape(input(:,3),200,20,40);
phi = reshape(pi/2 - input(:,2),200,20,40);
r = reshape(input(:,1),200,20,40);
density = reshape(input(:,4),200,20,40);

[x,y,z] = sph2cart(theta,phi,r);

% This has ofcourse the complete wrong dimensions but then it works
% [x,y,z] = meshgrid(1:1:20,1:1:200,1:1:40);

p = patch(isosurface(y,x,z,density,0.00001));
isonormals(x,y,z,density,p);
set(p,'FaceColor','red','EdgeColor','none','FaceAlpha',0.15);
daspect([1 1 1])
view(3)
grid on
camlight; lighting phong

当我运行代码时,我收到以下错误:

使用 interp3 时出错(第 146 行) 输入网格不是有效的 MESHGRID。

等正规线中的错误(第 75 行) n(:,1)=interp3(x, y, z, nx, verts(:,1), verts(:,2), verts(:,3));

data_import_plot 中的错误(第 16 行) isonormals(x,y,z,密度,p);

如果我用非常简单的 x、y、z 坐标创建自己的网格网格(在代码中检查 %),它就可以工作。我不知道我做错了什么。我希望有人可以帮助我。

干杯, 杰伦

附:如果您愿意,可以从此链接https://www.dropbox.com/s/msphgmg2oyi91cx/denNa20.dat?dl=0下载数据文件

【问题讨论】:

    标签: matlab mesh density-plot cartesian-coordinates


    【解决方案1】:

    我发现问题在于等值面不接受不规则的 x、y 和 z 坐标。这就是我发现的解决方案。我使用scatterInterpolant 插值密度,然后创建我自己的网格。

    input = importdata( 'denNa20.dat' );
    input(1,:)=[]; 
    
    [x,y,z] = sph2cart(input(:,3),pi/2 - input(:,2),input(:,1));
    density = input(:,4);
    
    F = scatteredInterpolant(x,y,z,density);
    xRange = linspace(min(x),max(x),75);
    yRange = linspace(min(y),max(y),75);
    zRange = linspace(min(z),max(z),75);
    [x,y,z] = meshgrid(xRange,yRange,zRange);
    density = F(x,y,z);
    
    axis([-5000,5000,-5000,5000,-5000,5000])
    
    p = patch(isosurface(x,y,z,density,0.00001));
    isonormals(x,y,z,density,p);
    set(p,'FaceColor','red','EdgeColor','none','FaceAlpha',0.50);
    daspect([1 1 1])
    view(3)
    grid on
    camlight; lighting phong
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-14
      • 2013-03-13
      • 2014-03-08
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多