Hello, I need an algorithm that receives polygons and outputs a single polygon that covers all.
Thanks in advance.
Joining polygons
Moderator: Board moderators
-
- New poster
- Posts: 9
- Joined: Sat Dec 01, 2007 1:42 am
Joining polygons
It would be easy.
-
- New poster
- Posts: 9
- Joined: Sat Dec 01, 2007 1:42 am
One simple O(n^2) algorithm is this:
First, for each edge of every polygon, find at which points other edges intersect it, and split it into multiple edges at these points. Then choose a vertex P0, which is known to be at the border of union of polygons, for example the one with smallest x coordinate, and in case of a tie, smallest y.
Starting from P0, at each step choose an edge incident to current vertex, which makes largest right-hand turn, and follow it until you come back to P0. The polyline that this process traces is what you're looking for, I guess.
First, for each edge of every polygon, find at which points other edges intersect it, and split it into multiple edges at these points. Then choose a vertex P0, which is known to be at the border of union of polygons, for example the one with smallest x coordinate, and in case of a tie, smallest y.
Starting from P0, at each step choose an edge incident to current vertex, which makes largest right-hand turn, and follow it until you come back to P0. The polyline that this process traces is what you're looking for, I guess.
-
- New poster
- Posts: 9
- Joined: Sat Dec 01, 2007 1:42 am
-
- New poster
- Posts: 9
- Joined: Sat Dec 01, 2007 1:42 am