예제 #1
0
        /// <summary>
        /// 判断点pt是否在多边形中
        /// </summary>
        /// <param name="poly">多边形</param>
        /// <param name="polyFaceNormal"></param>
        /// <param name="pt"></param>
        /// <returns></returns>
        public bool IsInsidePolyEx(Poly poly, Vector3d pt, PloySideType checkSideType = PloySideType.Allside)
        {
            PolySide[] polySides = poly.sidesList[0];
            Vector3d   n         = Vector3d.Cross(pt - polySides[0].startpos, polySides[0].dir);

            if (!IsZero(n) || !IsParallel(n, poly.faceNormal))
            {
                return(false);
            }

            return(IsInsidePoly(poly, pt, checkSideType));
        }
예제 #2
0
        /// <summary>
        /// 判断点pointMustInPloyPlane是否在多边形中,
        /// pointMustInPloyPlane必须在多边形的同一平面中,但不一定在多边形中
        /// </summary>
        /// <param name="polySides">多边形中所有点共面</param>
        /// <param name="pointMustInPloyPlane"></param>
        /// <returns></returns>
        public bool IsInsidePoly(Poly poly, Vector3d pointMustInPloyPlane, PloySideType checkSideType = PloySideType.Allside)
        {
            PolySide[]        polySides;
            List <PolySide[]> polySidesList  = poly.sidesList;
            Vector3d          pt             = pointMustInPloyPlane;
            Vector3d          polyFaceNormal = poly.faceNormal;

            //判断从点引出的平行于sides[0]方向的正向射线是否与其它边相交
            Vector3d n            = polySidesList[0][0].startpos - pt;
            int      crossPtCount = 0;
            Vector3d crossPt;
            PolySide polySide2 = new PolySide();

            polySide2.startpos = pt;
            polySide2.dir      = n;
            polySide2.step     = 1000000;

            for (int j = 0; j < polySidesList.Count; j++)
            {
                if (checkSideType == PloySideType.Outside)
                {
                    if (j == 1)
                    {
                        break;
                    }
                }
                else if (checkSideType == PloySideType.Inside)
                {
                    if (j == 0)
                    {
                        continue;
                    }
                }

                polySides = polySidesList[j];

                for (int i = 0; i < polySides.Length; i++)
                {
                    crossPtCount += SolvePolySideCrossPoint(polySides[i], polySide2, polyFaceNormal, true, out crossPt);
                }
            }

            //判断是偶数个交点,还是奇数个交点
            if (crossPtCount % 2 == 0)
            {
                return(false);
            }

            return(true);
        }