# Analytical Solution for the Problem of Point Location in Arbitrary Planar Domains
## 4 Calculation of the Contour Integral
### The Complex Logarithm
#### 4.2.3 Points on the Boundary of Polygons with Undefined Orientation  
Algorithm 1 is valid for all combinations of point \(a\) and polygon \(\{P_{1},P_{2},\ldots,P_{M}\}\), and requires no post-processing; however, there can be ambiguity in a special situation described next, which is nevertheless easily solvable with a more general approach. The special situation just mentioned concerns the points over the boundary when the orientation of the polygon (coarsely, the order in which the vertices are browsed) is not the direct orientation, which may give ambiguous results, as expected by the Jordan curve theorem, and mentioned at the beginning of this paper. Indeed, the contour integral \(\oint_{T}\frac{\text{d}z}{z-a}\), when \(a\) is over the path \(\Gamma\), can result either in \(0\) or \(2\pi\)j or, equivalently, a winding number of \(0\) or \(1\). Additionally, if the polygon is not simple (i.e., is self-intersecting), the polygon orientation is not adjustable (by reversing the order of vertices, for example) because the orientation changes locally after each self-intersection of the boundary line! For those cases, the contour integral is nonetheless always defined, and Figure 8 shows several examples of points near a self-intersecting polygon. In Figure 8, several observations immediately arise: the first is that clear \"outside\" and \"inside\" points are always well determined (winding number of zero or non-zero, respectively). A second observation is that points on the boundary may yield a winding number of \(0\) or \(1\), depending on the circulation sense. There is also a particular case of a point being twice on the boundary (in the intersections), which is always considered \"inside\", no matter the sense of circulation. The mentioned ambiguity is however not unsolvable since it is detectable: simply, in case of doubt about the sense of the polygon orientation, to cover even for points over the boundary, a double calculation can be performed: one with the given vertex point order, and the other with its reverse sense; in case one of the calculations yields zero and the other non-zero, then it is the case of a point over the boundary, and further decision can be taken (normally to be considered included in the polygon). This avoids the need of special analysis to detect points on the boundary, which could be absolutely not recommend on general shaped contours, as managed ahead in this paper. The challenge of points over the boundary is recurrent in all algorithms in the literature. Even one of the most common approaches in the state of the art (the already cited work of [PERSON] and [PERSON] (2018) used in Matlab) has a special treatment for the points on the boundary that the authors call _boundary version_ and is included in Algorithm 7 in their paper, and deals efficiently with points on boundaries of polygons. In conclusion, if there can be points anywhere on the boundary that need to be precisely assessed, and there is no knowledge whether a sequence of points \(\{P_{1},P_{2},\ldots,P_{M}\}\) of a simple polygon is not given in the positive circulation sense, or whether the polygon is not simple, then Algorithm 1 must be called twice, being the second time done with the polygon vertices in the reverse order. If the two calls of the algorithm yield different results, then we are in the presence of a point over the boundary, and it is (usually) to be considered inside the polygon (Algorithm 2 on the following page). Algorithm 2 on the next page requires double the computation resources since it calls the actual calculation algorithm twice. This is required only for the absolutely general case of totally random polygons and testing points, although total randomness will hardly generate situations of points exactly over the border. Anyway, alternatives will be presented ahead.