通过 MATLAB 通过随机表面切割 3D 点云



我在一个具有指定边长的立方体中有一个3D点云,在完全随机的位置填充粒子。此外,我有一个与立方体边长相同的表面,但每个 X 和 Y 的随机值为 Z,这使它成为一个随机粗糙的表面。所有这些数据都以XYZ格式由我访问。

我想做的是删除立方体中位于粗糙表面上方的粒子。

下面生成问题的简单配置:

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);

任何帮助,不胜感激。

使用以下代码,我可以解决问题:

%% 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');

最新更新