Пример #1
0
        private static List <Vector2> ExpandPolygon(List <Vector2> original, float length = 1.0f)
        {
            List <Vector2> tempOrigin = new List <Vector2>();

            tempOrigin.AddRange(original);
            if (GeoPolygonUtils.CalcualetArea(tempOrigin) < 0)
            {
                tempOrigin.Reverse();
            }
            List <Vector2> result = new List <Vector2>();

            for (int i = 0; i < tempOrigin.Count; ++i)
            {
                int j = i + 1;
                if (j == tempOrigin.Count)
                {
                    j = 0;
                }
                int k = i - 1;
                if (k == -1)
                {
                    k = tempOrigin.Count - 1;
                }
                Vector2 vk  = tempOrigin[k] - tempOrigin[i];
                Vector2 vj  = tempOrigin[j] - tempOrigin[i];
                Vector2 dir = vk.normalized + vj.normalized;
                dir.Normalize();
                if (GeoPolygonUtils.IsConvexAngle(tempOrigin[k], tempOrigin[i], dir + tempOrigin[i]))
                {
                    dir = -dir;
                }
                result.Add(tempOrigin[i] + dir * length);
            }
            return(result);
        }
Пример #2
0
 public void Initialize(float scale)
 {
     mScale = scale;
     mArea  = GeoPolygonUtils.CalcualetArea(mPolygonData);
     if (mArea < 0)
     {
         mPolygonData.Reverse();
         mArea = -mArea;
     }
     mAABB     = GeoPolygonUtils.CalculateAABB(mPolygonData);
     mMaxSize  = mAABB.mMax - mAABB.mMin;
     mIsConvex = IsAllConvex();
     Decompose();
     mLeftRectangle.Clear();
 }