File Exchange

image thumbnail

Sphere Fit (least squared)

version 1.1.0.0 (30.7 KB) by Alan Jennings
Fits a sphere to a set of noisy data. Does not require a wide arc or many points.

26 Downloads

Updated 02 Jul 2013

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

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.

Comments and Ratings (55)

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

Many thanks

Hello Alan,
Thank you for developing this function! Can you please provide me with the related papers that explain how you developed this function? I would like to cite your work.

Thanks again!
-Ramiz
rsa5wj@virginia.edu

Alice Liu

Hi Alan,
Could you provide the related paper so that I may cite your work?

Thanks,
Alice
sl332@duke.edu

harsh jain

jian fu

Dear Alan,
thanks for this great function! Is there any chance for me to get the related papers explaining this method?
Thanks a lot!
1197349243@qq.com

Ben Stone

Hi Alan,

Great bit of code. I would like to cite your work. Could you provide the paper that I can cite?

Thanks,
Ben Stone

b.m.stone@lboro.ac.uk

Hi Alan,
I would like to cite your work. Please let me know about the reference that I can put?
Thank you,

**najma.alami@gmail.com

How do you run the example, I keep getting, Error in spherefit (line 18)
[Center_LSE,Radius_LSE] = sphereFit(X);. As an error.

Hey Alan,
Very nice work. Is it also possible to have your related paper? My email is: carolzina_melo@hotmail.com
Thanks in advance.

Cory Hunt

This is great! I am interested in learning more about the algorithm. my email is huntcoyd@gmail.com

chu guo

Dear Alan,
Great work. May I have your related paper? I am also interested in this algorithm. my email: 790775266@qq.com
thank you!

Hi Alan,

Could you please let me know how we would cite your work?

Thanks,
Bugra

Dear Alan, Great work...May I have your relate paper?
my email: karollkv@hotmail.es

nay zhao

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

Many thanks

Hi Alan,

Great work! Thanks for this great function! Is there any chance for me to get the related papers explaining this method?

Thanks a lot!

andyxhliu@gmail.com

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

Dear Alan,

Thanks for the function. I would be interested in the related papers. May I ask you to send it to me? Thanks in advance.

Best regards,

Roderik

E-mail: roderik.berthelin@outlook.com

Jan Mervart

Dear Alan,
I also thank you for your function and I am interested in the related papers, too.

Best regards,
E-mail: gertbra@gmail.com

Ed

Hi Alan,
this sphereFit algorithm gives me nightmares, I'm looking to understand it since days. Please send me the related papers, too! :/
Email: jizaz84@googlemail.com

Do you think it will be possible to reduce the DOF within the sphereFit? I need to pin the XY position to a line.

Best regards,
Ed

Ed

joe W

Dear Alan,
Firstly, thank you for your function.I hope you can send me the related papers.Thanks again.

Best regards
E-mail: wqh806393670@163.com

niels st

Dear Alan,
Your function works great! I'm interested in the algorithm behind your code. Would it be possible to get the related papers?

Best regards
niels.steffen@tu-harburg.de

Hi Jack,
I'm glad this is useful for you. If you notice, there's a symmetry that you can extend to N dimensions. If you're very savy, you can do it progamatically without a for loop; but I thought that would make the code harder to understand. The derivation also extends to N dimensions, so the answer will still be the least square error (of the squared distance).
HTH, Alan

jack

Hello Alan,
Does your code works in n dimension where n>=3 ?
If not can you help me in making it work?

please advise.

Thanks in advance.

jack

Hello Alan,
Does your code works in n dimension where n>=3 ?
If not can you help me in making it work?

please advise.

Thanks in advance.

Lutas

Andrei

Alan,

I agree with the other comments. Very nice function. Could you also send me the mentioned reference papers.

Regards

Tom

tmhedges@gmail.com

Dear Alan,
thanks for this great function! Is there a possibility for me to get the related papers explaining this method ?
Thanks a lot in advanced.
Regards

Navy

Navy

That's just what I need.

Kao

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

Many thanks

Kao

Casey

li

good work!

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!
patrick-fink@gmx.net

Sa

Dear Alan,
Outstanding work! Could you send me the related paper explaining this method?
samuel.reimer@tum.de

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

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
Regards

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

JamesAb

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

jamesabott@yahoo.com

Many thanks!

Simao

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

simao.britodaluz@griffithuni.edu.au

much appreciated

Chloe

Hi Alan, any chance you could please send me the relating papers to c.carson@ncl.ac.uk?

Thanks for the code. Works perfect!

Laurens

Works great!

I was wondering if you could send me the paper as well (email: laurens.slot@gmail.com).

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

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: lhwsky@mail.ustc.edu.cn. many thanks

Daniel Lopes

Great piece of code!

Tim

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

Updates

1.1.0.0

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.

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux

sphereFit/

sphereFit/html/