Skip to content
Snippets Groups Projects
gtHex2Cart.m 1.48 KiB
Newer Older
function uvw = gtHex2Cart(hkil, latticepar, convention)
% GTHEX2CART  Converts a plane normal in direct hexagonal space described by 
%             Miller-Bravais indexes (hkil) to the cartesian coordinates in the 
%             real space (uvw) normalising it
%     uvw = gtHex2Cart(hkil, latticepar, convention)
%     ----------------------------------------------
%     It follows the X-convention using right handed CS
%     From (hkil) plane normal in real space to (uvw) direction in cartesian space
%     INPUT:
%       hkil       = <double>   Miller-Bravais indexes (N,4)
%       latticepar = <double>   Lattice parameters (1,6)
%       convention = <string>   hexagonal unit cell convention {'X'}/'Y'
%
%     OUTPUT:
%       uvw        = <double>   Direction of plane normal in the cartesian
%                               normalised space (N,3)
%
%     Version 002 25-10-2013 by LNervo
if ~exist('convention','var') || isempty(convention)
    convention = 'X';
end

% going to cartesian reciprocal space + normalisation of the cartesian
% space
uvw(:,1) = hkil(:,1)*2/sqrt(3) + hkil(:,2)/sqrt(3);
uvw(:,2) = hkil(:,2);
uvw(:,3) = hkil(:,4);
%scale with unit cell parameters
uvw(:,1) = uvw(:,1)/latticepar(1);
uvw(:,2) = uvw(:,2)/latticepar(1);
uvw(:,3) = uvw(:,3)/latticepar(3);
tmp = sqrt(sum((uvw.*uvw),2));
uvw = uvw./(repmat(tmp,1,3));
if strcmp(convention, 'X')
% rotates counterclockwise
    uvw = rotateVectors(uvw,'angle',30,'axis',[0 0 1]);