PNPOLY - Point Inclusion in Polygon Test

Posted at 2008/06/09 09:24 // in Programming // by Daniel

http://www.ecse.rpi.edu/homepages/wrf/r ··· oly.html

n vertex로 이루어진 다각형 안에 포인트가 있는지 알아보는 코드입니다.

int pnpoly(int nvert, float *vertx, float *verty, float testx, float testy)
{ int i, j, c = 0; for (i = 0, j = nvert-1; i < nvert; j = i++) { if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) c = !c; } return c;
}

Argument Meaning
nvert Number of vertices in the polygon. Whether to repeat the first vertex at the end is discussed below.
vertx, verty Arrays containing the x- and y-coordinates of the polygon’s vertices.
testx, testy X- and y-coordinate of the test point.

크리에이티브 커먼즈 라이센스
Creative Commons License

이 글에는 트랙백을 보낼 수 없습니다

  1. polygon-으로 이어질 블로그링 from blogring.org 2008/12/21 03:26 [삭제]