function [p,t] = hemisphere(filename,Center,r)

% HEMISPHERE projects the initial mesh element saved in 
% FILENAME over the surface of a hemisphere 
% Coordinates of the center and the radius are  
% specified by the user.

% Usage:  hemisphere('plate.mat', [0 0 -2], r) or
%         hemisphere('plate', [0 0 -2], r)


% load the data.
load (filename);

if(r==0 | r==inf) 
    error('The radius cannot be zero or infinity.');
elseif(Center(1,1)==inf | Center(1,2)==inf | Center(1,3)==inf | Center(:,:)==0)
    error('Center of the sphere cannot be at origin or at infinity.')
else
    % Get the center of the mesh at origin.
    p(1,:)=p(1,:)-mean(p(1,:));
    p(2,:)=p(2,:)-mean(p(2,:));
    p(3,:)=p(3,:)-mean(p(3,:));

    % Project the mesh over the surface of a hemisphere. 
    Q=p-repmat(Center',[1,length(p)]);
    n=sqrt(sum(Q.*Q,1));
    p=Q./repmat(n,[3,1])*r;
end

% Save and view the result.
save hemisphere p t; 
viewer hemisphere
    
        
    
    
    
    
    