Code for finding center of circle

Hello, Could someone please help me with a code for finding center of circle. I have known points (Xa,Xb, Ya,Yb) and Radius. I need to write a code in Matlab to display the center from a cloud data. Any help would be appreciated.
Thanks

2 Comments

i used the code imfindcircle to find the radius .but i need edge detection code and then to calculate the center point.could you help me out.
s., Are you SURE you looked at the documentation for imfindcircles(), which clearly states that it returns the radii:
[centers,radii] = imfindcircles(A,radiusRange) finds circles with radii in the range specified by radiusRange. The additional output argument, radii, contains the estimated radii corresponding to each circle center in centers.
Also see attached paper.

Sign in to comment.

 Accepted Answer

Image Analyst
Image Analyst on 10 Nov 2015

13 Comments

Thank You. To be clear th ebelow code will fid center from data pool. also can I ssign values to R, x, y and allow matlab to compute function [xc,yc,R,a] = circfit(x,y) %CIRCFIT Fits a circle in x,y plane % % [XC, YC, R, A] = CIRCFIT(X,Y) % Result is center point (yc,xc) and radius R. A is an optional % output describing the circle's equation: % % x^2+y^2+a(1)*x+a(2)*y+a(3)=0
I'm not sure what you mean. Is that a question?
I have attached the code, will this code get me center for circle. I know what R value, X1,X2, Y1,Y2 values,. How do I enter these values in code
Where did you attach it? I don't see any circle fitting code attached, just the code in your comment, but there's no real code there, just a function definition and a bunch of comments.
Hello, I need help in writing the code, with the formula's you had directed. Like I said I know R, X1,X2, Y1,Y2 values. I need to find the center from circle that is defined by 10000 point clouds from a laser scan. Hope this helps
Like I said, the code was in the FAQ. Help me to understand why you say "I need help in writing the code". I assume you already have code to get your x and y values, and the code for the circfit() function is in the FAQ so I don't understand what code you need help writing. Just call the circfit() function after your code that gets the x and y values. If you have 10,000 x values and 10,000 y values, just pass them in to this function (from the FAQ):
function [xc,yc,R,a] = circfit(x,y)
%CIRCFIT Fits a circle in x,y plane
%
% [XC, YC, R, A] = CIRCFIT(X,Y)
% Result is center point (yc,xc) and radius R. A is an optional
% output describing the circle's equation:
%
% x^2+y^2+a(1)*x+a(2)*y+a(3)=0
% by Bucher izhak 25/oct/1991
n=length(x); xx=x.*x; yy=y.*y; xy=x.*y;
A=[sum(x) sum(y) n;sum(xy) sum(yy) sum(y);sum(xx) sum(xy) sum(x)];
B=[-sum(xx+yy) ; -sum(xx.*y+yy.*y) ; -sum(xx.*x+xy.*y)];
a=A\B;
xc = -.5*a(1);
yc = -.5*a(2);
R = sqrt((a(1)^2+a(2)^2)/4-a(3));
Thank you for your prompt response. I should have been clearer in my question,I do not have a code to get x and y values, I need help in writing that code
You must at least have the data file that your laser scanner produced. Please attach it.
I have attached the file, it's only a portion of the data file as the full file size is 12MB. It is data for a part, attached snapshot. I am trying to find the center of the part as highlighted in picture using 3 sets of points
Hello Sorry to bother you again, just wanted to follow up if you had a chance to look at the data file for code. Thank you again for your help.
What does each column represent? There are 3 and I thought you would have 2: one column for x and one for y. If I plot the first 2 columns, it looks like this:
What is this? Where is the circle?
Thank you for taking a look at this. The 3 columns are x, y,z. But y and z have been interchanged. so you only have to use 1 and 3 column The circle is in the center. I was able to make some progress I was able to get a contour to pick points on the perimeter of the circle. I now have 2 quadratic equations with 2 known and 2 unknown. Ho do I write a script to solve this equation. (x1-xc)^2+(y1-yc)^2=R^2 (x2-xc)^2+(y2-yc)^2=R^2 I know the values for x1,x2,y1,y2 and R, these can be input manually in the script. I need to find xc and yc. How do I solve it in Matlab
Those x,y are over the whole part, not just the perimeter of the circle. You're going to have to find a way to get just the x,y around the perimeter of the circle. Maybe by converting to an image.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!