Fits an ellipsoid or other conic surface into a 3D set of points approximating such a surface, allows some constraints, like orientation constraint and equal radii constraint. E.g., you can use it to fit a rugby ball, or a sphere. 'help ellipsoid_fit' says it all. Returns both the algebraic description of the ellipsoid (the nine coefficients of the quadratic form) and the geometric description (center, radii, principal axes).
Can you give a pdf which you referenced ?
Lots of questions below about how to use the output to correctly map points onto a unit sphere. Here's the answer:
corrected_point = C * (raw_point - center)
where corrected_point, raw_point, center are 3x1 vectors (x,y,z) and C = evecs*diag(1./radii)*evecs' is a symmetric 3x3 matrix.
If you'd rather have the points mapped onto a sphere of radius k (rather than unit sphere), then use k*C in the above instead of just C.
Works good, very useful. Thank you.
But I have the same question that is how to get three rotation angles,or how to calibrate the values? help for your help
Very nice work!
Is there any hack to constrain the conic type? I would like to fit my data on an ellipsoid, not on a paraboloid nor an hyperboloid.
Very useful, thank you! Is there a paper available which describes the math behind this code?
I also think it would be convenient to have an 'yz' constraint included.
hello, how to apply this code to a csv (x,y,z) file data
Very useful piece of code!
evecs is eigenvectors matrix. Following the principal axis theorem, eigenvectors represent principal axes of ellipsoid. Regarding use with magnetometer calibration, those are needed to perform so called "soft iron" calibration, in order to properly shrink the ellipsoid into sphere. I would recommend taking a look at freescale's AN4246 & AN4248.
very useful and smart!
This is well done. I especially appreciate the multiple input methods.
The flag=0 method can easily return imaginary results for noisy data. Note that the flag=0 method is also trying to find the primary axes of the ellipsoid. For those getting imaginary results when using flat=0 (the default), if your ellipsoid is expected to already be aligned with x, y, and z, then just use flag=1. This works quite well even when flag=0 falls apart.
I see some folks are using this for magnetometer data, which has a "hard iron" offset. To convert from raw data to points on a unit sphere:
[c, r] = ellipsoid_fit(raw, 1);
% For a single point, k:
unit_sphere(:, k) = (raw(:, k) - c)./r
% For multiple points, vectorized:
unit_sphere = diag(1./r) * (m - c * ones(1, size(m, 2)));
% Just for kicks using bsxfun:
unit_sphere = bsxfun(@times, 1./r, bsxfun(@minus, m, c))
Excellent code! however, for some ellipsoid data the radii values are imaginary what is the problem?. CAN ANYONE HELP PLEASE!!
I used your code but the results are not correct with my data. The eigen values are very big. Should you normalise the Covariance matrix? I would also want to ask how did you derive from the 9 parameters of ellipsoid, the covariance matrix, center etc.. which book, notes did u use?
If the ellipsoid passes through the origin (0,0,0), how can the default equation "Ax^2 + By^2 + Cz^2 + 2Dxy + 2Exz + 2Fyz + 2Gx + 2Hy + 2Iz = 1" represent that? Thanks!
Hi, did you find hot to determine those rotation angles?
Nice code, however
center--> Magnetometer offset
radii --> scaling factor
v---> the 9 parameters,
what is evecs?
what do i do next to get the calibrated values??? need help.....
Hi, nice and efficient piece of code.
Nevertheless, I believe that the polynomial expression that you compute in a first step is not guaranteed to be one of an ellipsoid. I think that it could be any quadric (hyperboloid, paraboloid, etc), right?
It is probably no problem if you have much data (corresponding to a real ellipsoid) to fit your quadric on.
But in case of sparse data (for instance, data points only on a couple of planes), you could have bad surprises (and in particular negative eigenvalues).
This is a fine piece of code
Working very good
I have a question: we can find the center, the radii of the ellipsoid and also the 3*3 direction matrix "evecs" using this program. Then how do you determine the three rotation angles using "evecs"?
Thanks for your help!
I am sorry, I meant how do you determine three rotation angles using "evecs" then?
Indicated that the code fits surfaces, not volumes.
Updated the function to give correct radii and chi2 when fitting other conics beside ellipsoids.
Fixed instability arising for data points near zero.
Just a better description.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.