1 /* Copyright (c) 1997-2021
2    Ewgenij Gawrilow, Michael Joswig, and the polymake team
3    Technische Universität Berlin, Germany
4    https://polymake.org
5 
6    This program is free software; you can redistribute it and/or modify it
7    under the terms of the GNU General Public License as published by the
8    Free Software Foundation; either version 2, or (at your option) any
9    later version: http://www.gnu.org/licenses/gpl.txt.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 --------------------------------------------------------------------------------
16 */
17 
18 #include "polymake/client.h"
19 #include "polymake/Rational.h"
20 #include "polymake/Matrix.h"
21 #include "polymake/polytope/transform.h"
22 
23 namespace polymake { namespace polytope {
24 
25 template <typename Scalar>
26 BigObject facet_to_infinity(BigObject p_in, const Int inf_facet)
27 {
28    BigObject p_out("Polytope", mlist<Scalar>());
facet_areas(const GenericMatrix<MatrixTop> & Vertices,const IncidenceMatrix<> & Vertices_In_Facets,const GenericMatrix<MatrixTop2> & Facets)29 
30    const Matrix<Scalar> facets=p_in.give("FACETS");
31 
32    const Vector<Scalar> inf_f= facets.row(inf_facet);
33    const Matrix<Scalar> tau=null_space(inf_f);
34    transform_section(p_out, p_in, "FACETS | INEQUALITIES", T(inf_f/tau));
35    transform_section(p_out, p_in, "AFFINE_HULL | EQUATIONS", T(inf_f/tau));
36    transform_section(p_out, p_in, "VERTICES", inv(inf_f/tau));
37    transform_section(p_out, p_in, "LINEALITY_SPACE", inv(inf_f/tau));
38 
39    p_out.take("BOUNDED") << false;
40 
41    return p_out;
42 }
43 
44   UserFunctionTemplate4perl("# @category Producing a polytope from polytopes"
45                             "# Make an affine transformation such that the i-th facet is transformed to infinity"
46                             "# @param Polytope P"
47                             "# @param Int i the facet index"
48                             "# @return Polytope"
49                             "# @author Sven Herrmann"
50                             "# @example [prefer cdd] [require bundled:cdd] This generates the polytope that is the positive quadrant in 2-space:"
51                             "# > $q = new Polytope(VERTICES=>[[1,-1,-1],[1,0,1],[1,1,0]]);"
52                             "# > $pf = facet_to_infinity($q,2);"
53                             "# > print $pf->VERTICES;"
54                             "# | 0 -1 -1"
55                             "# | 0 0 1"
56                             "# | 1 0 1",
57                             "facet_to_infinity<Scalar>(Polytope<Scalar> $)");
58 } }
59 
60 // Local Variables:
61 // mode:C++
62 // c-basic-offset:3
63 // indent-tabs-mode:nil
64 // End:
65