Remove holes in a polygon

I have a polygon defined by an array of points.

This polygon intersects itself, forming some holes in the polygon itself.

My questions are: how can I lower these holes and just get the outside points of the polygon?

Or what will be the same and possibly simpler: which algorithm to check if a point is inside the polygon should be used to detect points in the holes of the polygon as inside the points?

Thanks in advance,

/Roger

+3
source share
2 answers

, . , , , (, " " ) , . ​​ .

+4

, .

- Graham-Scan O (nlgn). :

Let Q be the set of all points in your polygon
Graham-Scan(Q)

1  let p0 be the point in q with the minimum y-coordinate or the leftmost in case of tie
2  let (p1, p2,...,pm) be the remaining points in Q, sorted by polar angle around p0
       if more than one point shares the same polar angle, keep the farthest point

3  let S be an empty stack
4  PUSH(p0, S)
5  PUSH(p1, S)
6  PUSH(p2, S)
7  for i = 3 to m
8    while the angle formed by points NEXT_TO_TOP(S), TOP(S), and pi makes a non-left turn
9        POP(S)
10   PUSH(pi, S)
11 return S

S . - , . , . , , Graham-Scan. , !

0

Source: https://habr.com/ru/post/1722683/


All Articles