fitcircle: Fit a Circle to Three Points in the Plane
Version 1.0.0 (429 KB) von
Rob Comer
The fitcircle function fits a circle to exactly three points in the plane, returning the center coordinates and radius.
fitcircle is a simple MATLAB function (six executable lines) that fits a circle to (exactly) three points in the plane, (x1, y1), (x2, y2), and (x3, y3), and returns the center (xc, yc) and radius (r) of the circle:
[xc, yc, r] = fitcircle(x1, y1, x2, y2, x3, y3)
Use of mldivide (the \ operator) means that no input validation is needed, other than checking that the inputs are real, finite, and double (using Function Argument Validation).
In the event of collinear or nearly collinear points (including the cases of identical or nearly-identical points), the 2x2 matrix,
A = [x2 - x1, y2 - y1
x3 - x1, y3 - y1],
which is central to the computations, will be singular or nearly singular and a warning will be issued:
"Matrix is singular to working precision"
or
"Matrix is close to singular ...",
In this case, the radius output will equal Inf or NaN, so a call to isfinite will indicate programmatically whether or not A was too ill-conditioned for a solution to be computed. (In most cases like this, the center coordinate outputs will also be nonfinite (Inf, -Inf, or NaN).)
Related Submissions
To fit more than three points (the overdetermined problem), or to fit circles to multiple sets of three points in a single function call, consider:
Circle Fit (Pratt method) by Nikolai Chernov — "Fits a circle to a set of data points on a plane; returns the circle center (a,b) and radius R"
circfit by Andrew Horchler — "Matlab function for least squares fitting of two-dimensional data to a circle."
Fit circle through 3 points by Danylo Malyuta — "A fault-tolerant function for computing a circle's center and radius given three x-y points"
Zitieren als
Rob Comer (2025). fitcircle: Fit a Circle to Three Points in the Plane (https://de.mathworks.com/matlabcentral/fileexchange/182051-fitcircle-fit-a-circle-to-three-points-in-the-plane), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Erstellt mit
R2024b
Kompatibel mit R2019b und späteren Versionen
Plattform-Kompatibilität
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
| Version | Veröffentlicht | Versionshinweise | |
|---|---|---|---|
| 1.0.0 |
