Circle Fit at the Corner of the Step??
1 view (last 30 days)
Show older comments
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?
%
0 Comments
Answers (2)
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
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 ?
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
See Also
Categories
Find more on Surface and Mesh Plots 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!