Fit Circle to Weighted (x,y,w) Data
Version 1.0.0 (2.19 KB) by
James Akula
This program fits a circle to weighted set of 2D data.
weightedFitCircle Fits a circle to a list of datapoints X, Y, and weights W using fminsearch with specifiable options. Initial parameters are obtained using SVD (SVD approach inspired by https://people.cas.uab.edu/~mosya/cl/TaubinSVD.m).
Returns
CXCYout: XY of circle center
Rout: Radius of circle
RMS: Orthogonal, weighted, root mean squared error
exitFlag: Exit condition of fit
Example code showing that fitting is fast and accurate:
X = 1./rand(1, 6); Y = 1./rand(1, 6); W = rand(1, 6);
tic
[CXCYout, Rout, RMSE] = ...
weightedFitCircle(X, Y, W, optimset('Display', 'Iter'));
toc
disp(['(X,Y,R) = ', num2str([CXCYout, Rout])])
disp(['RMSE = ', num2str(RMSE)])
plot(CXCYout(1) + Rout*cos(0:0.00001:2.001*pi), ...
CXCYout(2) + Rout*sin(0:0.00001:2.001*pi), '--k')
hold on
scatter(X, Y, W/max(W)*75, 'r')
axis equal
Cite As
James Akula (2024). Fit Circle to Weighted (x,y,w) Data (https://www.mathworks.com/matlabcentral/fileexchange/111560-fit-circle-to-weighted-x-y-w-data), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2021b
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0 |