private bool IsTriangleOverlappingLoop(int first, int second, int third, List <int> loop, List <bool> concavity) { int point0 = edges[loop[first]]; int point1 = edges[loop[second]]; int point2 = edges[loop[third]]; Vector3 triangle0 = points[point0]; Vector3 triangle1 = points[point1]; Vector3 triangle2 = points[point2]; for (int i = 0; i < loop.Count; i++) { if (concavity[i]) { int reflexPoint = edges[loop[i] + 1]; // Do not test the reflex point if it is part of the triangle if (reflexPoint != point0 && reflexPoint != point1 && reflexPoint != point2) { Vector3 point = points[reflexPoint]; // Does the reflex point lie inside the triangle? if (Toolss.IsPointInsideTriangle(ref point, ref triangle0, ref triangle1, ref triangle2, ref planeNormal)) { return(true); } } } } return(false); }
private bool FindClosestPointInTriangle(int first, int second, int third, List <int> loop, out int loopIndex, out int loopLocation) { Vector3 triangle0 = points[edges[loop[first]]]; Vector3 triangle1 = points[edges[loop[second]]]; Vector3 triangle2 = points[edges[loop[third]]]; Vector3 firstNormal = Vector3.Cross(planeNormal, triangle1 - triangle0); int closestLoopIndex = -1; int closestLoopLocation = 0; float closestDistance = 0.0f; for (int i = 0; i < loops.Count; i++) { IList <int> otherLoop = loops[i]; IList <bool> otherConcavity = concavities[i]; if (otherLoop != loop) { for (int j = 0; j < otherLoop.Count; j++) { if (otherConcavity[j]) { Vector3 point = points[edges[otherLoop[j] + 1]]; if (Toolss.IsPointInsideTriangle(ref point, ref triangle0, ref triangle1, ref triangle2, ref planeNormal)) { // Calculate the distance from the bottom of the triangle to the point float distance = Vector3.Dot(point - triangle0, firstNormal); if (distance < closestDistance || closestLoopIndex == -1) { closestLoopIndex = i; closestLoopLocation = (j + 1) % otherLoop.Count; closestDistance = distance; } } } } } } loopIndex = closestLoopIndex; loopLocation = closestLoopLocation; return(closestLoopIndex != -1); }