跳到主要內容

Ray Casting Algorithm

struct Point {double x, y;} p[10]; // 十個頂點的多邊形

bool point_in_polygon(Point& t)
{
bool c = false;
for (int i = 0, j = 10-1; i t.y) != (p[j].y > t.y) &&
t.x < (p[j].x-p[i].x)*(t.y-p[i].y)/(p[j].y-p[i].y)+p[i].x)
c = !c;
return c;
}

留言