system: [SYSTEM]

user: 附录 BOOL PtInRegionEx(POINT *ps， int num， POINT p) { CRgn rgn; rgn.CreatePolygonRgn(ps，num，WINDING); BOOL YN = FALSE; //多边形包围盒 int minx = 999999999，maxx = -999999999，miny = 999999999，maxy = -999999999; for(int i=0; i { if(ps[i].x <= minx) minx = ps[i].x; if(ps[i].x >= maxx) maxx = ps[i].x; if(ps[i].y <= miny) miny = ps[i].y; if(ps[i].y >= maxy) maxy = ps[i].y; } //包围盒之内的点 int Dx， Dy， j; int minxl， maxxl， minyl， maxyl; //线段的范围(包围盒) if(p.x <= maxx && p.x >= minx && p.y <= maxy && p.y >= miny) { YN = PtInRegion(rgn， p.x， p.y); if( YN == TRUE ) return YN; else { for(j=0; j { if(p.x == ps[j].x && p.y == ps[j].y) YN = TRUE; } for(j=0; j { if(j == num-1) { if(ps[j].x <= ps[ 0 ].x) { minxl = ps[j].x; maxxl = ps[ 0 ].x; } else { minxl = ps[ 0 ].x; maxxl = ps[j].x; } if(ps[j].y <= ps[ 0 ].y) { minyl = ps[j].y; maxyl = ps[ 0 ].y; } else { minyl = ps[ 0 ].y; maxyl = ps[j].y; } Dx = ps[j].x - ps[ 0 ].x; Dy = ps[j].y - ps[ 0 ].y; //如果是边界上的点 if( (p.x minxl && p.y minyl) && (Dx*(p.y-ps[j].y) + Dy*ps[j].x ) == (Dy*p.x) ) YN = TRUE; } else { if(ps[j].x <= ps[j+1].x) { minxl = ps[j].x; maxxl = ps[j+1].x; } else { minxl = ps[j+1].x; maxxl = ps[j].x; } if(ps[j].y <= ps[j+1].y) { minyl = ps[j].y; maxyl = ps[j+1].y; } else { minyl = ps[j+1].y; maxyl = ps[j].y; } Dx = ps[j].x - ps[j+1].x; Dy = ps[j].y - ps[j+1].y; //如果是边界上的点 if( (p.x minxl && p.y minyl) &&(Dx*(p.y-ps[j].y) + Dy*ps[j].x ) == (Dy*p.x) ) YN = TRUE; } } return YN; } } //包围盒之外的点 else return YN; } const double PI = 3.14159265; double D2DistanceOfPointToLine(double xx，double yy，double x1，double y1，double x2，double y2) { double a，b，c，ang1，ang2，ang，m; double result=0; //分别计算三条边的长度 a = sqrt((x1 - xx) * (x1 - xx) + (y1 - yy) * (y1 - yy)); if (a == 0) return 0; b = sqrt((x2 - xx) * (x2 - xx) + (y2 - yy) * (y2 - yy)); if (b == 0) return 0; c = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); //如果线段时一个点则退出函数并返回距离 if (c == 0) { result = a; return result; } //如果点(xx，yy)到点(x1，y1)这条边近 if (a < b) { //如果直线段AB是水平线，得到直线段AB的弧度 if (y1 == y2) { if (x1 < x2) ang1 = 0; else ang1 = PI; } else { m = (x2 - x1) / c; if (m - 1 > 0.00001) m = 1; ang1 = acos(m); if (y1 >y2) ang1 = PI*2- ang1;//直线(x1，y1)-(x2，y2)与X轴正向夹角的弧度 } m = (xx - x1) / a; if (m - 1 > 0.00001) m = 1; ang2 = acos(m); if (y1 > yy) ang2 = PI * 2 - ang2;//直线(x1，y1)-(xx，yy)与X轴正向夹角的弧度 ang = ang2 - ang1; if (ang < 0) ang = -ang; if (ang > PI) ang = PI * 2 - ang; //如果是钝角则直接返回距离 if (ang > PI / 2) return a; else return a * sin(ang); } else//如果(xx，yy)到点(x2，y2)这条边较近 { //如果两个点的纵坐标相同，则直接得到直线斜率的弧度 if (y1 == y2) if (x1 < x2) ang1 = PI; else ang1 = 0; else { m = (x1 - x2) / c; if (m - 1 > 0.00001) m = 1; ang1 = acos(m); if (y2 > y1) ang1 = PI * 2 - ang1; } m = (xx - x2) / b; if (m - 1 > 0.00001) m = 1; ang2 = acos(m);//直线(x2，y2)-(xx，yy)斜率的弧度 if (y2 > yy) ang2 = PI * 2 - ang2; ang = ang2 - ang1; if (ang < 0) ang = -ang; if (ang > PI) ang = PI * 2 - ang;//交角的大小 //如果是对接则直接返回距离 if (ang > PI / 2) return b; else return b * sin(ang);//如果是锐角，返回计算得到的距离 } } BOOL PtInRgn(POINT *ps， int num， POINT p) { int minx = 999999999，maxx = -999999999，miny = 999999999，maxy = -999999999; for(int i=0; i { if(ps[i].x <= minx) minx = ps[i].x; if(ps[i].x >= maxx) maxx = ps[i].x; if(ps[i].y <= miny) miny = ps[i].y; if(ps[i].y <= maxy) maxy = ps[i].y; } if(p.x <= maxx && p.x >= minx && p.y <= maxy && p.y >= miny)//对包围盒内的点进行判断 { double mind = 999999999， d1; int index=-1， i， j; for(j=0; j { if(j==num-1) d1 = D2DistanceOfPointToLine(p.x，p.y，ps[j].x，ps[j].y，ps[ 0 ].x，ps[ 0 ].y); else d1 = D2DistanceOfPointToLine(p.x，p.y，ps[j].x，ps[j].y，ps[j+1].x，ps[j+1].y); if(d1>=0 && d1<=mind) { mind = d1; index = j; } } double v = 0.0; if(index>-1 && index { v = -((ps[index].x - p.x)*(ps[index+1].y - p.y) - (ps[index].y - p.y)*(ps[index+1].x - p.x)); } else if(index == num) v = -((ps[index].x - p.x)*(ps[ 0 ].y - p.y) - (ps[index].y - p.y)*(ps[ 0 ].x - p.x)); if(v<0) //点在线段右侧 mind = -mind; if(mind<0)//多边形外的点返回假 return FALSE; else //多边形内及边界上的点返回真 return TRUE; } else//包围盒外的点返回假 return FALSE; }