I have data points $(x,y)$ for a plane curve, and I would like to find its curvature. While I was googling to check how could I start, I found this matlab code:
mx = mean(x); my = mean(y) X = x - mx; Y = y - my; % Get differences from means dx2 = mean(X.^2); dy2 = mean(Y.^2); % Get variances t = [X,Y]\(X.^2-dx2+Y.^2-dy2)/2; % Solve least mean squares problem a0 = t(1); b0 = t(2); % t is the 2 x 1 solution array [a0;b0] r = sqrt(dx2+dy2+a0^2+b0^2); % Calculate the radius a = a0 + mx; b = b0 + my; % Locate the circle's center curv = 1/r; % Get the curvature
No specific explanation was added to this code except:
"The circle defined by center $(a, b)$ and radius $r$ will yield the least mean square value for the expression $(x-a)^2 + (y-b)^2 - r^2$ among all possible parameters, $a$, $b$, and $r$, over the points in vectors $x$ and $y$. The circle's curvature will be $1/r$."
The code worked very well, I checked this by taking as an example a circle.
I also tried to follow what they did step by step to understand the concept used behind this code; however I was stuck on the use of the mean. I know least square is used to solve systems, but why use mean least square? Why is the mean and variance included?
Would someone help me please. Any help will be highly appreciated.