How to fit largest ellipsoid for 3d data points such that it covers all points?
5 次查看(过去 30 天)
显示 更早的评论
Hi, I have search a lot for ellipsoid fit to 3d data and come up with some answer but I want some improvement in my method such that it covers all the data points. My code is here.
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.-')
end
The data file is here.
1 个评论
Baptiste Ottino
2017-8-7
What do you mean by "covers all the data points". Do you want an ellipsoid that encompasses all the data points? Or is all your data located on the surface of an ellipsoid for sure?
回答(1 个)
Image Analyst
2017-8-8
I think it's pretty difficult. John did the same thing in 2-D here http://www.mathworks.com/matlabcentral/fileexchange/34767-a-suite-of-minimal-bounding-objects If it were easy he'd probably have done it already.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!