#  Copyright (c) 1997-2008
#  Technische Universitaet Berlin, Germany
#  Department of Mathematics,
#  Research Group Algorithmic and Discrete Mathematics
#  mailto:polymake@math.tu-berlin.de
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA.
#-----------------------------------------------------------------------------
#  $Project: polymake $$Id: transformation 8208 2008-07-09 19:12:55Z gawrilow $

my $default_iterations=50;

# Polytope, Transformation Matrix, #iterations =>
sub visual_transformation {
   my ($Poly, $Transform, $n_iter)=@_;
   if ($Poly->AMBIENT_DIM>3) {
      die "only 2-d and 3-d polytopes are allowed\n";
   }
   $n_iter ||= $default_iterations;

   my @vis=($Poly->VISUAL(VertexThickness=>0.1));
   my $name=$Poly->name;
   for (my $i=1; $i<=$n_iter; ++$i) {
      $Poly=$Poly->type->construct->("${name}_$i", VERTICES => $Poly->VERTICES * $Transform);
      push @vis, $Poly->VISUAL(VertexThickness=>0.1, FacetTransparency=>0.5);
   }

   compose(@vis);
}

# Polytope, Array<Transformation Matrix>, #iterations =>
sub visual_random_transformation {
   my ($Poly, $Transformations, $n_iter)=@_;
   if ($Poly->AMBIENT_DIM>3) {
      die "only 2-d and 3-d polytopes are allowed\n";
   }
   $n_iter ||= $default_iterations;

   my $m=@$Transformations;
   $n_iter*=$m;
   my @transformed=($Poly);
   $#transformed=$n_iter+1;

   my @vis=($Poly->VISUAL(VertexThickness=>0.1));
   for (my $i=1; $i<$n_iter; ++$i) {
      my $rnd_tr=$Transformations->[int(rand($m))];
      my $rnd_poly=$transformed[int(rand($i))];
      $transformed[$i]=$Poly->type->construct->($Poly->name."_$i", VERTICES => $rnd_poly->VERTICES * $rnd_tr);
      push @vis, $transformed[$i]->VISUAL(VertexThickness=>0.1, FacetTransparency=>0.5);
   }

   compose(@vis);
}


# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
