Algorithm 1 Determining if a point is inside a polygon. |
-
Input:
: sequence of previously visited locations;
-
Output:
Is point located in polygon
-
1:
int crossings = 0;
-
2:
for (int i = 0;i < N ;i++) do
-
3:
double slope = (y[i + 1] − y[i]) / (x[i + 1] − x[i]);
-
4:
bool cond1 = (x[i] ≤ x0) && (x0 < x[i + 1]);
-
5:
bool cond2 = (x[i + 1] ≤ x0) && (x0 < x[i]);
-
6:
if ((cond1 || cond2) && above) then
-
7:
crossings ++;
-
8:
end if
-
9:
end for
-
10:
if crossings % 2 == 0 then
-
11:
return false;
-
12:
else
-
13:
return true;
-
14:
end if
|