public static bool IsTriangleInsectSphere(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 center, float r, ref GeoInsectPointArrayInfo insect) { GeoPlane plane = GeoPlaneUtils.CreateFromTriangle(p1, p2, p3); bool isInsec = GeoPlaneUtils.IsPlaneInsectSphere(plane, center, r, ref insect); if (isInsec) { Vector3 c1 = insect.mHitGlobalPoint.mPointArray[0]; float rad = insect.mHitGlobalPoint.mPointArray[0][0]; insect.Clear(); return(IsTriangleInsectPlaneCircle2(p1, p2, p3, c1, rad, plane, ref insect)); } return(false); }
// 两三角面 共面的情况 private static bool IsTriangleInsectTrianglePlane2(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 p5, Vector3 p6, ref GeoInsectPointArrayInfo insect) { GeoPlane plane = GeoPlaneUtils.CreateFromTriangle(p1, p2, p3); Vector2 p11, p21, p31, p41, p51, p61; GeoPlaneUtils.PlaneTransformLocalTriangle(p1, p2, p3, plane, out p11, out p21, out p31); GeoPlaneUtils.PlaneTransformLocalTriangle(p4, p5, p6, plane, out p41, out p51, out p61); GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo(); bool isInsect = IsTriangleInsectTriangle2(p11, p21, p31, p41, p51, p61, ref tmp); if (isInsect) { foreach (Vector3 v in tmp.mHitGlobalPoint.mPointArray) { Vector3 vt = new Vector3(v.x, 0.0f, v.z); vt = plane.TransformToGlobal(vt); insect.mHitGlobalPoint.mPointArray.Add(vt); } insect.mIsIntersect = insect.mHitGlobalPoint.mPointArray.Count > 0; } return(insect.mIsIntersect); }