public List <Triangule> Triangulate() { res.Clear(); Triangule root = new Triangule(); Pair pair; List <Point2D> leftOverPointsTemp = new List <Point2D>(leftOverPoints); List <Point2D> leftOverPoints2 = new List <Point2D>(leftOverPoints); foreach (Point2D[] p in GetRandomPoints()) { if (!HasPointsInside(p[0], p[1], p[2])) { root = new Triangule(p[0], p[1], p[2]); res.Add(root); leftOverPointsTemp.Remove(p[0]); leftOverPointsTemp.Remove(p[1]); leftOverPointsTemp.Remove(p[2]); pair = Triangulate(leftOverPointsTemp, res); if (pair.ok) { return(pair.res); } else { res.RemoveAt(0); leftOverPointsTemp = leftOverPoints2; } } } return(null); }
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 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); }
public List <Triangule> Triangulate() { res.Clear(); Triangule root = new Triangule();//este es el primer triangulo Pair pair; List <Point2D> leftOverPointsTemp = new List <Point2D>(leftOverPoints); List <Point2D> leftOverPoints2 = new List <Point2D>(leftOverPoints); foreach (Point2D[] p in GetRandomPoints())//la idea es: de todas los trios de puntos posibles, me quedo con el primero de esos trios tal que cumpla la condicion de Delaunay { if (!HasPointsInside(p[0], p[1], p[2])) { root = new Triangule(p[0], p[1], p[2]); res.Add(root); leftOverPointsTemp.Remove(p[0]); leftOverPointsTemp.Remove(p[1]); leftOverPointsTemp.Remove(p[2]); pointsUsed.Add(p[0]);//adiciona a la lista de puntos usados, los puntos que hay en p pointsUsed.Add(p[1]); pointsUsed.Add(p[2]); pair = Triangulate(leftOverPointsTemp, res); if (pair.ok) { return(pair.res); } else { res.RemoveAt(0);//quita de la posicion pasada de parametro pointsUsed.RemoveAt(pointsUsed.Count - 1); pointsUsed.RemoveAt(pointsUsed.Count - 1); pointsUsed.RemoveAt(pointsUsed.Count - 1); leftOverPointsTemp = leftOverPoints2; } } } return(null); }
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; }
public List<Triangule> Triangulate() { res.Clear(); Triangule root = new Triangule(); Pair pair; List<Point2D> leftOverPointsTemp = new List<Point2D>(leftOverPoints); List<Point2D> leftOverPoints2 = new List<Point2D>(leftOverPoints); foreach (Point2D[] p in GetRandomPoints()) { if (!HasPointsInside(p[0], p[1], p[2])) { root = new Triangule(p[0], p[1], p[2]); res.Add(root); leftOverPointsTemp.Remove(p[0]); leftOverPointsTemp.Remove(p[1]); leftOverPointsTemp.Remove(p[2]); pair = Triangulate(leftOverPointsTemp, res); if (pair.ok) return pair.res; else { res.RemoveAt(0); leftOverPointsTemp = leftOverPoints2; } } } return null; }
public override bool Equals(object obj) { Triangule other = obj as Triangule; return(other.a.Equals(a) && other.b.Equals(b) && other.c.Equals(c)); }