fsnow 发表于 2007-10-28 00:25

圆最小二乘拟合函数

一个比较老,但管用的圆最小二乘拟合函数
function = circfit(x,y)
%CIRCFIT Fits a circle in x,y plane
%
% = 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));

fsnow 发表于 2007-10-28 00:35

例:
xd = rand(1,10);
yd = rand(1,10);
=circfit(xd,yd);
plot(xd,yd,'r*');hold on;
t=linspace(0,pi*2,100);
z=xc+yc*i+R*exp(i*t);
plot(z); axis equal;

xjzuo 发表于 2007-10-29 10:36

这个好象matlab的help or demo里面已有.

eight 发表于 2007-10-29 11:09

原帖由 xjzuo 于 2007-10-29 10:36 发表 http://www.chinavib.com/forum/images/common/back.gif
这个好象matlab的help or demo里面已有.

没找到,请指示

zcs 发表于 2008-12-4 09:08

这个很好
很值得学习,谢谢楼主

Might_L 发表于 2012-4-13 14:29

多谢楼主分享
页: [1]
查看完整版本: 圆最小二乘拟合函数