diff --git a/zUtil_Cryst/gtCart2Hex.m b/zUtil_Cryst/gtCart2Hex.m index 64b8ca1284c5c97bd274b3d6891f87794cf14563..0e70de92b1d332ee1a2807fdcefebb1008068539 100644 --- a/zUtil_Cryst/gtCart2Hex.m +++ b/zUtil_Cryst/gtCart2Hex.m @@ -1,35 +1,43 @@ -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 diff --git a/zUtil_Cryst/gtHex2Cart.m b/zUtil_Cryst/gtHex2Cart.m index b4af0bd772fba498f1cae04fcb643a2bf7709c6c..7b84899bd25271ff8046300db426968ce09743c6 100644 --- a/zUtil_Cryst/gtHex2Cart.m +++ b/zUtil_Cryst/gtHex2Cart.m @@ -1,25 +1,46 @@ -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