Sphere Fit
Given 4+ points in 3D space, this function attempts to find the center of a sphere and its radius.
Consider that there are 4 points or more on the surface of a sphere, then the sphere equation may then be represented by (x-a)^2 + (y-b)^2 + (z-c)^2 = r^2, where a,b,c and r are the unknowns and x,y,z are known data points.
For each data point (x,y,z), the above equation may be reduced to a linear equation that has a,b,c and r as variables.
-2ax -2by -2cz + (a^2+b^2+c^2-r^2) = -(x^2 + y^2 + z^2).
Let D = (a^2+b^2+c^2-r^2),, then the above equation will reduce to
-2ax -2by -2cz + D = -(x^2 + y^2 + z^2)
For each data point, the above equation may be reduced to AA*X = BB and solved for X using the mldivide() or '\' operator.
The solution is not a least-squares solution in its truest sense, since the residuals aren't being minimized. This solution may be used as an initial guess to the lsqnonlin() function which may implement a Gauss-Newton or a Levenberg–Marquardt algorithm.
Cite As
Prem Rachakonda (2026). Sphere Fit (https://www.mathworks.com/matlabcentral/fileexchange/45910-sphere-fit), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Mathematics > Linear Algebra >
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
