Circle Fit at the Corner of the Step??

1 view (last 30 days)
Swati Jain
Swati Jain on 15 Jan 2018
Commented: Swati Jain on 22 Jan 2018
Hi,
I have a step curve (figure 1) and I want fit a circle to each corner of step (shown in figure 2). I wrote the following function for the circle fit:
function [xc,yc,R]=circfit(x,y)
x=x(:); y=y(:);
a=[x y ones(size(x))]\-(x.^2+y.^2);
xc=-0.5*a(1);
yc=-05*a(2);
R=0.5*sqrt((a(1)^2+a(2)^2)-4*a(3));
end
I read the corners coordinates manually and apply the following code to fit circle
y=C(1050:1100); % C is array of step
x=1050:1100;
[xc,yc,Re] = circfit(x,y);
I got the values of center and radius of circle, which are looking way to higher than I except and I don't understand how to plot this fitted circle. If I plot using
plot((x-xc).^2+(y-yc).^2-Re.^2)
It is same as the corner of the step. Could any one tell me that if approach is correct or not and how to plot fitted curve that I can show it in same way as shown in fig. 2? Is there any other way to find circle fit?
%

Answers (2)

Darshan Ramakant Bhat
Darshan Ramakant Bhat on 18 Jan 2018
This is due to the different scaling of the axes. If you observe y axes varies from 0 to 1, while x axes varies from 0 to 2000. MATLAB automatically fits the aspect ration of the axes for the visualization purpose. You have to limit the x-axes range to view the circle.
Please refer to the below code:
clc;
clear all;
close all;
t = 1 : 2000;
sf = t>1000;
figure(1);
plot(t,sf);
xlim([1000 1002])
c = [1001.05,0.95];
r = 0.05;
hold on;
%Inbuilt function in image processing toolbox to plot the circle.
viscircles(c,r);
I hope this will help you.
  2 Comments
Swati Jain
Swati Jain on 18 Jan 2018
Thanks for your response. viscirles is working well. But my other problem is still not solved. My problem is that radius obtained from circfit function is way to higher than I expect and even if I limit the x-axis in my plot there is no change, since MATLAB is adjusting the axes according to the radius of the circle. I am not sure what is wrong with my function, however, I found similar function on google. If there is any other way to fit a circle please let me now. Attached is the image what I am getting as after circle fit.
Darshan Ramakant Bhat
Darshan Ramakant Bhat on 19 Jan 2018
I am not sure what you are trying to do in circfit() function. Can you elaborate on your logic ?

Sign in to comment.


Darshan Ramakant Bhat
Darshan Ramakant Bhat on 19 Jan 2018
I guess there is something wrong going on in estimating the radius of curvature using the x,y points. Please refer below code to do the same:
I hope this will help you.
Regards,
Darshan
  1 Comment
Swati Jain
Swati Jain on 22 Jan 2018
Hi,
This function is giving same result as I got from my function. Thanks!

Sign in to comment.

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!