Circle2D.FromPoints gives incorrect results for special cases.
diluculo opened this issue · 0 comments
diluculo commented
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:
((pointB.Y == pointA.Y) && (pointC.X == pointA.X))
i.e A={0, 0}, B={1, 0}, and C={0, 1}((pointB.Y == pointC.Y) && (pointB.X == pointA.X))
i.e A={0, 0}, B={0, 1}, and C={1, 1}