/* Copyright (c) 1997-2010
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Darmstadt, Germany)
   http://www.polymake.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: 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.
--------------------------------------------------------------------------------
   $Project: polymake $$Id: zonotope.cc 9991 2010-12-12 23:36:28Z gawrilow $
*/

#include "polymake/client.h"
#include "polymake/Rational.h"
#include "polymake/Matrix.h"

namespace polymake { namespace polytope {
  
Matrix<Rational> zonotope(const Matrix<Rational>& Zones)
{
   const int dim=Zones.cols();
   Matrix<Rational> Zonotope(1,dim);    // one zero-filled row
    
   for (Entire< Rows< Matrix<Rational> > >::const_iterator z=entire(rows(Zones)); !z.at_end(); ++z)
      Zonotope = ( Zonotope + repeat_row(*z, Zonotope.rows()) ) /
         ( Zonotope - repeat_row(*z, Zonotope.rows()) );
   Zonotope.col(0).fill(1);

   return Zonotope;
}

UserFunction4perl("# @category Producing from given data"
                  "# Produce the points of a zonotope from the vectors given in //zones//."
                  "# The zonotope is obtained as the iterated Minkowski sum of all intervals [-x,x],"
                  "# where x ranges over the rows of a given matrix."
                  "# @param Matrix zones the input vectors"
                  "# @return Matrix",
                  &zonotope,"zonotope(Matrix<Rational>)");
} }

// Local Variables:
// mode:C++
// c-basic-offset:3
// indent-tabs-mode:nil
// End:
