반응형
int isPointInside(struct point A, vector<point>& v, int N) {
	int Count, i, LastPoint;
	bool PointOnTestLine = false;
	struct line TestLine, PolyLine;
	Count = LastPoint = 0;
	TestLine.p1 = A; TestLine.p2 = A;
	TestLine.p2.x = 9999;
	for (i = 0;i <= N;i++) {
		PolyLine.p1 = PolyLine.p2 = v[i];
		if (intersection(TestLine, PolyLine)) {
			PointOnTestLine = true;
			LastPoint = i;
		} //테스트 라인에 점이 있다
		else {// 테스트 라인과 변끼리 교차 확인
			PolyLine.p2 = v[LastPoint];
			LastPoint = i;
			if (!PointOnTestLine) {// false 라면
				if (intersection(PolyLine, TestLine)) Count++;
			}
			else {// true 라면
				if (direction(TestLine.p1, PolyLine.p2, PolyLine.p1) * direction(TestLine.p1, PolyLine.p2, v[LastPoint - 2]) < 0) {
					Count++; PointOnTestLine = false;
				}
			}
		}
	}
	if ((Count % 2) == 1) {
		cout << "true"; return 0;
	}
	else {
		cout << "false";
		return 0;
	}
}
반응형

+ Recent posts