classdef E0 < handle
    % An E0 object represents the ellipse 
    %                (a*cos(t),b*sin(t))        0<=t<=2pi  
    % Such an ellipse is centered at (0,0) and has no tilt
   
    properties (Access = protected)
        a                    % The major semiaxis
        b                    % The minor semi-axis (b<=a)
        F1 = Point.empty();  % Focus
        F2 = Point.empty();  % Focus
        s                    % string length
    end
    
    methods
        function E = E0(a,b)
        % Constructs an E0 object
          if a >= b
             E.a = a;
             E.b = b;
             E.F1 = Point(-sqrt(a^2-b^2),0);
             E.F2 = Point(sqrt(a^2-b^2),0);
             E.s = 2*a; 
          else
             disp('a cannot be smaller than b')
          end
        end
        
        function A = Area(ThisE0)
        % The area of the ellipse referenced by ThisE0.
            A = pi*ThisE0.a*ThisE0.b;
        end
        
        function alfa = Enclose(ThisE0,P)
        % alfa is one if the point referenced by P is inside the
        %   ellipse referenced by ThisE0. 
        % Otherwise, alfa is zero.
            alfa = P.Dist(ThisE0.F1)+P.Dist(ThisE0.F2) <= ThisE0.s;
        end
        
        function Show(ThisE0,c)
        % Displays the ellipse referenced by ThisE0 in the current figure window
        % with color c. The two focii are also displayed. Assumes hold is
        % on 
           a = ThisE0.a;
           b = ThisE0.b;
           F1 = ThisE0.F1;
           F2 = ThisE0.F2;
           x = a*cos(linspace(0,2*pi));
           y = b*sin(linspace(0,2*pi));
           plot(x,y,c)
           plot(F1.x,0,'.k','Markersize',20)
           plot(F2.x,0,'.k','Markersize',20)
        end
                
    end
    
end

