function [p,t] = bendc(filename, rx, ry)

% BENDC bends initial mesh element saved in FILENAME over 
% radius RX (XZ plane) and/or RY (YZ plane).
% RX = RY means bending over a sphere surface.
% RX ~= RY means bending over an ellipsoid.

% Usage:  bendc('plate.mat', RX, RY) or
%           bendc('plate', RX, RY) 


%Load the data.
load(filename);

% Bend the mesh through an angle theta1 and theta2 in XZ and 
% YZ plane respectively.

if (rx == 0 | ry == 0)
    error('Radius has to be a non-zero number.');
else
    p(1,:) = cos((p(1,:)./rx)/2).*p(1,:);
    p(3,:) = p(3,:)+sin((p(1,:)./rx)/2).*p(1,:);
    
    p(2,:) = cos((p(2,:)./ry)/2).*p(2,:);
    p(3,:) = p(3,:)+sin((p(2,:)./ry)/2).*p(2,:);
end


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