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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
# 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.
#-------------------------------------------------------------------------------
package Visual::Polytope;
# Visualize the [[LATTICE_POINTS]] of a polytope
# @options %Visual::PointSet::decorations
# @return Visual::Polytope
# @example Visualizes the lattice points of the threedimensional cube.
# > cube(3)->VISUAL->LATTICE;
user_method LATTICE(%Visual::PointSet::decorations) {
my ($self, $decor)=@_;
my $VP=$self->basis_solid;
$VP->VertexStyle //= "hidden";
my $P=$self->Polytope;
if ($P->CONE_DIM > 2) {
$VP->FacetStyle //= "hidden";
}
my $vert = $P->VERTICES;
my $lp = $P->LATTICE_POINTS;
my $nlv = new Matrix<Float>(map { convert_to<Float>($_) } grep {!is_integral($_)} @$vert);
my $points = new Matrix<Float>(0,$P->CONE_DIM);
$points /= convert_to<Float>($P->LATTICE_POINTS) if ($P->N_LATTICE_POINTS);
$points /= $nlv if ($nlv->rows);
push @{$self->elements} , new Visual::PointSet(
Name => "Lattice points and vertices of ". $P->name,
Points => dehomogenize($points),
PointLabels => "hidden",
PointColor => sub { $_[0] < $P->N_LATTICE_POINTS ? $Visual::Color::LatticePointColor :
$Visual::Color::vertices },
$decor,
);
visualize($self);
}
# Visualize the [[LATTICE_POINTS]] of a polytope in different colors (interior / boundary / vertices)
# @options %Visual::PointSet::decorations
# @return Visual::Polytope
# @example Creates the threedimensional unit cube scaled by 1.5 and displays the colored version of its lattice points
# > cube(3,(3/2),0)->VISUAL->LATTICE_COLORED;
user_method LATTICE_COLORED(%Visual::PointSet::decorations) {
my ($self, $decor)=@_;
my $VP=$self->basis_solid;
$VP->VertexStyle //= "hidden";
my $P=$self->Polytope;
if ($P->CONE_DIM > 2) {
$VP->FacetStyle //= "hidden";
}
$P->provide("LATTICE_POINTS_GENERATORS");
my $vert = $P->VERTICES;
my $nlv = new Matrix<Float>(map { convert_to<Float>($_) } grep {!is_integral($_)} @$vert);
my $points = new Matrix<Float>(0, $P->CONE_DIM);
$points /= convert_to<Float>($P->INTERIOR_LATTICE_POINTS) if ($P->N_INTERIOR_LATTICE_POINTS);
$points /= convert_to<Float>($P->BOUNDARY_LATTICE_POINTS) if ($P->N_BOUNDARY_LATTICE_POINTS);
$points /= $nlv if ($nlv->rows);
push @{$self->elements} , new Visual::PointSet(
Name => "Lattice points and vertices of ". $P->name,
Points => dehomogenize($points),
PointLabels => "hidden",
PointColor => sub { $_[0] < $P->N_INTERIOR_LATTICE_POINTS ? $Visual::Color::InteriorLatticePointColor :
$_[0] < $P->N_LATTICE_POINTS ? $Visual::Color::BoundaryLatticePointColor :
$Visual::Color::vertices },
$decor,
);
visualize($self);
}
package Visual::Color;
# Color for the visualization of interior lattice points
custom $InteriorLatticePointColor="30 250 30";
# Color for the visualization of boundary lattice points
custom $BoundaryLatticePointColor="70 150 70";
# Color for the visualization of lattice points
custom $LatticePointColor="70 150 70";
# Local Variables:
# mode: perl
# c-basic-offset:4
# End:
|