Reputation: 904
I have a few points circle is passing through and I want to find the radius of the best fitting circle with center fixed at the origin.
CircFit doesn't allow specifying the center explicitly and I need it fixed at origin.
Upvotes: 0
Views: 719
Reputation: 22204
To post my answer from the comments.
The distance from a point to the nearest point on a circle is sqrt((x-xc).^2 + (y-yc).^2) - r).^2
. The error function for the least squares optimal is then err = sum((sqrt((x-xc).^2 + (y-yc).^2) - r).^2)
.
Taking the derivative of err
with respect to r
and setting it to zero, then solving for r
gives you the solution r = mean(sqrt((x - xc).^2 + (y - yc).^2))
.
As a MATLAB function this could be written as
function r = circfitFixedC(x,y,xc,xy)
r = mean(sqrt((x - xc).^2 + (y - xy).^2));
Upvotes: 1