필터 지우기
필터 지우기

recognize the center and diameter of a circle

조회 수: 3 (최근 30일)
Yu Li
Yu Li 2018년 12월 4일
댓글: Yu Li 2018년 12월 5일
I have a 2D scatter, it is a circle but the center and diameter is not given.
I need its center and diameter but as you can see in the figure, there are some noise points around. is there anyway to do this?
circle.jpg

채택된 답변

Akira Agata
Akira Agata 2018년 12월 5일
If you have Optimization Toolbox, you can solve this nonlinear least-square problem by simply using lsqnonlin function, like:
load('circle_coordinate.mat');
x = circle_coordinate(:,1);
y = circle_coordinate(:,2);
% Solve as nonlinear least-squares problem
f = @(a) (x-a(1)).^2 + (y-a(2)).^2 - a(3).^2;
a0 = [mean(x),mean(y),max(x)-mean(x)];
af = lsqnonlin(f,a0);
% Fittig circle
theta = linspace(0,2*pi);
xFit = af(1)+af(3)*cos(theta);
yFit = af(2)+af(3)*sin(theta);
% Visualize the result
figure
scatter(x,y,'.')
hold on
plot(af(1),af(2),'rx')
plot(xFit,yFit,'r-')
legend({'Data','Center','Fitting circle'})
circle.png
  댓글 수: 1
Yu Li
Yu Li 2018년 12월 5일
fantastic! I have never know Matlab can do this before.
Thank you so much!
Yu

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by