How to fit largest ellipsoid for 3d data points such that it covers all points?

4 views (last 30 days)
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 Comment
Baptiste Ottino
Baptiste Ottino on 7 Aug 2017
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?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 8 Aug 2017
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.
  1 Comment
ankit agrawal
ankit agrawal on 8 Aug 2017
Thank you for answer. Someone told me about Khachiyan Algorithm and it is working very fine. https://github.com/minillinim/ellipsoid/blob/master/ellipsoid.py

Sign in to comment.

Categories

Find more on Curve Fitting Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!