public Circle(float radius, Point2D center) { this.radius = radius; this.center = center; }
public Triangule(Point2D a, Point2D b, Point2D c) { if (a.Equals(b) || a.Equals(c) || b.Equals(c)) throw new Exception("no pueden haber 2 puntos de un triangulo iguales"); float low = Math.Min(a.x, b.x); low = Math.Min(low, c.x); if (!FindAssign(a, b, c,low) && !FindAssign(b, a, c,low)) FindAssign(c,a,b,low); }
bool FindAssign(Point2D a1,Point2D a2,Point2D a3,float low) { if (a1.x == low) { if (a2.x == low) { if (a1.y > a2.y) { this.a = a1; this.b = a2; this.c = a3; return true; } else { this.a = a2; this.b = a1; this.c = a3; return true; } } else if (a3.x == low) { if (a1.y > a3.y) { this.a = a1; this.b = a3; this.c = a2; return true; } else { this.a = a3; this.b = a1; this.c = a2; return true; } } else if (a2.x > a3.x) { this.a = a3; this.b = a1; this.c = a2; return true; } else { this.a = a2; this.b = a1; this.c = a3; } } return false; }
private bool HasPointsInside(Point2D point2D, Point2D point2D_2, Point2D point2D_3) { List<Triangule> list = new List<Triangule>(); Triangule t = new Triangule(point2D, point2D_2, point2D_3); list.Add(t); Dictionary<Triangule, Circle> dict = GetCircumcicles(list); foreach (Point2D p in points) { if (!p.Equals(point2D) && !p.Equals(point2D_2) && !p.Equals(point2D_3)) { if (Math.Pow(p.x - dict[t].center.x, 2) + Math.Pow(p.y - dict[t].center.y, 2) <= Math.Pow(dict[t].radius, 2)) return true; } } return false; //float[,] matrix = new float[3, 3]; //Triangule t = new Triangule(point2D, point2D_2, point2D_3); //foreach (Point2D p in points) //{ // //if (res.Find(t => t.a.Equals(p) || t.b.Equals(p) || t.c.Equals(p)) == null && !p.Equals(point2D) && !p.Equals(point2D_2) && !p.Equals(point2D_3)) // if (!p.Equals(point2D) && !p.Equals(point2D_2) && !p.Equals(point2D_3)) // { // matrix = new float[3, 3]; // matrix[0, 0] = t.a.x - p.x; // matrix[0, 1] = t.a.y - p.y; // matrix[0, 2] = (float)(Math.Pow(matrix[0, 0], 2) + Math.Pow(matrix[0, 1], 2)); // matrix[1, 0] = t.b.x - p.x; // matrix[1, 1] = t.b.y - p.y; // matrix[1, 2] = (float)(Math.Pow(matrix[1, 0], 2) + Math.Pow(matrix[1, 1], 2)); // matrix[2, 0] = t.c.x - p.x; // matrix[2, 1] = t.c.y - p.y; // matrix[2, 2] = (float)(Math.Pow(matrix[2, 0], 2) + Math.Pow(matrix[2, 1], 2)); // if (CalculateDeterminant(matrix) > 0) // return true; // } //} //return false; }
private Pair Triangulate(List<Point2D>leftOverPoints,List<Triangule>res) { List<Triangule> temp=null; Point2D newPoint = new Point2D(); while (leftOverPoints.Count > 0) { for (int i = 0; i < leftOverPoints.Count; i++) { temp = GetNextTriangules(leftOverPoints[i],res); if (temp.Count > 0) { res.AddRange(temp); newPoint=leftOverPoints[i]; leftOverPoints.RemoveAt(i); int countTriangules = res.Count; Pair p=Triangulate(leftOverPoints, res); if (p.ok) return p; else { res.RemoveRange(res.Count - temp.Count, temp.Count); leftOverPoints.Insert(i, newPoint); } } } return new Pair(res,false); } return new Pair(res,true); }
private List<Triangule> GetNextTriangules(Point2D newPoint,List<Triangule>res) { List<Triangule> result = new List<Triangule>(); foreach (Point2D[] p in GetPairRandomPoints()) { if (!p[0].Equals(newPoint) && !p[1].Equals(newPoint)) { if (!HasPointsInside(p[0],p[1],newPoint)) { result.Add(new Triangule(p[0],p[1],newPoint)); } } } return result; }
public List<Triangule> Triangulate(List<Triangule> triangules, Point2D newPoint) { List<Point2D> l = new List<Point2D>(); l.Add(newPoint); return Triangulate(l, triangules).res; }
public Rect GetRectEcuation(Point2D p1, Point2D p2) { return new Rect(new Rational((int)(p1.y - p2.y), (int)(p1.x - p2.x)), -1 * p1.x * ((float)(p1.y - p2.y) / (float)(p1.x - p2.x)) + p1.y); }
public Rect GetMediatrixEcuation(Point2D p1, Point2D p2,Rect r) { Point2D halfPoint = new Point2D((p1.x+p2.x)/2f,(p1.y+p2.y)/2f); Rational m = new Rational(r.M.denominator,r.M.numerator * -1); return new Rect(m, -1 * m.Eval() * halfPoint.x + halfPoint.y); }
//con la norma euclideana public float GetDistance(Point2D p1, Point2D p2) { return (float)Math.Sqrt(Math.Pow(p1.x - p2.x, 2) + Math.Pow(p1.y - p2.y, 2)); }