public void SetCircle3Points(Point[] p) { PointDbl[] dblArray = new PointDbl[3]; PointDbl dbl3 = new PointDbl(p[0]); dblArray[0] = dbl3; PointDbl dbl2 = new PointDbl(p[1]); dblArray[1] = dbl2; PointDbl dbl = new PointDbl(p[2]); dblArray[2] = dbl; CircleInfo info = CGM2SVGMath.FindCircleBy3Points(dblArray); if (info.R >= 0.0) { this.center.X = new decimal(info.Center.X); this.center.Y = new decimal(info.Center.Y); this.SetCircleDiameters(info.R, Math2.CompareAngles(Convert.ToDouble(decimal.Subtract(p[2].X, p[0].X)), Convert.ToDouble(decimal.Subtract(p[2].Y, p[0].Y)), Convert.ToDouble(decimal.Subtract(p[1].X, p[0].X)), Convert.ToDouble(decimal.Subtract(p[1].Y, p[0].Y))) < 0.0); this.v1.X = decimal.Subtract(p[0].X, this.center.X); this.v1.Y = decimal.Subtract(p[0].Y, this.center.Y); this.v2.X = decimal.Subtract(p[2].X, this.center.X); this.v2.Y = decimal.Subtract(p[2].Y, this.center.Y); } else { this.collinearCoords = true; this.center = p[1]; this.SetCircleDiameters(Math2.Distance(Convert.ToDouble(decimal.Subtract(p[0].X, this.center.X)), Convert.ToDouble(decimal.Subtract(p[2].X, this.center.X))), false); this.v1.X = decimal.Subtract(p[0].X, this.center.X); this.v1.Y = decimal.Subtract(p[0].Y, this.center.Y); this.v2.X = decimal.Subtract(p[2].X, this.center.X); this.v2.Y = decimal.Subtract(p[2].Y, this.center.Y); } }
// Methods public static CircleInfo FindCircleBy3Points(PointDbl[] p) { CircleInfo info = new CircleInfo();//TODO if (Math2.IsNul(Math2.CompareAngles(p[0].X - p[1].X, p[0].Y - p[1].Y, p[2].X - p[1].X, p[2].Y - p[1].Y))) { info.R = -1.0; return(info); } double[] numArray = Math2.SolveSystem2(new double[, ] { { 2.0 * (p[0].X - p[2].X), 2.0 * (p[0].Y - p[2].Y) }, { 2.0 * (p[1].X - p[2].X), 2.0 * (p[1].Y - p[2].Y) } }, new double[] { (((p[0].X * p[0].X) - (p[2].X * p[2].X)) + (p[0].Y * p[0].Y)) - (p[2].Y * p[2].Y), (((p[1].X * p[1].X) - (p[2].X * p[2].X)) + (p[1].Y * p[1].Y)) - (p[2].Y * p[2].Y) }); info.Center.X = numArray[0]; info.Center.Y = numArray[1]; info.R = Math2.Distance(p[0].X - numArray[0], p[0].Y - numArray[1]); return(info); }