其他分享
首页 > 其他分享> > 判断点在选择的范围内

判断点在选择的范围内

作者:互联网

 #region 判断点在选择的范围内
        //判断点在线的一边 
        private int isLeft(Point P0, Point P1, Point P2)
        {
            int abc = (int)((P1.X - P0.X) * (P2.Y - P0.Y) - (P2.X - P0.X) * (P1.Y - P0.Y));
            return abc;
        }  
        //判断点pnt是否在region内主程序  
        private bool isInRegion(Point pnt, List<Point> region)
        {
            int wn = 0, j = 0; //wn 计数器 j第二个点指针  
            for (int i = 0; i < region.Count; i++)
            {
                //开始循环  
                if (i == region.Count - 1)
                {
                    j = 0;//如果 循环到最后一点 第二个指针指向第一点  
                }
                else
                {
                    j = j + 1; //如果不是 ,则找下一点  
                }
                if (region[i].Y <= pnt.Y) // 如果多边形的点 小于等于 选定点的 Y 坐标  
                {
                    if (region[j].Y > pnt.Y) // 如果多边形的下一点 大于于 选定点的 Y 坐标  
                    {
                        if (isLeft(region[i], region[j], pnt) > 0)
                        {
                            wn++;
                        }
                    }
                }
                else
                {
                    if (region[j].Y <= pnt.Y)
                    {
                        if (isLeft(region[i], region[j], pnt) < 0)
                        {
                            wn--;
                        }
                    }
                }
            }
            if (wn == 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        #endregion

 

标签:P0,判断,Point,int,region,pnt,选择,P1,范围
来源: https://www.cnblogs.com/devgis/p/16524731.html