function [M, theta] = wamrot(P,n,r0,z0,omega)

%---------------------------------------------------------------

% This function starting from a 2d mesh P, 
% creates a 3d toroidal mesh M around center z0, radius r0
% and angle omega. The output variable theta corresponds
% to 2n+1 Chebyshev-like angles in the rotation interval

%

% by Stefano De Marchi and Marco Vianello, University of Padova 

% 

% January 2013

%---------------------------------------------------------------

M=[];

theta=angles(n,omega);

for k=1:length(theta)

    r=r0+P(:,1);

    z=z0+P(:,2); 

    M=[M; [r.*cos(theta(k)) r.*sin(theta(k)) z]];

end

end


function theta= angles(n,omega)

% computes the 2n+1 angles theta for trigonometric interpolation 
% of degree n on [-omega,omega] subseteq [-pi,pi]

% input
% n: trigonometric degree 
% omega: half-length of the angular interval, 0<omega<=pi

% output
% theta: 1-column array of the 2n+1 angular nodes

k=[0:1:2*n];
theta=2*asin(sin(omega/2)*cos((pi*k+pi/2)/(2*n+1)));

end


