Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find the best-fit sphere for a set of points
ResourceFunction["SphereFit"][pts] returns the best-fit Sphere for the points pts. | |
ResourceFunction["SphereFit"][w→pts] returns the best-fit Sphere using the weights w. | |
ResourceFunction["SphereFit"][pts,"Association"] returns an Association with the center, radius, Sphere, and a pure function defining the sphere. |
Find the best-fit Sphere for the given points:
| In[1]:= |
| Out[2]= |
See the result along with the points:
| In[3]:= |
| Out[5]= | ![]() |
Fit a sphere through a noisy 1000 points:
| In[6]:= | ![]() |
| Out[9]= | ![]() |
Get all the properties:
| In[10]:= |
| Out[11]= | ![]() |
Use the "Function" to create a definition of the sphere:
| In[12]:= |
| Out[12]= |
Specify weights for outliers:
| In[13]:= | ![]() |
| Out[15]= | ![]() |
For two points, the fit goes through both:
| In[16]:= | ![]() |
| Out[17]= | ![]() |
For three points, the fit goes through all the points:
| In[18]:= | ![]() |
| Out[19]= | ![]() |
For four points, the fit goes through all the points:
| In[20]:= | ![]() |
| Out[21]= | ![]() |
If the points fall on a sphere and cover more than a hemisphere, BoundingRegion can give similar results:
| In[22]:= | ![]() |
| Out[24]= |
When 3 points are given and they are collinear, a Failure object is returned:
| In[25]:= |
| Out[25]= |
When 4 or more points are given and they are coplanar, a Failure object is returned:
| In[26]:= | ![]() |
| Out[27]= |
Fit points that only lay on one-eighth of a sphere:
| In[28]:= | ![]() |
| Out[29]= | ![]() |
Wolfram Language 14.0 (January 2024) or above
This work is licensed under a Creative Commons Attribution 4.0 International License