public static bool IsPointInAABB2Plane(Vector3 min, Vector3 max, GeoPlane plane, ref Vector3 p)
        {
            if (!GeoPlaneUtils.IsPointOnPlane(plane.mNormal, plane.mD, p))
            {
                return(false);
            }
            Vector3 size = max - min;
            float   sx   = Vector3.Dot(size, plane.mAxisX);
            float   sz   = Vector3.Dot(size, plane.mAxisZ);
            Vector3 pc   = p - min;
            float   d1   = Vector3.Dot(pc, plane.mAxisX);
            float   d2   = Vector3.Dot(pc, plane.mAxisZ);

            if (d1 < sx && d2 < sz)
            {
                return(true);
            }
            return(false);
        }
Exemple #2
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);
        }
        public static bool IsCircleInsectCircle3(Vector3 center1, float r1, GeoPlane plane1, Vector3 center2, float r2, GeoPlane plane2, ref GeoInsectPointArrayInfo insect)
        {
            float dot = Mathf.Abs(Vector3.Dot(plane1.mNormal, plane2.mNormal));

            if (1 - dot < GeoUtils.PRECISION)
            {
                if (GeoPlaneUtils.IsPointOnPlane(plane2.mNormal, plane2.mD, center1)) // 共面
                {
                    return(IsCircleInsectCirclePlane2(center1, r1, center2, r2, plane2, ref insect));
                }
                return(false);
            }
            GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo();
            bool isInsect = GeoPlaneUtils.IsPlaneInsectCircle(plane1.mNormal, plane1.mD, center2, r2, plane2, ref tmp);

            if (isInsect)
            {
                Vector3 lin1 = tmp.mHitGlobalPoint.mPointArray[0];
                Vector3 lin2 = lin1 + tmp.mHitGlobalPoint.mPointArray[1];
                GeoLineUtils.IsLineInsectCirclePlane2(lin1, lin2, center1, r1, plane1, ref insect);
            }
            return(insect.mIsIntersect);
        }
        public static bool IsAABBInsectCircle3(Vector3 min, Vector3 max, GeoPlane plane1, Vector3 center, float r, GeoPlane plane2, ref GeoInsectPointArrayInfo insect)
        {
            float dot = Vector3.Dot(plane1.mNormal, plane2.mNormal);

            if (1 - Mathf.Abs(dot) < 1e-5f)
            {
                if (GeoPlaneUtils.IsPointOnPlane(plane2.mNormal, plane2.mD, min))
                {
                    return(IsAABBInsectCirclePlane2(min, max, center, r, plane1, ref insect)); // should use plane1
                }
                return(false);
            }
            GeoInsectPointArrayInfo tmp = new GeoInsectPointArrayInfo();
            bool isInsect = GeoPlaneUtils.IsPlaneInsectCircle(plane1.mNormal, plane1.mD, center, r, plane2, ref tmp);

            if (isInsect)
            {
                if (tmp.mHitGlobalPoint.mPointArray.Count == 1)
                {
                    Vector3 line1 = tmp.mHitGlobalPoint.mPointArray[0];
                    if (GeoAABBUtils.IsPointInAABB2Plane(min, max, plane1, ref line1))
                    {
                        insect.mIsIntersect = true;
                        insect.mHitGlobalPoint.mPointArray.Add(line1);
                        return(true);
                    }
                }
                else
                {
                    Vector3 seg1 = tmp.mHitGlobalPoint.mPointArray[0];
                    Vector3 seg2 = seg1 + tmp.mHitGlobalPoint.mPointArray[1];
                    return(GeoSegmentUtils.IsSegmentInsectAABB2Plane(seg1, seg2, min, max, plane1, ref insect));
                }
            }
            return(false);
        }