반응형
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;
}
}
반응형
'Lecture > Algorithm' 카테고리의 다른 글
[자료구조] 해쉬 테이블 (0) | 2021.05.13 |
---|---|
[정렬] 퀵 정렬 ( Quick Sort ) (0) | 2021.05.12 |
[탐색] 흑적나무 ( Red - Black Tree ) (0) | 2021.05.12 |
[탐색] 이진탐색트리 (BST) (0) | 2021.05.11 |
[탐색] 이진탐색 (Binary Search ) (0) | 2021.05.10 |