% Script to generate points on the attainable set for the Bushaw Problem
%
% The dynamics are:
% \dot x(1) = x(2); \dot x(2) = u
% with   -1 \le u \le 1
%
% We star from the origin and 
% seek points that can be  attained at t = 1
%
% These points are on the boundary of the attainable set
% K(1;[0;0]) (i.e. t_f =1; and initially at the origin)
% The outward normal  to a separating plane at x(t_f)
% is given by (cos(theta), sin(theta))
% The user is asked to supply values for theta
%
qmag = .1; plot(0,0,'ro'); hold on
%
% first generate the boundary then query for special  points
%
      theta = [0:.02:1]*(-pi/4);
      ts = 1 + tan(theta);
      x = -.5 - ts.^2 + 2.*ts; y = 2*ts - 1; % point on Eastern Boundary
      plot(x,y,'r',-x,-y,'r'); grid on; axis('equal') % use symmetry			 
%
 while 1 > 0
     fprintf('Supply a value for the normal direction (radians) \n ');
     theta = input(' -pi < theta < pi:  ')
     if (theta > pi)
	 break
     end
%
     if  theta <= 3*pi/4  & theta >= 0
	  x = .5; y = 1;
    elseif theta <0 & theta >= -pi/4
	ts = 1 + tan(theta);
	x = -.5 - ts^2 + 2*ts; y = 2*ts - 1;
    elseif theta < -pi/4 & theta >= -pi
	 x = -.5; y = -1;
    else
	ts = 1 + tan(theta);
	x =  .5 + ts^2 - 2*ts; y = 1 - 2*ts ;
    end
%
    plot(x,y,'bo');
    plot([x x+qmag*cos(theta)],[y y+qmag*sin(theta)],'b')
%
end	
