Пример #1
0
        public static bool IsSegmentInsectCircle2(Vector2 seg1, Vector2 seg2, Vector2 center, float r, ref GeoInsectPointArrayInfo insect)
        {
            if (GeoCircleUtils.IsInCircle(center, r, seg1) && GeoCircleUtils.IsInCircle(center, r, seg2)) // 都在外面,不一定
            {
                return(false);
            }
            bool           isinsect    = GeoLineUtils.IsLineInsectCircle2(seg1, seg2, center, r, ref insect);
            List <Vector3> array       = insect.mHitGlobalPoint.mPointArray;
            List <int>     removeIndex = new List <int>();

            for (int i = 0; i < array.Count; ++i)
            {
                Vector2 temp = new Vector2(array[i].x, array[i].y);
                if (!IsPointInSegment2(seg1, seg2, ref temp))
                {
                    removeIndex.Add(i);
                }
            }
            for (int i = removeIndex.Count - 1; i >= 0; --i)
            {
                array.RemoveAt(i);
            }
            insect.mHitGlobalPoint.mPointArray = array;
            insect.mIsIntersect = insect.mHitGlobalPoint.mPointArray.Count > 0;
            return(insect.mIsIntersect);
        }
Пример #2
0
 public static bool IsRayInsectCircle3(Vector3 rayOrigin, Vector3 rayDirection, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointInfo insect)
 {
     if (GeoPlaneUtils.IsPlaneInsectRay(plane.mNormal, plane.mD, rayOrigin, rayDirection, ref insect))
     {
         if (GeoCircleUtils.IsInSphere(center, r, insect.mHitGlobalPoint))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #3
0
        public static bool IsSegmentInsectCircle3(Vector3 seg1, Vector3 seg2, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointInfo insect)
        {
            bool isInsect = GeoPlaneUtils.IsPlaneInsectSegment(plane.mNormal, plane.mD, seg1, seg2, ref insect);

            if (isInsect)
            {
                if (GeoCircleUtils.IsInSphere(center, r, insect.mHitGlobalPoint))
                {
                    return(true);
                }
            }
            insect.mIsIntersect = isInsect;
            return(isInsect);
        }
        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);
        }
Пример #5
0
        public static bool IsLineInsectCircle3(Vector3 line1, Vector3 line2, Vector3 center, float r, GeoPlane plane, ref GeoInsectPointArrayInfo insect)
        {
            if (GeoPlaneUtils.IsPointOnPlane(plane.mNormal, plane.mD, line1) && GeoPlaneUtils.IsPointOnPlane(plane.mNormal, plane.mD, line2))
            {
                return(IsLineInsectCirclePlane2(line1, line2, center, r, plane, ref insect));
            }
            GeoInsectPointInfo info = new GeoInsectPointInfo();
            bool isInsect           = GeoPlaneUtils.IsPlaneInsectLine(plane.mNormal, plane.mD, line1, line2, ref info);

            if (isInsect)
            {
                if (GeoCircleUtils.IsInSphere(center, r, info.mHitGlobalPoint))
                {
                    insect.mIsIntersect = true;
                    insect.mHitGlobalPoint.mPointArray.Add(info.mHitGlobalPoint);
                    return(true);
                }
                insect.mIsIntersect = false;
            }
            return(false);
        }