/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.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.
*/

#ident "$Project: polymake $$Id: cutting_plane.cc,v 1.10 2004/06/22 16:23:10 gawrilow Exp $"

#include <cutting_plane.h>

namespace polymake { namespace polytope {

Vector<Rational>
cutting_plane_via_barycenter(const Matrix<Rational>& V, const Graph<>& G, int vertex_number) {
   Vector<Rational> cutting_plane=average(rows(V.minor(G.neighbors(vertex_number), All)));
   cutting_plane-=V[vertex_number];
   cutting_plane[0]=0;
   return cutting_plane;
}

Vector<Rational>
cutting_plane_via_normals(const Matrix<Rational>& V, const Matrix<Rational>& F,
			  const IncidenceMatrix<>& VIF, int vertex_number) {
   // translation matrix moves V[vertex_number] into origin
   Matrix<Rational> tau=unit_matrix<Rational>(V.cols());
   tau.col(0) = -V[vertex_number];

   return accumulate(rows( F.minor(VIF.col(vertex_number),All) * tau ), operations::add());
}

} }
