
n = 20;   % plots an n by n grid of quadrilateral cells from certain slices
          % of 3d grid.  

% Plot quarter sphere:

clf

n2 = n/2;
[x1,x2] = meshgrid(linspace(0,1,n2+1), linspace(0,1,n2+1));
one = ones(size(x1));

xc = x1;
yc = x2;
zc = one;
[xp,yp,zp] = mapc2p(xc,yc,zc);
surf(xp,yp,zp)

hold on
zc = -one;
[xp,yp,zp] = mapc2p(xc,yc,zc);
surf(xp,yp,zp)

[x1,x2] = meshgrid(linspace(0,1,n2+1), linspace(-1,1,n+1));
zero = zeros(size(x1));
xc = x1;
yc = zero;
zc = x2;
[xp,yp,zp] = mapc2p(xc,yc,zc);
surf(xp,yp,zp)

xc = zero;
yc = x1;
zc = x2;
[xp,yp,zp] = mapc2p(xc,yc,zc);
surf(xp,yp,zp)


colormap([1 1 1]);   
daspect([1 1 1])
axis([0 1 0 1 -1 1])
axis off
hold off
