mathnet / mathnet-spatial

Math.NET Spatial
http://spatial.mathdotnet.com
MIT License
376 stars 132 forks source link

Circle2D.FromPoints gives incorrect results for special cases. #176

Closed diluculo closed 4 years ago

diluculo commented 4 years ago

Circle2D.FromPoints(A, B, C) may have a problem in case of A.X = B.X, B.X = C.X, A.Y = B.Y, or B.Y = C.Y. e.g., for three points A={0, 0}, B={1, 0}, and C={0, 1} it throws an exception.

        public static Circle2D FromPoints(Point2D pointA, Point2D pointB, Point2D pointC)
        {
            ...
            var gradientAB = (pointB.Y - pointA.Y) / (pointB.X - pointA.X);
            var gradientBC = (pointC.Y - pointB.Y) / (pointC.X - pointB.X);
            var gradientl1 = -1 / gradientAB;
            var gradientl2 = -1 / gradientBC;
            ...
        }

EDIT: It is not handling correctly in two cases: