Fast circle fitting of a set of 2D points based on Least-Squares method from Michael Migliore's circle-fit: https://github.com/Meakk/circle-fit
> npm install --save circle-fit
> mocha
const Circlefit=require("circle-fit");
let result = cf.compute([
{ x: 10, y: 10 },
{ x: 11, y: 7 },
{ x: 12, y: 7 },
{ x: 14, y: 11 }
]);
//{
// "success": true,
// "center": {
// "x": 12.26153846153846,
// "y": 9.256410256410255
// },
// "radius": 2.427575528264906
// ...
//}
The algorithm do not contain any iterative solvers and will find a solution in linear time, meaning that you will have the result instantly.
This library handles degenerate cases when you do not have enough non-colinear points to determine a correct circle by returning an error flag.
The result object contains more than the circle informations, here are all the parameters :
success (Boolean)
: status of the computationpoints (Array)
: all points given by the userprojections (Array)
: projections of each points onto the circledistances (Array)
: distance of each points to the circlecenter (Object)
: center of the circleradius (Number)
: radius of the circleresidue (Number)
: residue of the least squares method, can be use to define the quality of the circlecomputationTime (Number)
: time spent in computation (in milliseconds)