function [XR,TR,theta] = createMesh(Ntheta,Nr,degree)
% Nr = 20 ;
% Ntheta = 10 ;

nptheta = degree*Ntheta + 1;
npr = degree*Nr + 1;
npt = nptheta*npr;

r = linspace(15,25,npr) ;
theta_max = 10*pi/180 ;
theta = linspace(-theta_max,theta_max,nptheta) ;

[R,TH ] = meshgrid(r,theta) ;
x = R.*sin(TH) ;
y = R.*cos(TH) ;
XR = [reshape(x,npt,1), reshape(y,npt,1)];

nen = (degree+1)^2;
TR = zeros(Ntheta*Nr,nen);
if degree == 1
    for i=1:Nr
        for j=1:Ntheta
            ielem = (i-1)*Ntheta+j;
            inode = (i-1)*(nptheta)+j;
            TR(ielem,:) = [inode   inode+1   inode+nptheta+1   inode+nptheta];
        end
    end
elseif degree == 2
    for i=1:Nr
        for j=1:Ntheta
            ielem = (i-1)*Ntheta + j;
            inode = (i-1)*2*nptheta + 2*(j-1) + 1;
            nodes_aux = [inode+(0:2)  inode+nptheta+(0:2)  inode+2*nptheta+(0:2)];
            TR(ielem,:) = nodes_aux([1  3  9  7  2  6  8  4  5]);
        end
    end
else
    error('not available element')
end
% Node_number = 1:numel(X) ;
% Node_number = reshape(Node_number,size(X)) ;
%
% node_data = zeros(numel(X),4) ;
% filename = 'nodes_trial.txt' ;
% for i_node = 1:numel(X)
%     node_data(i_node,:) = [Node_number(i_node) , X(i_node) , Y(i_node), 0] ;
% end
%
% % dlmwrite(filename,node_data,'\t')
% % eval(['open ' filename])
%
% ind_ele = 0 ;
%
% for jj = 1:Nr
%     for ii = 1:Ntheta
%         ind_ele = ind_ele +1 ;
%         ele_data(ind_ele,:) = [ind_ele , Node_number(ii+1,jj) , Node_number(ii+1,jj+1), Node_number(ii,jj+1), Node_number(ii,jj)] ;
%     end
% end

% filename = 'elements_trial.txt' ;
% dlmwrite(filename,ele_data,'\t') ;
% eval(['open ' filename])

% XR = node_data(:,2:3) ;
% TR = ele_data(:,2:end) ;

end