2017-05-27 404 views
0

我想計算點雲中某些點的均值和高斯曲率。 我有x,y,z,它們是座標並且是1d數組。我想使用下面的代碼,但在輸入參數中,X,Y和Z是2d數組,我不知道這意味着什麼,以及如何計算與它們對應的2d數組。 非常感謝在matlab中計算曲面的曲率

function [K,H,Pmax,Pmin] = surfature(X,Y,Z), 
% SURFATURE - COMPUTE GAUSSIAN AND MEAN CURVATURES OF A SURFACE 
% [K,H] = SURFATURE(X,Y,Z), WHERE X,Y,Z ARE 2D ARRAYS OF POINTS ON THE 
% SURFACE. K AND H ARE THE GAUSSIAN AND MEAN CURVATURES, RESPECTIVELY. 
% SURFATURE RETURNS 2 ADDITIONAL ARGUEMENTS, 
% [K,H,Pmax,Pmin] = SURFATURE(...), WHERE Pmax AND Pmin ARE THE MINIMUM 
% AND MAXIMUM CURVATURES AT EACH POINT, RESPECTIVELY. 


% First Derivatives 
[Xu,Xv] = gradient(X); 
[Yu,Yv] = gradient(Y); 
[Zu,Zv] = gradient(Z); 

% Second Derivatives 
[Xuu,Xuv] = gradient(Xu); 
[Yuu,Yuv] = gradient(Yu); 
[Zuu,Zuv] = gradient(Zu); 

[Xuv,Xvv] = gradient(Xv); 
[Yuv,Yvv] = gradient(Yv); 
[Zuv,Zvv] = gradient(Zv); 

% Reshape 2D Arrays into Vectors 
Xu = Xu(:); Yu = Yu(:); Zu = Zu(:); 
Xv = Xv(:); Yv = Yv(:); Zv = Zv(:); 
Xuu = Xuu(:); Yuu = Yuu(:); Zuu = Zuu(:); 
Xuv = Xuv(:); Yuv = Yuv(:); Zuv = Zuv(:); 
Xvv = Xvv(:); Yvv = Yvv(:); Zvv = Zvv(:); 

Xu   = [Xu Yu Zu]; 
Xv   = [Xv Yv Zv]; 
Xuu   = [Xuu Yuu Zuu]; 
Xuv   = [Xuv Yuv Zuv]; 
Xvv   = [Xvv Yvv Zvv]; 

% First fundamental Coeffecients of the surface (E,F,G) 
E   = dot(Xu,Xu,2); 
F   = dot(Xu,Xv,2); 
G   = dot(Xv,Xv,2); 

m   = cross(Xu,Xv,2); 
p   = sqrt(dot(m,m,2)); 
n   = m./[p p p]; 

% Second fundamental Coeffecients of the surface (L,M,N) 
L   = dot(Xuu,n,2); 
M   = dot(Xuv,n,2); 
N   = dot(Xvv,n,2); 

[s,t] = size(Z); 

% Gaussian Curvature 
K = (L.*N - M.^2)./(E.*G - F.^2); 
K = reshape(K,s,t); 

% Mean Curvature 
H = (E.*N + G.*L - 2.*F.*M)./(2*(E.*G - F.^2)); 
H = reshape(H,s,t); 

% Principal Curvatures 
Pmax = H + sqrt(H.^2 - K); 
Pmin = H - sqrt(H.^2 - K); 

回答

0

你有辦法轉換你的X,Y,Z數據表面矩陣/二維數組。方式取決於你的數據是什麼,如何和什麼。

  1. 結構網格數據:

    (i)中。如果你的x,y,z對應一個結構化網格,那麼你可以直接得到x,y的唯一值,沿着x和y軸分別給出沿着10(nx,ny)的點數。有了這個(nx,ny),您需要將x,y,z數據分別重塑爲矩陣X,Y,Z並使用您的函數。 (ii)。如果你不好嗎與重塑,就可以得到分鐘最大x的值,Y使自己的電網使用meshgrid和使用的GridData做插值。

  2. 非結構化網格數據:如果你的數據是非結構化/分散,得到分鐘最大,使用meshgrid讓你的網格,並使用的GridDatascatteredInterpolant做插值。

也有以下鏈接看看:

https://in.mathworks.com/matlabcentral/fileexchange/56533-xyz2grd

https://in.mathworks.com/matlabcentral/fileexchange/56414-xyz-file-functions