function [A,M] = transmatrix(a,b,c,alpha,beta,gamma)
%TRANSMATRIX Calculate transformation matrix and metric tensor for crystal
%system.
%   [A,M] = TRANSMATRIX(a,b,c,alpha,beta,gamma) with a,b,c the lengths of
%   the crystallographic basis vectors and alpha,beta,gamma the interaxial
%   angles produces the transformation matrix A and metric tensor M.
%   
%   TRANSMATRIX is part of the CRYSTALPLOT package.
%
%   References:
%   [1] Dowty, E. (1980). Computing and drawing crystal shapes. American Mineralogist, 65,
%       465-471.
%
%   $Revision: 1.0 $  $Date: 2009/05/18 $

% The following licence is added according to the email stored as
%   agreement.eml.

% Christian Borchert, Copyright 2009, 
%   Max Planck Institute for Dynamics of Complex Technical Systems, 
%   Magdeburg, Germany
%
% 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/>.

nu_1 = sqrt(1 - cos(alpha)^2 - cos(beta)^2 - cos(gamma)^2 +...
        2*cos(alpha)*cos(beta)*cos(gamma) )/sin(alpha);
nu_2 = (cos(gamma) - cos(alpha)*cos(beta))/sin(alpha);

A = [a*(nu_1) 0            0;
     a*(nu_2) b*sin(alpha) 0;
     a*cos(beta) b*cos(alpha) c];

M = A'*A;