How to find circle from data points

4 次查看(过去 30 天)
Jw
Jw 2011-10-11
How do i detect circle,circle center and radius from my data points?
clear all;clc;
x=zeros(1,361);
y=zeros(1,361);
x=[-90:0.5:90];
for i=1:361
if (1<=i && i<160)
y(i)=0.2*x(i)+3;
end
if (161<=i && i<200)
y(i)=-sqrt(10^2-(x(i)^2));
end
if (201<=i && i<361)
y(i)=-0.2*x(i)+3;
end
end
figure
plot(x,y,'b.')
axis equal

回答(1 个)

Andrei Bobrov
Andrei Bobrov 2011-10-11
dy = diff(y,2);
idx = find(abs(dy) > 1e-10)+1;
idc = idx(5)+(0:2:4);
id = [x(idc)',y(idc)'];
f = @(x,y)(y(:,1)+x(1)).^2+(y(:,2)+x(2)).^2 - x(3).^2;
xabr = fsolve(@(x)f(x,id),[0 0 1]').*[-1; -1; 1];
xabr(1:2) % coordinate of center circle [x;y]
x(3) % radius circle

标签

Community Treasure Hunt

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

Start Hunting!

Translated by