|
|
发表于 2005-3-3 00:29:00
|
显示全部楼层
Re:怎么样判断平面上一个点是不是在一个多边形内部?
//如果点在多边形内,则返回值为1.
//如果点在多边形外,则返回值为0.
//在边界上返回值不确定,可能0或1.
int is_point_in_polygon_cn(const point_type* P, int n, const point_type& tp)
{
int i, j, b = 0;
for (i = 0, j = n-1; i < n; j = i++)
{
if(((P.y <= tp.y && tp.y < P[j].y) ||
(P[j].y <= tp.y && tp.y < P.y)) &&
tp.x < (P[j].x - P.x) * (tp.y - P.y) / (P[j].y - P.y) + P.x)
b = !b;
}
return b;
}
http://www.faqs.org/faqs/graphics/algorithms-faq/ |
|