TA的每日心情![](source/plugin/dsu_paulsign/img/emot/kx.gif) | 开心 昨天 15:23 |
---|
签到天数: 69 天 [LV.6]常住居民II
管理员
- 积分
- 2704
|
objectarx之点在点集内
static bool IsPtInPolygon(const AcGePoint2d& pt, const AcGePoint2dArray& points)
{
int nCross = 0;
int nCount = points.length();
for (int i = 0; i < nCount; i++)
{
AcGePoint2d pt1 = points[i];
AcGePoint2d pt2 = points[(i + 1) % nCount];
if (pt1.y == pt2.y) // 平行于X轴
continue;
if (pt.y < min(pt1.y, pt2.y) || pt.y > max(pt1.y, pt2.y) ) // 没有交点
continue;
double x = (pt.y - pt1.y) * (pt2.x - pt1.x) / (pt2.y - pt1.y) + pt1.x;
if (x > pt.x)
nCross++;
}
return (nCross % 2 == 1);
}
|
|