代码块:MATLAB拟合圆函数
程序员文章站
2022-03-31 20:53:24
...
function [xc,yc,R,a] = circfit(x,y)
%MATLAB拟合圆函数
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));
theta=0:0.1:2*pi;
Circle1=xc+R*cos(theta);
Circle2=yc+R*sin(theta);
plot(Circle1,Circle2,'g','linewidth',1);hold on;grid on;grid minor;
axis equal
end
上一篇: DICOM图像压缩传输
下一篇: matlab 求圆的周长和面积