%% ================================================================
% S2 with spherical 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] = s2setup()

%% ----------------------------------------------------------------
% phi sweeps down from the north pole.
phimin   = 0.0;
phimax   = pi;
nphi     = 50;
dphi     = (phimax-phimin)/nphi;

%% ----------------------------------------------------------------
% theta sweeps around in the xy plane.

thetamin = 0.0;
thetamax = 2.0*pi;

%thetamin = pi;
%thetamax = 1.5*pi;

ntheta   = 50;
dtheta   = (thetamax-thetamin)/ntheta;

%% ----------------------------------------------------------------
% Extend the theta by one dtheta unit to avoid having a slit in the
% plotted surface.  Leave out singular values of phi to avoid blow-up
% in the computation of scalar curvature.
[phi, theta] = meshgrid( ...
	phimin+dphi:dphi:phimax-dphi, ...
	thetamin:dtheta:thetamax+dtheta);

%% Apply the parameterization to obtain R^3 coordinates
x  = sin(phi) .* cos(theta);
y  = sin(phi) .* sin(theta);
z  = cos(phi);
ds = dphi;
dt = dtheta;
