private static bool InTriangle(EarPoint pointToCheck, EarPoint earTip, EarPoint earTipPlusOne, EarPoint earTipMinusOne) { bool isIntriangle = GeoTriangleUtils.IsPointInTriangle2(earTip.mPoint, earTipPlusOne.mPoint, earTipMinusOne.mPoint, ref pointToCheck.mPoint); if (isIntriangle) { if (pointToCheck.mPoint == earTip.mPoint || pointToCheck.mPoint == earTipPlusOne.mPoint || pointToCheck.mPoint == earTipMinusOne.mPoint) // 端点 { return(false); } } return(isIntriangle); }
public static float PointClosest2Triangle3(Vector3 p1, Vector3 p2, Vector3 p3, ref Vector3 p, ref Vector3 close) { GeoPlane plane = new GeoPlane(p1, p2, p3); float d = GeoPlaneUtils.PointClosestToPlaneAbs(plane.mNormal, plane.mD, p, ref close); if (GeoTriangleUtils.IsPointInTriangle3(p1, p2, p3, ref close)) { return(d); } else { Vector3 close1 = new Vector3(); float dt = PointClosest2PlaneTriangle2(p1, p2, p3, plane, ref p, ref close1); return((float)Math.Sqrt(d * d + dt * dt)); } }
public static bool IsSegmentInsectOrOverlapTriangle2(Vector2 seg1, Vector2 seg2, Vector2 p1, Vector2 p2, Vector2 p3, ref GeoInsectPointArrayInfo insect) { // 在三角形内部 if (GeoTriangleUtils.IsPointInTriangle2(p1, p2, p3, ref seg1) && GeoTriangleUtils.IsPointInTriangle2(p1, p2, p3, ref seg2)) { insect.mIsIntersect = true; insect.mHitGlobalPoint.mPointArray.Add(new Vector3(seg1.x, seg1.y, 0.0f)); insect.mHitGlobalPoint.mPointArray.Add(new Vector3(seg2.x, seg2.y, 0.0f)); return(true); } // 相交测试(不包含 边的重叠) bool isInsect = GeoSegmentUtils.IsSegmentInsectTriangle2(seg1, seg2, p1, p2, p3, ref insect); if (!isInsect) { // 边重叠 测试 isInsect = GeoSegmentUtils.IsSegmentOverlapTriangle2(seg1, seg2, p1, p2, p3, ref insect); } return(insect.mIsIntersect); }