Search code examples
geometrybest-fit-curvebest-fit

Quality of circle fit for points (java/kotli/js/c)


A question I asked on recently SO elicited an excellent solution for finding best fit circle for a collection of points in 2d space. I now find that I need to quantify the quality of the circle fit, and not just determine the circle itself. I do not understand the maths involved - could someone point me to a source of an algorithm to achieve this? Any and all input gratefully received, but answers in a language that I can use (c/c++/java/kotlin/swift/js etc) would be especially helpful. I am not familiary with matrix algebra so explanations/algorithms using matrices would be less helpful)

Thanks,

Phill


Solution

  • Found it - mean squares:

        fun meanSquares(points: List<Point>): Int {
            val center = Point(x, y)
            val avSquareDiff =  points
                .map { (center.distance(it) - radius) }
                .map { it * it }
                .average()
            return sqrt(avSquareDiff).roundToInt()
        }
    

    Average the squares of distance between each point and circle line, take the square root for convenience in GUI.