function B2 = translatequadratic(B,T)
%TRANSLATEQUADRATIC Translates coefficients of a quadratic
% 
%   B2 = TRANSLATEQUADRATIC(B,T) where B are the coefficients [c b a]
%   of a quadratic having the form y = ax^2 +bx +c, and T is a vector
%   [row col] indicating the amount by which to translate the
%   quadratic's origin.  

% Copyright (c) 2011
% Jerod Weinman
% jerod@acm.org

% $Id: translatequadratic.m 595 2014-10-24 18:15:54Z weinman $
 
% Jerod Weinman, Zach Butler, Dugan Knoll, Alexander Turner, Yirong Jing
% jerod@acm.org
% Copyright 2011, 2012, 2013, 2014
 
%    This file is part of PIONEER WordNorm.
%
%    PIONEER WordNorm 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.
%
%    PIONEER WordNorm 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 PIONEER WordNorm.  If not, see <http://www.gnu.org/licenses/>.

if length(B)==3 && B(3)~=0
    % Complete The Square to find H and K.
    H = -B(2)/(2*B(3));
    K = B(1)-B(2)^2/(4*B(3));
    % Add the T values to translate the origin.
    H = H + T(2);
    K = K + T(1);
    H = -H;
    % Convert back to a quadratic's coefficients.
    B2(3) = B(3); % a = a
    B2(2) = 2*B(3)*H; % b = -2ah
    B2(1) = B(3) * H^2 + K; %c = k + b^2/4a
else
    B2(2) = B(2); % b
    B2(1) = -B(2)*T(2) + B(1) + T(1); % c
    if length(B)==3
      B2(3) = 0;  % a
    end
end

end % translatequadratic
