nass-micro-station-measurem.../spindle/Macros_ttt_spindle/fitcircle2.m
Thomas Dehaeze 6e3677eb29 [WIP] Breaking Change - Use Update
Folder name is changed, rework the html templates
Change the organisation.
2019-05-10 16:06:43 +02:00

15 lines
475 B
Matlab

function [c,r] = fitcircle2(x,y)
% Function to plot a linear least squares circle on a data set
% x = vector of x-coordinates
% y = vector of y-coordinates
% c = center of the circle
% r = radius of circle (not relevant)
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));
c = [xc;yc];
end