1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
# Copyright (c) 1997-2024
# Ewgenij Gawrilow, Michael Joswig, and the polymake team
# Technische Universität Berlin, Germany
# https://polymake.org
#
# 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: http://www.gnu.org/licenses/gpl.txt.
#
# 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.
#-------------------------------------------------------------------------------
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/$n_iter, 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 @colors=("red", "blue", "yellow", "green", "orange");
my @colors=("255 0 0","0 0 255","255 255 0","0 255 0","255 165 0");
my @vis=($Poly->VISUAL(VertexThickness=>0.1, VertexLabels=>"hidden"));
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,
FacetColor=>$colors[$i%5],
FacetTransparency=>0.5,
VertexLabels=>"hidden");
}
compose(@vis);
}
# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
|