bool point_in_polygon(const Vector2d &pt,const std::vector<Vector2d>& polygon)
{
int i,j = static_cast<int>(polygon.size())-1 ;
bool oddNodes=false;
double x = pt.x;
double y =pt.y;
for (i=0;i<polygon.size(); i++)
{
if((polygon[i].y < y && polygon[j].y >= y
|| polygon[j].y < y && polygon[i].y >= y)
&& (polygon[i].x <= x || polygon[j].x <= x))
{
oddNodes^=(polygon[i].x+(y-polygon[i].y)/(polygon[j].y-polygon[i].y)*(polygon[j].x-polygon[i].x)<x);
}
j=i;
}
return oddNodes;
}
判断点是否在多边形内
最新推荐文章于 2020-02-10 15:45:28 发布