Ejemplo n.º 1
0
        public static bool IsTriangleInsectCircle3(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointArrayInfo insect)
        {
            bool isInsect = GeoPlaneUtils.IsPlaneInsectTriangle(plane.mNormal, plane.mD, p1, p2, p3, ref insect);

            if (isInsect)
            {
                if (insect.mHitGlobalPoint.mPointArray.Count == 3) // 共面, 转化成 2d
                {
                    insect.Clear();
                    return(IsTriangleInsectPlaneCircle2(p1, p2, p3, center, r, plane, ref insect));
                }
                else if (insect.mHitGlobalPoint.mPointArray.Count == 1)
                {
                    if (GeoCircleUtils.IsInSphere(center, r, insect.mHitGlobalPoint.mPointArray[0]))
                    {
                        return(true);
                    }
                }
                else if (insect.mHitGlobalPoint.mPointArray.Count == 2)
                {
                    Vector3 seg1 = plane.TransformToLocal(insect.mHitGlobalPoint.mPointArray[0]);
                    Vector3 seg2 = plane.TransformToLocal(insect.mHitGlobalPoint.mPointArray[1]);
                    Vector3 c1   = plane.TransformToLocal(center);
                    Vector2 p12  = new Vector2(seg1.x, seg1.z);
                    Vector2 p22  = new Vector2(seg2.x, seg2.z);
                    Vector2 c2   = new Vector2(c1.x, c1.z);
                    insect.Clear();
                    GeoInsectPointArrayInfo temp = new GeoInsectPointArrayInfo();
                    if (GeoSegmentUtils.IsSegmentInsectCircle2(p12, p22, c2, r, ref temp))
                    {
                        insect.mIsIntersect = true;
                        foreach (Vector3 v in temp.mHitGlobalPoint.mPointArray)
                        {
                            Vector3 vv = new Vector3(v.x, 0.0f, v.y);
                            vv = plane.TransformToGlobal(vv);
                            insect.mHitGlobalPoint.mPointArray.Add(vv);
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        public static bool IsTriangleInsectTriangle3(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 p5, Vector3 p6, ref GeoInsectPointArrayInfo insect)
        {
            /*
             * // 外面进行 剔除 处理
             * Vector3 min1 = Vector3.Min(p1, p2);
             * min1 = Vector3.Min(min1, p3);
             * Vector3 max1 = Vector3.Max(p1, p2);
             * max1 = Vector3.Max(max1, p3);
             * Vector3 min2 = Vector3.Min(p4, p5);
             * min2 = Vector3.Min(min2, p6);
             * Vector3 max2 = Vector3.Max(p4, p5);
             * max2 = Vector3.Max(max2, p6);
             * if (!GeoAABBUtils.IsAABBInsectAABB3(min1, max1, min2, max2))
             * {
             *  return false;
             * }
             */
            // 417
            Vector3 p12     = p2 - p1;
            Vector3 p13     = p3 - p1;
            Vector3 normal1 = Vector3.Cross(p12, p13);
            Vector3 p45     = p5 - p4;
            Vector3 p46     = p6 - p4;
            Vector3 normal2 = Vector3.Cross(p45, p46);

            normal1.Normalize();
            normal2.Normalize();
            float dot = Vector3.Dot(normal1, normal2);

            if (1 - Mathf.Abs(dot) < 1e-5f) // 共面
            {
                return(IsTriangleInsectTrianglePlane2(p1, p2, p3, p4, p5, p6, ref insect));
            }
            float d1 = -Vector3.Dot(normal1, p1);
            float d2 = -Vector3.Dot(normal2, p4);
            GeoInsectPointArrayInfo temp1 = new GeoInsectPointArrayInfo();

            if (GeoPlaneUtils.IsPlaneInsectTriangle(normal1, d1, p4, p5, p6, ref temp1))
            {
                GeoInsectPointArrayInfo temp2 = new GeoInsectPointArrayInfo();
                if (GeoPlaneUtils.IsPlaneInsectTriangle(normal2, d2, p1, p2, p3, ref temp2))
                {
                    int count1 = temp1.mHitGlobalPoint.mPointArray.Count;
                    int count2 = temp2.mHitGlobalPoint.mPointArray.Count;
                    if (count1 == 1 && count2 == 1)
                    {
                        bool isEq = temp1.mHitGlobalPoint.mPointArray[0] == temp2.mHitGlobalPoint.mPointArray[0];
                        if (isEq)
                        {
                            insect.mIsIntersect = true;
                            insect.mHitGlobalPoint.mPointArray.Add(temp1.mHitGlobalPoint.mPointArray[0]);
                            return(true);
                        }
                    }
                    else if (count1 == 2 && count2 == 2)
                    {
                        Vector3 s1 = temp1.mHitGlobalPoint.mPointArray[0];
                        Vector3 s2 = temp1.mHitGlobalPoint.mPointArray[1];
                        Vector3 s3 = temp2.mHitGlobalPoint.mPointArray[0];
                        Vector3 s4 = temp2.mHitGlobalPoint.mPointArray[1];
                        GeoSegmentUtils.IsSegmentOverlapSegment3(s1, s2, s3, s4, ref insect);
                    }
                }
            }
            return(insect.mIsIntersect);
        }