コード例 #1
0
        private void Decompose()
        {
            List <List <Vector2> > tempCenters = new List <List <Vector2> >();

            if (mIsConvex)
            {
                tempCenters = ConvexPolygonScanning.DrawPolygonTranslate(mPolygonData.mPointArray, mScale);
            }
            else
            {
                tempCenters = PolygonScanning.DrawPolygonScale(mPolygonData.mPointArray, mScale);
            }
            foreach (List <Vector2> vv in tempCenters)
            {
                foreach (Vector2 v in vv)
                {
                    Vector2 p = v;
                    if (mIsConvex && GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref p))
                    {
                        mCenterList.Add(p);
                    }
                    else if (!mIsConvex && GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref p))
                    {
                        mCenterList.Add(p);
                    }
                }
            }
        }
コード例 #2
0
        public List <Vector2> Build()
        {
            GeoPointsArray2 polygon2 = FirstTriangle();

            for (int i = 0; i < mCount; ++i)
            {
                Vector2 tmp = mPoints[i];
                if (GeoPolygonUtils.IsPointInConvexPolygon2(polygon2, tmp) == -1)
                {
                    AddPoint(polygon2, tmp);
                }
            }
            return(polygon2.mPointArray);
        }
コード例 #3
0
        private bool CheckRectangleValid(Vector2 min, Vector2 max, float w, float h)
        {
            Vector2 p4 = new Vector2(min[0], max[1]);
            Vector2 p2 = new Vector2(max[0], min[1]);

            // 点都在polygon 内部  // 使用 bvh 判断
            if (mIsConvex)
            {
                bool isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref max);
                if (!isInconvex)
                {
                    return(false);
                }
                isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref min);
                if (!isInconvex)
                {
                    return(false);
                }
                isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref p2);
                if (!isInconvex)
                {
                    return(false);
                }
                isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref p4);
                if (!isInconvex)
                {
                    return(false);
                }
            }
            else
            {
                if (mSegmentsBvh != null)
                {
                    bool insect = mSegmentsBvh.TestIntersection(new GeoAABB2(min, max));
                    if (insect)
                    {
                        return(false);
                    }
                }
                else
                {
                    bool isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref max);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                    isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref min);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                    isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref p2);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                    isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref p4);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                }
            }
            // 矩形与矩形是否有交叉
            bool isInsectAABB = IsIntersectOtherAABB(min, max);

            if (isInsectAABB)
            {
                return(false);
            }
            return(true);
        }
コード例 #4
0
        // 对于环状问题,暂时没处理。处理起来,稍作修改即可。后期遇到时加入(检测环状,然后分离环状,及带孔的多边形环形区域。)
        public static void PolygonExpand(List <Vector2> original, List <Vector2> results, float length = 1.0f, bool useHull = true)
        {
            List <Vector2> origin = new List <Vector2>();

            origin.AddRange(original);
            GeoPointsArray2 hullArray = null;

            if (useHull)
            {
                List <Vector2> hull = JarvisConvex.BuildHull(original);
                GeoPolygonUtils.ReverseIfCW(ref hull);
                hullArray = new GeoPointsArray2(hull);
            }
            float len = length;

            while (results.Count == 0)
            {
                List <Vector2> segs = ExpandPolygonSegments(origin, len);
                float          min  = CheckSegmentsIntersect(segs);
                if (min > len)
                {
                    min = len;
                }
                if (min > 1e-5f)
                {
                    List <Vector2> expands = ExpandPolygon(origin, min);
                    //List<int> vLst = GeoUtils.VertexIndexList(expands);
                    //List<List<int>> circles = CommonUtils.CheckCircle(vLst);
                    // GeoUtils.Split(origin, circles);
                    origin = PolygonIntersectRemove(expands);
                    len    = len - min;
                    if (len < 0.01f)
                    {
                        results.AddRange(origin);
                    }
                }
                else
                {
                    for (int i = 1; i < segs.Count; i += 2)
                    {
                        results.Add(segs[i]);
                    }
                }
                if (useHull && results.Count == 0 && hullArray != null)
                {
                    bool flag = false;
                    for (int i = 0; i < origin.Count; i++)
                    {
                        Vector2 refV = origin[i];
                        if (GeoPolygonUtils.IsPointInConvexPolygon2(hullArray, ref refV))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        List <Vector2> split = JarvisConvex.BuildHull(origin);
                        GeoPolygonUtils.ReverseIfCW(ref split);
                        split = ConvexMarginalExpand(split, len);
                        results.AddRange(split);
                        len = 0;
                    }
                }
            }
        }