function Hrep = normalizeHrep(Hrep)
% normalize length of facet normals to 1
%
% Syntax: Hrep = normalizeHrep(Hrep)
%
% An H-representation is not unique. For a facet normal a[i] and a facet
%   distance h[i] and any g > 0 it the halfspace defined by the facet
%   normal g*a[i] and g*h[i] is identical to the original halfspace. A
%   normalized H-representation is unique and it holds:
%     norm(a[i], 2) = 1
%
% See also: movePolytope, stretchPolytope, rotatePolytope

% The elk-library: convex geometry applied to crystallization modeling.
%   Copyright (C) 2012 Alexander Reinhold
%
% 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 3 of the License, or (at your 
%   option) any later version.
%
% 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.
%
% You should have received a copy of the GNU General Public License along 
%   with this program.  If not, see <http://www.gnu.org/licenses/>.

for iFacet = 1:length(Hrep.h)
    thisNorm = norm(Hrep.A(iFacet, :), 2);
    Hrep.h(iFacet) = Hrep.h(iFacet) / thisNorm;
    Hrep.A(iFacet, :) = Hrep.A(iFacet, :) / thisNorm;
end