Ejemplo n.º 1
0
        /// <summary>
        /// 计算多边形和折线(包括线段)是否相交,(未考虑“回”字型)
        /// </summary>
        /// <param name="pd"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        public static bool CalcIfPolygonIntersectPolyline(PolygonD pd, PointDArray line)
        {
            if (!pd.Bounds.IntersectsWith(line.Bounds))
            {
                return(false);
            }
            PointD[] plg1 = pd.Points[0].Points;
            PointD[] plg2 = line.Points;
            PointD   start1, end1, start2, end2;

            for (int i = 0; i < plg1.Length; i++)
            {
                start1 = plg1[i];
                end1   = (i == plg1.Length - 1) ? plg1[0] : plg1[i + 1];
                for (int j = 0; j < plg2.Length - 1; j++)
                {
                    start2 = plg2[j];
                    end2   = plg2[j + 1];
                    if (CrossLine(start1, end1, start2, end2) != 0)
                    {
                        return(true);
                    }
                }
            }
            //补充判断多边形完全包含折线或线段的情况
            if (PtInPolygon(line.Points[0].X, line.Points[0].Y, pd))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// </summary>
 public void AddPoints(PointDArray points)
 {
     _points.Add(points);
     if (_bounds.IsEmpty)
     {
         _bounds = points.Bounds;
     }
     else
     {
         _bounds.Union(points.Bounds);
     }
 }
Ejemplo n.º 3
0
 public static bool CalcRegionContainsRectangle2(PointDArray pda, RectangleD rd)
 {
     if (!pda.Bounds.IntersectsWith(rd))
     {
         return(false);
     }
     PointD[] rc = Calculator.CalcPolygonIntersect(pda.Points, rd);
     if (rc.Length > 2)
     {
         byte result = 0x00;
         for (int i = 0; i < rc.Length; i++)
         {
             if ((rc[i].X != rd.Left && rc[i].X != rd.Right) || (rc[i].Y != rd.Top && rc[i].Y != rd.Bottom))
             {
                 return(false);
             }
             if (rc[i].X == rd.Left && rc[i].Y == rd.Top)
             {
                 result |= 0x01;
             }
             if (rc[i].X == rd.Right && rc[i].Y == rd.Top)
             {
                 result |= 0x02;
             }
             if (rc[i].X == rd.Right && rc[i].Y == rd.Bottom)
             {
                 result |= 0x04;
             }
             if (rc[i].X == rd.Left && rc[i].Y == rd.Bottom)
             {
                 result |= 0x08;
             }
         }
         if (result == 0x0f)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 计算多边形(不含“回”字型)是否包含另一个多边形
 /// </summary>
 /// <param name="regionSource"></param>
 /// <param name="regionTarget"></param>
 /// <returns></returns>
 public static bool CalcRegionContainsRegion(PointDArray regionSource, PointDArray regionTarget)
 {
     if (!regionSource.Bounds.IntersectsWith(regionSource.Bounds))
     {
         return(false);
     }
     for (int i = 0; i < regionTarget.Points.Length; i++)
     {
         PointD start = regionTarget.Points[i];
         PointD end   = (i == regionTarget.Points.Length - 1) ? regionTarget.Points[0] : regionTarget.Points[i + 1];
         if (!CalcRegionContainsLine(regionSource.Points, start, end))
         {
             return(false);
         }
     }
     return(true);
 }