public Circle(MyPoint p1, MyPoint p2, MyPoint p3) { try { double x = (p3.getX() * p3.getX() * (p1.getY() - p2.getY()) + (p1.getX() * p1.getX() + (p1.getY() - p2.getY()) * (p1.getY() - p3.getY())) * (p2.getY() - p3.getY()) + p2.getX() * p2.getX() * (-p1.getY() + p3.getY())) / (2 * (p3.getX() * (p1.getY() - p2.getY()) + p1.getX() * (p2.getY() - p3.getY()) + p2.getX() * (-p1.getY() + p3.getY()))); double y = (p2.getY() + p3.getY()) / 2 - (p3.getX() - p2.getX()) / (p3.getY() - p2.getY()) * (x - (p2.getX() + p3.getX()) / 2); Center = new MyPoint(x, y); radius = Center.distance(p1); } catch (Exception e) { MessageBox.Show("Error creating circle with three MyPoints: " + e.ToString()); } }
private void MainDrawingArea_MouseClick(object sender, MouseEventArgs e) { g.DrawArc(new Pen(Color.Red), (float)e.X, (float)e.Y, (float)4.0, (float)4.0, (float)0.0, (float)360.0); p[n++] = new MyPoint(e.X, e.Y); sec = findSec(n, p, 0, b); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"Log.txt", true)) { file.WriteLine("Num MyMyPoints: {0}", n); for (int i = 0; i < n; i++) { string formatString = String.Format("Center {0} {1} MyPoint {2} {3} Radius: {4} Distance: {5}", sec.getCenter().getX(), sec.getCenter().getY(), p[i].getX(), p[i].getY(), sec.getRadius(), sec.getCenter().distance(p[i])); file.WriteLine(formatString); } file.WriteLine(""); } if (n > 1) { try { MyPoint center = sec.getCenter(); int r = (int)sec.getRadius(); if (prev_height > 0) { g.DrawArc(new Pen(Color.White), (float)prev_x, (float)prev_y, (float)prev_width, (float)prev_height, 0, 360); } double x = center.getX() - r; prev_x = x; double y = center.getY() - r; prev_y = y; double width = 2 * r; prev_width = width; int height = 2 * r; prev_height = height; g.DrawArc(new Pen(Color.Blue), (float)x, (float)y, (float)width, (float)height, 0, 360); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
public Circle(MyPoint first, MyPoint second) { Center = new MyPoint((first.getX() + second.getX()) / 2, (first.getY() + second.getY()) / 2); radius = Center.distance(first); }