几种判断点是否在闭合区域内的方法

1、GDI+自带方法:

        GraphicsPath graphicsPath = new GraphicsPath();
        Region region = new Region();
        graphicsPath.Reset();
        graphicsPath.AddPolygon(listPoint);
        region.MakeEmpty();
        region.Union(graphicsPath);
        bool isInRegion = region.IsVisible(point);

2、其他方法:

       private bool IsInPolygon(PointF checkPoint, List polygonPoints)
       {
        	bool inside = false;
       	 int pointCount = polygonPoints.Count;
        	PointF p1, p2;
       	 for (int i = 0, j = pointCount - 1; i < pointCount; j = i, i++)
       	 {
           	 p1 = polygonPoints[i];
          	  p2 = polygonPoints[j];
            	if (checkPoint.Y < p2.Y)
            	{
               	 if (p1.Y <= checkPoint.Y)
               	 {
                	    if ((checkPoint.Y - p1.Y) * (p2.X - p1.X) > (checkPoint.X - p1.X) * (p2.Y - p1.Y))
                  	  {
                      		  inside = (!inside);
                 	   }
              	         }
            }
            else if (checkPoint.Y < p1.Y)
            {
                   if ((checkPoint.Y - p1.Y) * (p2.X - p1.X) < (checkPoint.X - p1.X) * (p2.Y - p1.Y))
           	     {
                	    inside = (!inside);
              	     }
           }
           }
        	return inside;
        }

你可能感兴趣的:(小知识点)