%Chapter 5, Example 5.2, Fig 5.2
%Eric Dubois, updated 2018-11-16
%Plot figure for example of continuous domain periodic circ function
%Required functions: Lattice_Points_2d, ds2nfu by Michelle Hirsch
clear all
close all
%Sampling matrix and extent for periodicity lattice
VG = [2 1;0  sqrt(3)];
UL = [-3 -2.5]';
LR = [3 2.5]';
%get the points of the lattice in the desired region 
xoutG = Lattice_Points_2d(VG,UL,LR);

%create the plot
figure

%plot the points
points = plot(xoutG(:,1),xoutG(:,2),'k.');
points(1).MarkerSize= 9;

axis equal
axis off
set(gca,'ydir','reverse'); 
%set region
xlim([-3, 3]);
ylim([-2.5, 2.5]);
hold on

%plot the circ at each of the points of Gamma
radii = 0.5*ones(size(xoutG,1),1);
viscircles(xoutG,radii,'Color','k','LineWidth',.7);

%create the axes
text(3.5,-0.15,'\itx','FontName','times')
text(-0.15, 2.5, '\ity','FontName','times')
%x axis from -3 to 3
[xaxx,xaxy] = ds2nfu([-3 3], [0 0]);
annotation('arrow',xaxx,xaxy,'headlength',5,'headwidth',5);
%y axis from -2.5 to 2.5
[yaxx,yaxy] = ds2nfu([0.0 0.0],[2.5 -2.5]);
annotation('arrow',yaxx,yaxy,'headlength',5,'headwidth',5);

%Label axes
text(1.03,.15,'\itZ','FontName','times');
text(1.97, .15, '2\itZ','FontName','times');
text(-1,.15,'-\itZ','FontName','times');
text(-2.1, .15, '-2\itZ','FontName','times');
text(-.2,.9,'\itZ','FontName','times');
text(-.27,-.9,'-\itZ','FontName','times');
text(-.32,2.0,'2\itZ','FontName','times');
text(-.4,-2.0,'-2\itZ','FontName','times');
text(.53, .15,'\itA','FontName','times');

plot([-.05 .05],[1 1],'k')
plot([-.05 .05],[2 2],'k')
plot([-.05 .05],[-1 -1],'k')
plot([-.05 .05],[-2 -2],'k')

%Draw the unit cell of Gamma
A = 1/sqrt(3);
hex = polyshape([1 0 -1 -1 0 1],[A 2*A A -A -2*A -A]);
plot(hex,'Facecolor','white','EdgeColor','red')
%label unit cells
strPG = '$$\mathcal{P}_{\Gamma}$$';
text(.7,-.42,strPG,'Interpreter','latex');

%Label signal values
text(-1, -1, '0','FontName','times');
nptG = size(xoutG,1);
for rpt = 1:nptG
   text(xoutG(rpt,1)-.25,xoutG(rpt,2)-.27,'1','FontName','times');
end;

set(gcf,'Color',[1 1 1]);
