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
|
# 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.
#-------------------------------------------------------------------------------
use application 'polytope';
die "usage: polymake --script visual_normal_fan object|DATA-FILE\n" unless @ARGV;
my $poly=ref($ARGV[0]) ? $ARGV[0] : load($ARGV[0]);
die "defined for objects of type Polytope<Scalar> only" unless ref($poly) =~ m/^Polymake::polytope::Polytope__/;
die "defined for polytopes of dimension <= 3 only" unless $poly->DIM <= 3;
my $nf = fan::normal_fan($poly);
my $d=$nf->RAYS->cols;
my $rays= normalized(convert_to<Float>($nf->RAYS));
my $zero=new Vector<Float>($d);
my @visuals = ();
my $i = 0;
my $vertices = $poly->VERTICES;
foreach (@{$nf->MAXIMAL_CONES}) {
my $cone=$_;
my $all_ones=ones_vector<Float>($cone->size()+1);
my $v=$all_ones | -($rays->minor($cone,All) / $zero);
my $T1 = new Matrix<Float>([[0,1,0,0],[0,0,1,0],[0,0,0,1]]);
my $V = 1 | (convert_to<Float>(dehomogenize($vertices->[$i])));
my $T = $V / $T1;
my @labels = @{$cone};
push @labels, " ";
my $p=new polytope::Polytope<Float>(VERTICES => $v*$T, VERTEX_LABELS => \@labels);
my $pv=$p->VISUAL(FacetColor => new RGB(.7,.7,0) );
my $dim=$p->DIM;
push @visuals, $pv;
++$i;
}
compose($poly->VISUAL(VertexLabels => "hidden"), @visuals);
# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
|