private void inkCanvas_MouseDown(object sender, MouseButtonEventArgs e) { try { if (points.Count < 3) { points.Add(new System.Drawing.PointF((float)e.GetPosition(e.Device.Target).X, (float)e.GetPosition(e.Device.Target).Y)); } else { points.Clear(); inkCanvas.Strokes.Clear(); } if (points.Count == 3) { Console.WriteLine("All points have been set. Calc.."); Console.WriteLine(points); KvaziParams _params = KvaziTools.GetParams(points); DrawLines(points, _params); } } catch (Exception ee) { Console.WriteLine("{0} inkCanvas_MouseDown.", ee); } }
public static KvaziParams GetParams(PointF A, PointF B, PointF C) { Console.WriteLine("{0}, {1}, {2}", A, B, C); var D = new PointF((A.X + B.X) / 2f, (A.Y + B.Y) / 2f); var E = new PointF((C.X + B.X) / 2f, (C.Y + B.Y) / 2f); float[,] matrix = new float[, ] { { B.X - A.X, B.Y - A.Y }, { C.X - B.X, C.Y - B.Y } }; float[] vector = new float[] { D.X *(B.X - A.X) + D.Y * (B.Y - A.Y), E.Y *(C.Y - B.Y) + E.X * (C.X - B.X) }; float[] result = solve(matrix, vector); float x0 = result[0]; //система уравнений float y0 = result[1]; var O = new PointF(x0, y0); Console.WriteLine("Center coords are: " + String.Join(";", result)); Console.WriteLine("Radius A B C: {0} ; {1} ; {2} ", GetLengthLine(A, O), GetLengthLine(B, O), GetLengthLine(C, O)); KvaziParams kvaziParams = new KvaziParams(O, GetLengthLine(A, O), GetLengthLine(B, O), GetLengthLine(C, O)); kvaziParams.D = D; kvaziParams.E = E; return(kvaziParams); }
private void DrawLines(List <PointF> points, KvaziParams _params) { try { System.Windows.Point A = new System.Windows.Point(points[0].X, points[0].Y); System.Windows.Point B = new System.Windows.Point(points[1].X, points[1].Y); System.Windows.Point C = new System.Windows.Point(points[2].X, points[2].Y); DrawLine(A, B, true); DrawLine(B, C, true); System.Windows.Point centerAB = new System.Windows.Point(_params.D.X, _params.D.Y); System.Windows.Point centerBC = new System.Windows.Point(_params.E.X, _params.E.Y); System.Windows.Point center = new System.Windows.Point(_params.CircleCentr.X, _params.CircleCentr.Y); DrawLine(centerAB, center, true); DrawLine(centerBC, center, true); DrawLine(A, center, true); DrawLine(B, center, true); DrawLine(C, center, true); } catch (Exception ee) { Console.WriteLine("{0} DrawLine", ee); } }