private void LinkPointToTris(int curPoint) //Send the current unvisited star as the seed point SOMETHING WRONG { for (int i = 0; i < externalPoints.Count; ++i) //For all the external points { int nextPoint = i + 1; //Assign the next point if (nextPoint == externalPoints.Count) //If the next point is out of range { nextPoint = 0; //Set it to the first point in the list } Vector3 lineCurToExternal = MathsFunctions.ABCLineEquation(unvisitedStars[curPoint].transform.position, externalPoints[i].transform.position); //Create a line between the external point and the unvisited star if (IsIllegalIntersection(i, curPoint, lineCurToExternal)) //If there is an illegal intersection between the external point-current point line and the external point-unvisited point line { continue; //Move onto the next external point } Vector3 lineCurToNextExternal = MathsFunctions.ABCLineEquation(unvisitedStars[curPoint].transform.position, externalPoints[nextPoint].transform.position); if (IsIllegalIntersection(nextPoint, curPoint, lineCurToNextExternal)) //If there is an illegal intersection between the next point-current point line and the external point-unvisited point line { continue; //Move onto the next external point } bool illegal = false; //Say that the line is not illegal for (int j = 0; j < externalPoints.Count; ++j) //Check through all other external points { if (j == i || j == nextPoint) { continue; } if (MathsFunctions.IsInTriangle(externalPoints[i].transform.position, externalPoints[nextPoint].transform.position, unvisitedStars[curPoint].transform.position, externalPoints[j].transform.position) == true) //If the point lies in any of the triangles { //if(MathsFunctions.PointsAreColinear(externalPoints[i].transform.position, externalPoints[nextPoint].transform.position, externalPoints[j].transform.position) == false) //{ //if(MathsFunctions.PointsAreColinear(externalPoints[i].transform.position, unvisitedStars[curPoint].transform.position, externalPoints[j].transform.position) == false) //{ //if(MathsFunctions.PointsAreColinear(externalPoints[nextPoint].transform.position, unvisitedStars[curPoint].transform.position, externalPoints[j].transform.position) == false) //{ illegal = true; //It is an illegal triangle break; // //} //} //} } } if (illegal) //If it's an illegal triangle { continue; //Skip to the next point } GameObject pointA = externalPoints[i]; //Otherwise assign the points of the triangle GameObject pointB = externalPoints[nextPoint]; GameObject pointC = unvisitedStars[curPoint]; Triangle newTri = new Triangle(); //Create a new triangle object newTri.points.Add(pointA); //Add the points newTri.points.Add(pointB); newTri.points.Add(pointC); newTri.lines.Add(MathsFunctions.ABCLineEquation(pointA.transform.position, pointB.transform.position)); //Calculate the line equations between the points newTri.lines.Add(MathsFunctions.ABCLineEquation(pointB.transform.position, pointC.transform.position)); newTri.lines.Add(MathsFunctions.ABCLineEquation(pointC.transform.position, pointA.transform.position)); tempTri.Add(newTri); //Add the triangle to the temptriangle list } }