Skip to content

Commit

Permalink
add xyz and hkl to plotbase
Browse files Browse the repository at this point in the history
  • Loading branch information
tsdev committed Feb 13, 2017
1 parent 8e089a4 commit 921417b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
43 changes: 33 additions & 10 deletions swfiles/+swplot/plotbase.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
%
% Options:
%
% mode String that determines the type base to plot. Possible values
% are:
% abc Plots the lattice vectors, default.
% xyz Plots the lattice Descartes coordinate system.
% hkl Plots the reciprocal lattice vectors.
% length Determines the length of the a, b and c arrows. If 0, the
% length will be equal to the corresponding lattice parameters,
% while if non-zero, the number determines the length in
Expand Down Expand Up @@ -37,7 +42,7 @@
nPatch0 = swpref.getpref('npatch',[]);

inpForm.fname = {'range' 'mode' 'figure' 'color' 'R' 'alpha' 'lhead' 'shift'};
inpForm.defval = {range0 'default' [] col0 0.06 30 0.5 [0;0;0]};
inpForm.defval = {range0 'abc' [] col0 0.06 30 0.5 [0;0;0]};
inpForm.size = {[-1 -2] [1 -3] [1 1] [-4 -5] [1 1] [1 1] [1 1] [3 1] };
inpForm.soft = {false false true false false false false false };

Expand All @@ -61,8 +66,13 @@

% range of previous plot
rDat = getappdata(hFigure,'range');
range0 = rDat.range;
unit = rDat.unit;
if isempty(rDat)
range0 = [0 1;0 1;0 1];
unit = 'lu';
else
range0 = rDat.range;
unit = rDat.unit;
end

if isempty(range0)
range0 = [0;0;0];
Expand All @@ -73,6 +83,18 @@
% basis vectors
BV = swplot.base(hFigure);

switch param.mode
case 'abc'
pBase = eye(3);
axText = {'a' 'b' 'c'};
case 'xyz'
pBase = inv(BV);
axText = {'x' 'y' 'z'};
case 'hkl'
pBase = 2*pi*inv(BV)^2;
axText = {'h' 'k' 'l'};
end

switch unit
case 'lu'
% do nothing
Expand All @@ -86,17 +108,18 @@
% convert d from xyz to base
d = (param.d/(BV'))'-range0;

% lattice parameters
length0 = sqrt(sum(BV.^2,1));
% vector length
length0 = sqrt(sum((BV*pBase).^2,1));

if param.length == 0
Rend = ones(1,3);
% do nothing
else
% normalize the length of the vectors
Rend = param.length./length0;
pBase = bsxfun(@times,pBase,param.length./length0);
length0 = param.length;
end

pos = bsxfun(@minus,cat(3,zeros(3),diag(Rend)),d);
pos = bsxfun(@minus,cat(3,zeros(3),pBase),d);

% shift
pos = bsxfun(@plus,pos,BV\param.shift);
Expand All @@ -106,10 +129,10 @@

if param.label
% convert d from xyz to base
pos_text = bsxfun(@minus,bsxfun(@times,diag(Rend),1+param.dtext./(length0.*Rend)),d);
pos_text = bsxfun(@minus,bsxfun(@times,pBase,1+param.dtext./length0),d);
pos_text = bsxfun(@plus,pos_text,BV\param.shift);

swplot.plot('type','text','position',pos_text,'text',{'a' 'b' 'c'},'data',data,...
swplot.plot('type','text','position',pos_text,'text',axText,'data',data,...
'figure',hFigure,'legend',false,'tooltip',false,'translate',false,...
'zoom',false,'name','base_label','replace',param.replace);
end
Expand Down
23 changes: 17 additions & 6 deletions swfiles/sw_cartesian.m
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
function [vy, vz, vx] = sw_cartesian(n)
function [vyOut, vzOut, vxOut] = sw_cartesian(n)
% creates a right handed Cartesian coordinate system
%
% [vy, vz, vx] = SW_CARTESIAN(n)
%
% It creates an (x,y,z) right handed Cartesian coordinate system.
% V = SW_CARTESIAN(n)
%
% It creates an (x,y,z) right handed Cartesian coordinate system with vx,
% vy and vz defines the basis vectors. If only a single output is required,
% V will contain the basis vectors in a matrix: V = [vx vy vz].
%
% Input:
%
Expand Down Expand Up @@ -51,9 +55,16 @@
error('sw_cartesian:WrongInput','Wrong size of n!')
end

% Conserves the shape of the input vector.
vy = reshape(vy/norm(vy),nShape);
vz = reshape(vz/norm(vz),nShape);
vx = reshape(n/norm(n),nShape);

if nargout == 1
% return a matrix
vyOut = [n/norm(n) vy/norm(vy) vz/norm(vz)];
else
% conserve the shape of the input vector.
vyOut = reshape(vy/norm(vy),nShape);
vzOut = reshape(vz/norm(vz),nShape);
vxOut = reshape(n/norm(n),nShape);

end

end

0 comments on commit 921417b

Please sign in to comment.