in reply to Combine line segments to form a single line
If we can assume that the segments always form a cycle (the ones in your example do), then the Graph module's find_a_cycle method seems to do the trick...
use Graph; my @AoA = ( [11,29, 10,25], [15,35, 11,29], [15,15, 11,21], [10,25, 11,21], [15,35, 21,39], [25,40, 21,39], [21,11, 25,10], [15,15, 21,11], [35,35, 29,39], [29,39, 25,40], [35,15, 29,11], [25,10, 29,11], [40,25, 39,29], [35,35, 39,29], [39,21, 40,25], [35,15, 39,21], ); my $graph = Graph::Undirected->new; for my $pair (@AoA) { my ($x1, $y1, $x2, $y2) = @$pair; $graph->add_edge("$x1,$y1", "$x2,$y2"); } print "$_\n" for $graph->find_a_cycle;
If the points are not guaranteed to form a cycle, then I think Graph is still a good place to start.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Combine line segments to form a single line
by bangor (Monk) on Jan 13, 2014 at 13:58 UTC |