Skip to content
Snippets Groups Projects
Commit 5a0504a1 authored by Laura Nervo's avatar Laura Nervo
Browse files

gtHex2Cart / gtCart2Hex : added option to change convention for hexagonal materials


Signed-off-by: default avatarLaura Nervo <laura.nervo@esrf.fr>
parent 7559bc0e
No related branches found
No related tags found
No related merge requests found
function hkil = gtCart2Hex(hkl, latticepar)
% GTCART2HEX Convert a plane normal in cartesian coordinates (hkl) to the four
% indexes
function hkil = gtCart2Hex(uvw, latticepar, convention)
% GTCART2HEX Converts a plane normal in cartesian coordinates (uvw) to the
% Miller-Bravais indexes in the direct space (hkil)
%
% hkil = gtCart2Hex(uvw, latticepar, convention)
% ----------------------------------------------
% It follows the X-convention using right handed CS.
% From (uvw) direction in cartesian space to (hkil) plane normal in hexagonal real space
%
% hkil = gtCart2Hex(hkl, latticepar)
% ----------------------------------
% INPUT:
% hkl = plane normal Miller indexes <double Nx3>
% latticepar = lattice parameters <double 1x6>
% uvw = <double> plane normal in cartesian coordinates (N,3)
% latticepar = <double> lattice parameters (row vector 1,6)
% convention = <string> hexagonal unit cell convention {'X'}/'Y'
%
% OUTPUT:
% hkil = cartesian coordinates for hexagonal materials
%
% Version 002 25-11-2011 by LNervo
% *** update version ***
% hkil = <double> plane normal in hexagonal direct space described by
% Miller-Bravais indexes (N,4)
%
% Version 001 June-2008 by AKing
% Four index hexagonal coordinates are given!
% reverse of the formulae implemented by Sabine in gtForwardSimulate_360
% the output {hkil} is not normalised in any way.
% Version 002 25-10-2013 by LNervo
if ~exist('convention','var') || isempty(convention)
convention = 'X';
end
if strcmp(convention, 'X')
% rotates counterclockwise
uvw = rotateVectors(uvw,'angle',30,'axis',[0 0 1]);
end
hkil=zeros(size(hkl,1), 4);
hkil = zeros(size(uvw,1), 4);
%change to hexagonal axes
hkil(:,1) = hkl(:,1) - (hkl(:,2)/sqrt(3));
hkil(:,2) = hkl(:,2)*2/sqrt(3);
hkil(:,3) = -(hkil(:,1)+hkil(:,2));
hkil(:,4) = hkl(:,3);
% change to hexagonal axes
hkil(:,1) = uvw(:,1)*sqrt(3)/2 - uvw(:,2)/2;
hkil(:,2) = uvw(:,2);
hkil(:,3) = -(hkil(:,1) + hkil(:,2));
hkil(:,4) = uvw(:,3);
%allow for unit cell parameters
hkil(:,1:3) = hkil(:,1:3)*(latticepar(1)*sqrt(3))/2;
% allow for unit cell parameters
hkil(:,1:3) = hkil(:,1:3)*latticepar(1);
hkil(:,4) = hkil(:,4)*latticepar(3);
end % end function
end % end of function
function normalised_hkls = gtHex2Cart(all_hkils, latticepar)
% GTHEX2CART
% normalised_hkls = gtHex2Cart(all_hkils, latticepar)
% ---------------------------------------------------
% Transforms from direct hexagonal to cartesian coordinates
% and normalise
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
%
% Same as the old function gtCrystHKL2Cart
% 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
all_hkls(:, 1) = all_hkils(:, 1) + 0.5 * all_hkils(:, 2);
all_hkls(:, 2) = sqrt(3)/2 * all_hkils(:, 2);
all_hkls(:, 3) = all_hkils(:, 4);
uvw(:,1) = hkil(:,1)*2/sqrt(3) + hkil(:,2)/sqrt(3);
uvw(:,2) = hkil(:,2);
uvw(:,3) = hkil(:,4);
all_hkls(:, 1) = all_hkls(:, 1)*2/(sqrt(3)*latticepar(1));
all_hkls(:, 2) = all_hkls(:, 2)*2/(sqrt(3)*latticepar(1));
all_hkls(:, 3) = all_hkls(:, 3)/latticepar(3);
%scale with unit cell parameters
uvw(:,1) = uvw(:,1)/latticepar(1);
uvw(:,2) = uvw(:,2)/latticepar(1);
uvw(:,3) = uvw(:,3)/latticepar(3);
% normalise hkls vector
tmp = sqrt(sum((all_hkls.*all_hkls),2));
normalised_hkls = all_hkls./(repmat(tmp,1,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]);
end
end % end of function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment