|
各位好!
以下是我在网上找的一个判定点是否在四边形之内的函数,但是使用C语言写的,并且利用到了指针,自己的VB知识在指针方面的应用还不熟悉,麻烦高人帮我转为VBA,非常感谢!
function InsidePolygon3( POINTD *polygon,int N,POINTD pt )
{
int i,j;
bool inside = false;
double polygon_area = 0;
double trigon_area = 0;
for (i = 0,j = N - 1;i < N;j = i++)
{
polygon_area += polygon[i].x * polygon[j].y - polygon[j].x * polygon[i].y;
trigon_area += abs(
pt.x * polygon[i].y -
pt.x * polygon[j].y -
polygon[i].x * pt.y +
polygon[i].x * polygon[j].y +
polygon[j].x * pt.y -
polygon[j].x * polygon[i].y
);
}
trigon_area *= 0.5;
polygon_area = abs(polygon_area * 0.5);
if ( fabs(trigon_area - polygon_area) < 1e-7 )
inside = true;
return inside;
} |
|