简体   繁体   English

用MATLAB随机曲面切割3D点云

[英]Cutting a 3D point cloud by a random surface by MATLAB

I have a 3D point cloud in a cube with a specified side length, filled with particles at totally random positions. 我在具有指定边长的立方体中有一个3D点云,在完全随机的位置填充了粒子。 Also, I have a surface that has the same side length as the cube, but with random values of Z for each X and Y, which makes it a random rough surface. 另外,我的表面的边长与立方体相同,但是每个X和Y的Z值都是随机的,这使其成为随机的粗糙表面。 All of these data are in my access in XYZ format. 我以XYZ格式访问所有这些数据。

What I want to do is to delete the particles in the cube that stands above that rough surface. 我要做的是删除位于该粗糙表面上方的多维数据集中的粒子。

The following generates a simple configuration of the problem: 以下生成问题的简单配置:

samples = 1000;

%data extrema
l = -2; h = 2;
zl = 0; zh = 5;

%The point cloud
xC = random('Uniform',l,h,[samples,1]);
yC = random('Uniform',l,h,[samples,1]);
zC = random('Uniform',zl,zh,[samples,1]);

scatter3(xC,yC,zC,1);

% # grid points
gp = 20;

% grid costruction
xS = linspace(l,h,gp);
yS = linspace(l,h,gp);
[xS,yS] = meshgrid(xS,yS);
xS = xS(:);
yS = yS(:);

% random rough surface
zS = random('Uniform',zl+2,zh-2,[length(xS),1]);

hold on
scatter3(xS,yS,zS);

Any help is appreciated. 任何帮助表示赞赏。

Using the following code, I could solve the problem: 使用以下代码,我可以解决问题:

%% THE PROBLEM
samples = 1000;

% data extrema
l = -2; h = 2;
zl = 0; zh = 5;

% the point cloud
xC = random('Uniform',l,h,[samples,1]);
yC = random('Uniform',l,h,[samples,1]);
zC = random('Uniform',zl,zh,[samples,1]);

scatter3(xC,yC,zC,1);

% # grid points
gp = 20;

% sample grid costruction
xS = linspace(l,h,gp);
yS = linspace(l,h,gp);
[xSm,ySm] = meshgrid(xS,yS);
zSm = random('Uniform',zl+2,zh-2,[length(xS),length(yS)]);
xS = xSm(:);
yS = ySm(:);
zS = zSm(:);
hold on
scatter3(xS,yS,zS);

%% THE SOLUTION
% estimation of the zS for XY of each point
for i = samples:-1:1
    x_t = xC(i);
    y_t = yC(i);
    Zq = interp2(xSm,ySm,zSm,x_t,y_t,'linear');

    % delete the point if it is located above the surface
    if zC(i)>Zq
        xC(i) = [];
        yC(i) = [];
        zC(i) = [];
    end
end
scatter3(xC,yC,zC,30,'b');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM