1、PointWithIn 解题报告该题曾经在讲座中讲过,这里再此将其总结。题是告诉一简单多边形(非相邻边不自交) ,判断一个给定的点是否在该多边形之内。因为该多边形可能是凹多边形,所以不能以判断点同侧的方法来作判断。这里的方法是,从该点出发,引一条射线,计算该射线和多边形边的相交次数,如果次数为奇数,则点在内部;否则,点在外部。相关的代码如下:struct Point double x, y;struct Line Point pt1, pt2;Point polygon100;/functiondouble max(double a,double b)if(ab)return a;else r
2、eturn b;double min(double a,double b)if(a= min(L2.pt1.x, L2.pt2.x) bool InPolygon(Point* polygon,Point point,int size)int n = size;if (n = 1) return ( (fabs(polygon0.x - point.x) side.pt2.y ) count+; else if( IsOnline(side.pt2, line) ) if( side.pt2.y side.pt1.y ) count+; else if( Intersect(line, side) ) count+;return ( count % 2 = 1 );