Code covered by the BSD License  

Highlights from
Sphere Fit (least squared)


5.0 | 12 ratings Rate this file 82 Downloads (last 30 days) File Size: 30.7 KB File ID: #34129
image thumbnail

Sphere Fit (least squared)



08 Dec 2011 (Updated )

Fits a sphere to a set of noisy data. Does not require a wide arc or many points.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

Given a set of data points, this function calculates the center and radius of the data in a least squared sense. The least squared equations are used to reduce the matrix that is inverted to a 3x3, opposed to doing it directly on the data set. Does not require a large arc or many data points. Assumes points are not singular (co-planar) and real...
Created on R2010b, but should work on all versions.

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (17)
14 Oct 2014 Kao

Dear Alan,
Great work. May I have your relate paper? I am interested in this algorithm. my email:

Many thanks

14 Oct 2014 Kao  
15 Sep 2014 Casey  
07 Sep 2014 Pierrick Bersier  
25 May 2014 li

good work!

10 Mar 2014 Patrick

Dear Alan,
thanks for this great function! Is there any chance for me to get the related papers explaining this method, as well? Tried to research it the whole day - without succes...
Thanks a lot!

23 Jan 2014 Sa

Dear Alan,
Outstanding work! Could you send me the related paper explaining this method?

30 Jun 2013 Farsat Balata

Dear Alan, could you please, explain more about the two vectors A and B. I don't understand the rationality of Error function you defined as sum((x-xc)^2+(y-yc)^2+(z-zc)^2-r^2)^2,. Is the initial sphere center is taken for partial of the error of each parameter for example xc= mean(x), yc=mean (y) and zc= mean (z) and the function E = sum((xi-mean(x))^2+(y-mean(y))^2+(z-mean(z))^2-r^2)^2 and then, minimze the function E. many thanks

30 Jun 2013 Farsat Balata

Dear Alan, pointing to my previous comment, I have just want to correct the equation
E = sum((xi-mean(x))^2+(yi-mean (y))^2+(zi-mean(z))^2-r^2)^2

06 May 2013 Farsat Balata

Hi Alan,
Great work I would be happy if you could send me the related paper describing the method.

04 Apr 2013 JamesAb

Hi Alan. Great code! I really appreciate if you could send me the related paper describing the method:

Many thanks!

26 Mar 2013 Simao

Hi Alan. Great work! can you please send me the relating papers?

much appreciated

11 Mar 2013 Chloe

Hi Alan, any chance you could please send me the relating papers to

Thanks for the code. Works perfect!

22 Jan 2013 Laurens

Works great!

I was wondering if you could send me the paper as well (email:

Also, how would this look if the radius was known?

19 Dec 2012 luo

Dear Alan, can you send me the related papers? You know, I don't understand the rationality of Error function you defined as sum((x-xc)^2+(y-yc)^2+(z-zc)^2-r^2)^2, since I thought it was supposed to be sum(sqrt((x-xc)^2+(y-yc)^2+(z-zc)^2)-r)^2. My email: many thanks

27 Aug 2012 Daniel Lopes

Great piece of code!

13 Mar 2012 Tim

works great for my task, and thank you for sending me the related papers! :-)

02 Jul 2013

Since the matrix A is symmetric, I changed the calculation to avoid superfluous calculations. Runs about 25% faster, and even better for large data sets.

Contact us