function data=s_rect(xy,dx,dy)

% function data=s_rect(xy,dx,dy)
%
% This function is used in conjuction with FD3.  If the function is called
% with three arguments, 'xy' is the vector containing the [x, y] coordinate
% of the center, 'dx' is the horizontal distance between the left or right
% edge of the rectangle and the center, and 'dy' if the vertical distance
% between the top or bottom edge of the rectangle and the center.  If the
% function is called with one argument 'xy', 'xy' will represent the [x, y]
% coordinate of the top of the tank the first time the function is called, and
% 'xy' will represent the [x, y] coordinate of one corner of the tank the
% second time the function is called.  The former method of sending
% information to s_rect is employed during the load process while the
% latter method is employed when an FD3 user creates a rectangle by clicking
% on the window two times.  See 'user_def' for a complete explanation of the
% information contained in 'data'.
%
% ACP

% Last update:  July 11, 1993
% Author:       Adrian C. Penisson

global FD3FUNCLEVEL FD3LASTPOS FD3MESSAGE FD3AXES

if nargin==1

   if FD3FUNCLEVEL==0

      str='Point and|click on a|corner of the|rectangle.';
      FD3MESSAGE=di_mssg(str);
      FD3LASTPOS=xy;   
      FD3FUNCLEVEL=1;

      return

   elseif FD3FUNCLEVEL==1

      z1=FD3LASTPOS(1,1)+i*FD3LASTPOS(1,2);
      z2=xy(1,1)+xy(1,2)*i;
      dz=z2-z1;
      r=abs(real(z2-z1));
      dx=abs(real(dz));
      dy=abs(imag(dz));

   end

elseif nargin>1

   x=xy(1,1);
   y=xy(1,2);

   z1=x+y*i;

end

data=z1+[dx+i*dy,-dx+i*dy,-dx-i*dy,dx-i*dy,dx+i*dy];

axes(FD3AXES(3))

h=line(real(data),imag(data));

theta1=atan2(dy,dx);
theta2=pi-theta1;
theta3=2*pi-theta2;
theta4=2*pi-theta1;

FD3FUNCLEVEL=0;
FD3LASTPOS=[];

data=[h 0 0 real(z1) imag(z1) 3 dx dy 0 theta1 theta2 theta3 theta4 1 1];
