Reputation: 4113
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:
O(n log(n))
where n
is the number of pointsThanks for your help!
Upvotes: 3
Views: 309
Reputation: 4113
I think I've got it.
x
. In case of a tie, pick the one with the lowest y
. This process is O(n)
O(s)
where s
is the number of segments that are connected to the starting vertex.O(n i/2)
where i
is the average number of segments connected to each vertex.This algorithm's worst case time complexity is O(n i/2)
where n
is the number of vertices and i
is the average number of segments connected to each vertex. The best case complexity is O(n)
for a polygon that never intersects. In my case the polygons rarely intersect so this process is close to O(n)
.
Upvotes: 1
Reputation: 6021
Let me think of a way where this isn't n^2, because you are comparing n points with n segments.
Upvotes: 0