I'm looking for an algorithm for calculating the maximum area in a self-intersecting polygon. As it's self-intersecting it is not trivial to calculate the area with methods such as the shoelace formula.
Example:
The polygon in the example prioritises vertices with the "smallest" letter alphabetically, sometimes going back to the same vertex in a non-alphabetical way as it is self-intersecting. Although that shouldn't make a difference in the expected area.
In this case the algorithm should output 40: the area of the square (36) plus the area of the 4 outer triangles (4).
Constraints:
- The intersection points are known in advance, no need to calculate them (as the example shows)
- The last point is guaranteed to connect back to the figure, i.e. no dangling lines
- The polygon is always traceable, i.e. it can be drawn, without lifting the pen
- Time complexity ideally not worse than
O(n log(n))
wheren
is the number of points
Thanks for your help!
O(n²)
- I was hoping for something with a better performance – satoshi