首页 文章

在Matlab中插入3D圆柱体的表面

提问于
浏览
10

我有一个描述3D圆柱点 Cloud 的数据集( xx,yy,zz,C ):
3D point cloud

我想从这个数据集制作一个表面图,类似于这个
enter image description here

为了做到这一点,我想我可以使用 TriScatteredInterp 将我的散乱数据插入到常规网格中,然后使用 surf 绘制它:

F = TriScatteredInterp(xx,yy,zz);
max_x = max(xx); min_x = min(xx);
max_y = max(yy); min_y = min(yy);
max_z = max(zz); min_z = min(zz);
xi = min_x:abs(stepSize):max_x;
yi = min_y:abs(stepSize):max_y;
zi = min_z:abs(stepSize):max_z;
[qx,qy] = meshgrid(xi,yi);
qz = F(qx,qy);
F = TriScatteredInterp(xx,yy,C);
qc = F(qx,qy);

figure
surf(qx,qy,qz,qc);
axis image

这对于凸面和凹面的物体非常有效,但对于圆柱体则以此结束:
enter image description here

任何人都可以帮助我如何实现更好的情节?

4 回答

  • 0

    你试过Delaunay三角测量吗?

    http://www.mathworks.com/help/matlab/ref/delaunay.html

    load seamount
    tri = delaunay(x,y);
    trisurf(tri,x,y,z);
    

    plot

    还有TriScatteredInterp

    http://www.mathworks.com/help/matlab/ref/triscatteredinterp.html

    ti = -2:.25:2;
    [qx,qy] = meshgrid(ti,ti);
    qz = F(qx,qy);
    mesh(qx,qy,qz);
    hold on;
    plot3(x,y,z,'o');
    

    enter image description here

  • 1

    我认为你所要求的是Convex hull功能 . 查看其文档 .

    K = convhull(X,Y,Z)返回点(X,Y,Z)的3-D凸包,其中X,Y和Z是列向量 . K是表示凸包边界的三角剖分 . K的大小为mtri-by-3,其中mtri是三角形小平面的数量 . 也就是说,K的每一行是根据点索引定义的三角形 .

    2D中的示例

    xx = -1:.05:1; yy = abs(sqrt(xx));
    [x,y] = pol2cart(xx,yy);
    k = convhull(x,y);
    plot(x(k),y(k),'r-',x,y,'b+')
    

    enter image description here

    使用plot绘制2-D中的convhull输出 . 使用trisurf或trimesh绘制3-D中的convhull输出 .

  • 0

    圆柱体是与线条等距的所有点的集合 . 所以你知道你的数据有一个共同点,那就是它们都应该位于与对称线相等的距离 . 您可以使用它来生成新的圆柱体(在此示例中,对称线为z轴):

    % best-fitting radius 
    % NOTE: only works if z-axis is cylinder's line of symmetry
    R = mean( sqrt(xx.^2+yy.^2) );
    
    % generate some cylinder
    [x y z] = cylinder(ones(numel(xx),1));
    
    % adjust z-range and set best-fitting radius
    z = z * (max(zz(:))-min(zz(:))) + min(zz(:));
    x=x*R;
    y=y*R;
    
    % plot cylinder
    surf(x,y,z)
    
  • 1

    TriScatteredInterp适用于拟合z = f(x,y)形式的2D表面,其中f是单值函数 . 它不适合像你一样适合点 Cloud .

    由于您正在处理一个圆柱体,实际上是一个2D曲面,如果转换为极坐标,您仍然可以使用TriScatterdInterp,并且,例如,将半径拟合为角度和高度的函数 - 如下所示:

    % convert to polar coordinates:
    theta = atan2(yy,xx);
    h = zz;
    r = sqrt(xx.^2+yy.^2);
    
    % fit radius as a function of theta and h
    RFit = TriScatteredInterp(theta(:),h(:),r(:));
    
    % define interpolation points
    stepSize = 0.1;
    ti = min(theta):abs(stepSize):max(theta);
    hi = min(h):abs(stepSize):max(h);
    [qx,qy] = meshgrid(ti,hi);
    % find r values at points:
    rfit = reshape(RFit(qx(:),qy(:)),size(qx));
    % plot
    surf(rfit.*cos(qx),rfit.*sin(qx),qy)
    

相关问题