function h = viewNormalVectorBnd(input, bnd)
% plot normal vector for boundary
%
% Syntax:  h = viewNormalVectorBnd(angle, bnd)
%  or      h = viewNormalVectorBnd(normalVector, bnd)
%
% View normal vector and fit size to the given boundary shape.
%
% See also: viewBoundary, viewBoundaryShape, obtainBoundary, fitShapeBnd

% 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/>

if length(input) == 1
    normVector = computeNormalFromAngle(input);
elseif size(input, 1) == 2 && size(input, 2) == 1
    % everything OK
    normVector = input;
elseif size(input, 1) == 1 && size(input, 2) == 2
    normVector = input';
else
    error('elk:boundary:wrongInput', ['The normal vector must be ' ...
        'specified either by an angle or by a normal vector']);
end

% calculate distance
normLength = max(normVector' * [bnd.cartX; bnd.cartY]);

% plot
h = plot([0 normVector(1)]*normLength, ...
         [0 normVector(2)]*normLength, 'r-');