Supposing the polygon descriptions obtained from M::G::Voronoi doesn't return different overlapping edges (that I think it doesn't):
- select all the points/polygons you want to merge: @points
- calculate the set of all the edges involved: @edges
- discard from @edges all the edges that have both side points belonging to @points
- reconstruct polygons from the remaining edges:
- calculate the set of all the vertices in @edges: @vertices
- set @polygon = (); $direction = vector (0, -1)
- get the leftmost $vertex from @vertices
- select from @edges the ones that have $vertex at some extreme: @departing
- for my $dep (@departing) { calculate the angle in the range (-π,π) between $direction and the vector ($dep->the_other_vertex - $vertex) } and select the edge $this_edge with minimum angle (minimum = most negative, not minimum in abs value!)
- push $polygon, $this_edge
- set $direction = previously calculated vector ($this_edge->the_other_vertex - $vertex)
- set $vertex = $this_edge->the_other_vertex
- repeat from 4.4 until $vertex is equal again to the starting vertex found in 4.3
- look for holes inside @polygon (left as an exercise for the reader :-) )
- remove the edges inside @polygon from @edges
- repeat from 4.1 until @edges is empty.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|