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 IsTriangleInsectCircle2(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 center, float r, ref GeoInsectPointArrayInfo insect)
        {
            GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo();

            if (GeoSegmentUtils.IsSegmentInsectCircle2(p1, p2, center, r, ref tmp))
            {
                insect.mHitGlobalPoint.mPointArray.AddRange(tmp.mHitGlobalPoint.mPointArray);
            }
            tmp.Clear();
            if (GeoSegmentUtils.IsSegmentInsectCircle2(p3, p2, center, r, ref tmp))
            {
                insect.mHitGlobalPoint.mPointArray.AddRange(tmp.mHitGlobalPoint.mPointArray);
            }
            tmp.Clear();
            if (GeoSegmentUtils.IsSegmentInsectCircle2(p1, p3, center, r, ref tmp))
            {
                insect.mHitGlobalPoint.mPointArray.AddRange(tmp.mHitGlobalPoint.mPointArray);
            }
            tmp.Clear();
            return(false);
        }
Ejemplo n.º 3
0
        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);
        }