2016-02-19 118 views
0

我在具有指定邊長的立方體中有一個3D點雲,在完全隨機的位置上填充了粒子。另外,我有一個與立方體具有相同邊長的表面,但是對於每個X和Y具有隨機值Z,這使得它成爲一個隨機的粗糙表面。所有這些數據都以XYZ格式存取。通過MATLAB隨機曲面切割3D點雲

我想要做的是刪除站在粗糙表面上方的立方體中的粒子。

下產生問題的一個簡單的配置:

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

任何幫助理解。

+0

「刪除」 是指設置爲0?您需要爲該(X,Y)對定義一個Z值。如果只是從雲Z值('zC-zS')中減去表面Z值?然後保持正值的值在表面之上,負值在表面之下 –

+0

通過「刪除」我的意思是從雲中移除該點。而且,如果我能夠管理如何將隨機分佈雲的XY與規則分佈的表面進行比較,那麼這種減法方法就可以很好地工作;不過,我不知道該怎麼做。 – user2969863

+0

您必須內插(X,Y)座標以匹配表面中最近的座標。看看那個:http://ch.mathworks.com/help/matlab/math/interpolating-gridded-data.html#bs5vl1n –

回答

0

使用下面的代碼,我可以解決這個問題:

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

你應該能夠插入所有的點而不用'for'循環。然後一次刪除所有不需要的點。否則使用循環會慢幾個數量級。 –

+0

我正在使用一個非常大的系統,有時在雲中有超過一百萬個粒子,我想通過不使用循環的方式導致內存錯誤。 – user2969863