Skip to content
Snippets Groups Projects
gtCrystMiller2FourIndexes.m 1.50 KiB
function [hkil, hkil_int] = gtCrystMiller2FourIndexes(hkl, miller_type)
% GTCRYSTMILLER2FOURINDEXES  Converts the Miller notation (hkl) to the
%                            four indexes Miller-Bravais notation
%
%     [hkil, hkil_int] = gtCrystMiller2FourIndexes(hkl, miller_type)
%     --------------------------------------------------------------
%     INPUT:
%       hkl         = <double>   plane normal Miller indexes (Nx3)
%       miller_type = <string>   'plane' / 'direction'
%
%     OUTPUT:
%       hkil        = <double>   Miller-Bravais notation for hexagonal
%                                materials (float allowed)
%       hkil_int    = <double>   Miller-Bravais indexes for hexagonal materials
%                                as integers
%
%     Version 001 22-10-2013 by LNervo
%
%     Ref. LaboTex 3.0: Piotr Ozga, "Hexagonal Axes: Conventions & Conversions"


hkil = zeros(size(hkl,1), 4);

switch miller_type
  case 'direction'
    hkil(:,1) = 2*hkl(:,1) - hkl(:,2);
    hkil(:,2) = 2*hkl(:,2) - hkl(:,1);
    hkil(:,3) = - (hkl(:,1) + hkl(:,2));
    hkil(:,4) = 3*hkl(:,3);

  case 'plane'
    hkil(:,1) = hkl(:,1);
    hkil(:,2) = hkl(:,2);
    hkil(:,3) = - (hkl(:,1) + hkl(:,2));
    hkil(:,4) = hkl(:,3);
end

if nargout > 1
    for ii=1:size(hkil,1)
        tmp = hkil(ii,:);
        tmp((tmp > 10^-9 & tmp <= 0.1) | tmp == 0)=[];
        minimum(ii) = max(min(abs(tmp)), 0);
        hkil_int(ii,:) = hkil(ii,:) ./minimum(ii);
        hkil_int(ii,:) = fix(hkil_int(ii,:));
    end
end

end % end of function