function [X,Y] = ellipse(a,b,theta)

% ELLIPSE[X Y] = (A,B,THETA)  Function to plot an ellipse given semi-axes A and B 
%   and a rotation angle THETA.  The angle THETA is considered to be
%   positive anti-clockwise from the x-axis

% set degree to radian conversion factor
d2r = pi/180;

% Calculate u,v coordinates of ellipse using parametric equations
% u = a*cos(psi)
% v = b*sin(psi)
% where the u-axis is the major axis, the v-axis is the minor axis and psi is the auxiliary angle 
% measured positive anti-clockwise from the u-axis to a point moving around the auxiliary circle of 
% radius a.
% The x,y coordinates are computed by rotating the ellipse axes by an angle theta, considered as 
% positive anti-clockwise from the x-axis.
% x = u*cos(theta) - v*sin(theta)
% y = u*sin(theta) + v*cos(theta)

for k=1:360
  u    = a*cos(k*d2r);  
  v    = b*sin(k*d2r);  
  X(k) = u*cos(theta*d2r) - v*sin(theta*d2r);
  Y(k) = u*sin(theta*d2r) + v*cos(theta*d2r);
end
return




