%% ================================================================
% T2 with phi/theta coordinates.
% phi must come before theta in order for the normal to be outward-pointing.
% ----------------------------------------------------------------
% John Kerl
% Math 537A
% 2007-11-27
% ----------------------------------------------------------------

function [x, y, z, ds, dt] = t2setup()

phimin   = 0.0*pi;
phimax   = 2.0*pi;
nphi     = 50;
dphi     = (phimax-phimin)/nphi;

thetamin = 0.0*pi;
thetamax = 2.0*pi;
ntheta   = 50;
dtheta   = (thetamax-thetamin)/ntheta;

% Extend the phi and theta by one unit each to avoid having slits in the
% plotted surface.
[phi, theta] = meshgrid( ...
	phimin:dphi:phimax+dphi, ...
	thetamin:dtheta:thetamax+dtheta);

%% Apply the parameterization to obtain R^3 coordinates


% ^ z
% |
% |      --- theta
% |    /   / \
% +---|---x---|----->  r
% |    \     /
% |      ---
% |
% |
%
% phi is the angle of revolution about the z axis.

z =       sin(theta);
r = 2.0 + cos(theta);
x =  r .* cos(phi);
y =  r .* sin(phi);

ds = dphi;
dt = dtheta;
