in reply to reordering segments to form a polygon
Just tidy up what others have done, especially the non-closed situation.
use strict; my @seg = ( [ 1, 1, 2, 1 ], [ 5, 5, 1, 5 ], [ 2, 3, 5, 3 ], [ 5, 3, 5, 5 ], [ 2, 1, 2, 3 ], [ 1, 5, 1, 1 ]); my %pairs = map{("[$_->[0],$_->[1]]","[$_->[2],$_->[3]]")} @seg; my $start = "[1,1]"; my $current = $start; do{ print $current,"\n"; $current = $pairs{$current}; }while(defined $pairs{$current} && $current ne $start) __OUTPUT__ [1,1] [2,1] [2,3] [5,3] [5,5] [1,5]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: reordering segments to form a polygon
by ikegami (Patriarch) on Aug 13, 2004 at 18:42 UTC |
In Section
Seekers of Perl Wisdom