如何为3d数据点拟合最大的椭球,使其覆盖所有点?

时间:2017-08-07 05:43:20

标签: matlab ellipse data-fitting

我经常搜索适合3d数据的椭圆体并得出一些答案,但我希望我的方法有一些改进,以便它涵盖所有数据点。我的代码在这里。

Y=data;  % data in non-principle coordinate 
X = data;
oldmu =mean(X);
X= bsxfun(@minus,X,oldmu); % mean-centered data
[pc val] = eig(X'*X  ); 

nC = X*pc;   % data in principle coordinate 
a2=(max(nC(:,1))-min(nC(:,1)))/2;  %range of data in X 
b2=(max(nC(:,2))-min(nC(:,2)))/2;  %range of data in Y
c2=(max(nC(:,3))-min(nC(:,3)))/2;  %range of data in Z
[x, y, z] = ellipsoid(0,0,0,a2,b2,c2,40); % fit ellipsoid in principle coordinate 

tt=[x(:) y(:) z(:)]*inv(pc);   %ellipsoid in non-principle coordinate
nx=reshape(tt(:,1),size(x,1),size(x,2));
ny=reshape(tt(:,2),size(x,1),size(x,2));
nz=reshape(tt(:,3),size(x,1),size(x,2));
% plot ellipsoid in non-principle coordinate 
hSurface=surf(nx+oldmu(1), ny+oldmu(2), nz+oldmu(3),    'FaceColor','r','EdgeColor','none','FaceAlpha',0.6);

hold on 
%plot data in non-principle coordinate 
plot3(Y(:,1),Y(:,2),Y(:,3),'k.-')

您可以在此处查看数据 https://www.imsc.res.in/~aagrawal/data enter image description here

0 个答案:

没有答案