新发现判断一个点在多边形的最高效率算法 推荐******
//計算點是否在多邊形內(nèi)
int msIntersectPointPolygon(pointObj *point, shapeObj *poly)
{//主函數(shù)1-在 0-不在
?int i;
?int status=MS_FALSE;
?for(i=0; i<poly->numlines; i++)
?{
?? if(msPointInPolygon(point, &poly->line[i]) == MS_TRUE) /* ok, the point is in a line */
????? status = !status;
? }
? return(status);
}
int msPointInPolygon(pointObj *p, lineObj *c)
{//算法非常奇怪!!!
?int i, j, status = MS_FALSE;
?for (i = 0, j = c->numpoints-1; i < c->numpoints; j = i++)
{ if ((((c->point[i].y<=p->y) && (p->y<c->point[j].y)) || ((c->point[j].y<=p->y) && (p->y<c->point[i].y))) && (p->x < (c->point[j].x - c->point[i].x) * (p->y - c->point[i].y) /(c->point[j].y - c->point[i].y) + c->point[i].x))
????? status = !status;?
}
?return status;
}
總結(jié)
以上是生活随笔為你收集整理的新发现判断一个点在多边形的最高效率算法 推荐******的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 生活中处处有joke!!
- 下一篇: 动态sql语句返回值