private static Point3D[] TwoInside(ITriangleIndexed[] hull, ITriangle triangle, int insidePointIndex1, int insidePointIndex2) { if (insidePointIndex1 > insidePointIndex2) { // Reverse them to simplify the switch statements return TwoInside(hull, triangle, insidePointIndex2, insidePointIndex1); } #region Examine Indices TriangleEdge edgeLeft, edgeRight; Point3D insidePointLeft, insidePointRight, insidePointMiddle, outsideCenterPoint; switch (insidePointIndex1) { case 0: switch (insidePointIndex2) { case 1: #region 0, 1 edgeLeft = TriangleEdge.Edge_20; edgeRight = TriangleEdge.Edge_12; insidePointLeft = triangle.Point0; insidePointRight = triangle.Point1; insidePointMiddle = triangle.GetEdgeMidpoint(TriangleEdge.Edge_01); outsideCenterPoint = triangle.Point2; #endregion break; case 2: #region 0, 2 edgeLeft = TriangleEdge.Edge_01; edgeRight = TriangleEdge.Edge_12; insidePointLeft = triangle.Point0; insidePointRight = triangle.Point2; insidePointMiddle = triangle.GetEdgeMidpoint(TriangleEdge.Edge_20); outsideCenterPoint = triangle.Point1; #endregion break; default: throw new ApplicationException("Unexpected point: " + insidePointIndex2.ToString()); } break; case 1: #region 1, 2 if (insidePointIndex2 != 2) { throw new ApplicationException("Unexpected point: " + insidePointIndex2.ToString()); } edgeLeft = TriangleEdge.Edge_01; edgeRight = TriangleEdge.Edge_20; insidePointLeft = triangle.Point1; insidePointRight = triangle.Point2; insidePointMiddle = triangle.GetEdgeMidpoint(TriangleEdge.Edge_12); outsideCenterPoint = triangle.Point0; #endregion break; default: throw new ApplicationException("Unexpected point: " + insidePointIndex2.ToString()); } // Make sure that outsideCenterPoint is outside the hull outsideCenterPoint = EnsureOutsidePointIsBeyondHull(hull[0].AllPoints, insidePointMiddle, outsideCenterPoint); #endregion // Get edge/hull intersections var intersectLeft = GetIntersectPoints(hull, triangle.GetPoint(edgeLeft, true), triangle.GetPoint(edgeLeft, false)); if (intersectLeft.Length == 0) { return null; // triangle is only touching the hull, not really intersecting } var intersectRight = GetIntersectPoints(hull, triangle.GetPoint(edgeRight, true), triangle.GetPoint(edgeRight, false)); if (intersectRight.Length == 0) { return null; } // Now that the two intersect points are found, find connecting lines Point3D[] hullEdge = GetConnectingLines(hull, intersectLeft[0], intersectRight[0], outsideCenterPoint); // Clip poly List<Point3D> hullPoly = new List<Point3D>(); hullPoly.Add(insidePointLeft); hullPoly.AddRange(hullEdge); hullPoly.Add(insidePointRight); Point3D[] retVal = Math2D.GetIntersection_Polygon_Triangle(hullPoly.ToArray(), triangle); // Exit Function return retVal; }
private static Point3D[] OneInside(ITriangleIndexed[] hull, ITriangle triangle, int insidePointIndex) { #region Examine Index TriangleEdge edge1, edge2, edgeOutside; // Edges that are intersecting the hull Point3D insidePoint, outsideCenterPoint; switch (insidePointIndex) { case 0: edge1 = TriangleEdge.Edge_01; edge2 = TriangleEdge.Edge_20; edgeOutside = TriangleEdge.Edge_12; insidePoint = triangle.Point0; outsideCenterPoint = triangle.GetEdgeMidpoint(edgeOutside); break; case 1: edge1 = TriangleEdge.Edge_01; edge2 = TriangleEdge.Edge_12; edgeOutside = TriangleEdge.Edge_20; insidePoint = triangle.Point1; outsideCenterPoint = triangle.GetEdgeMidpoint(edgeOutside); break; case 2: edge1 = TriangleEdge.Edge_12; edge2 = TriangleEdge.Edge_20; edgeOutside = TriangleEdge.Edge_01; insidePoint = triangle.Point2; outsideCenterPoint = triangle.GetEdgeMidpoint(edgeOutside); break; default: throw new ApplicationException("Unexpected point: " + insidePointIndex.ToString()); } // Make sure that outsideCenterPoint is outside the hull outsideCenterPoint = EnsureOutsidePointIsBeyondHull(hull[0].AllPoints, insidePoint, outsideCenterPoint); #endregion // Get edge/hull intersections var intersect1 = GetIntersectPoints(hull, triangle.GetPoint(edge1, true), triangle.GetPoint(edge1, false)); if (intersect1.Length == 0) { return null; // triangle is only touching the hull, not really intersecting } else if (intersect1.Length > 1) { throw new ApplicationException("Should never get more than one intersect point: " + intersect1.Length.ToString()); } var intersect2 = GetIntersectPoints(hull, triangle.GetPoint(edge2, true), triangle.GetPoint(edge2, false)); if (intersect2.Length == 0) { return null; } else if (intersect2.Length > 1) { throw new ApplicationException("Should never get more than one intersect point: " + intersect2.Length.ToString()); } // Now that the two intersect points are found, find connecting lines Point3D[] hullEdge = GetConnectingLines(hull, intersect1[0], intersect2[0], outsideCenterPoint); // Clip poly List<Point3D> hullPoly = new List<Point3D>(); hullPoly.Add(insidePoint); hullPoly.AddRange(hullEdge); Point3D[] retVal = Math2D.GetIntersection_Polygon_Triangle(hullPoly.ToArray(), triangle); // Exit Function return retVal; }