classdef Point < handle
% A point has an x and y coordinate
    
    properties
       x
       y
    end
    
    methods
        % Construct a point object
        function P = Point(x,y)
           if nargin==2
              P.x = x;
              P.y = y;
           end
        end
        
        function Q = Rotate(ThisPoint,angle)
            % Rotates ThisPoint by angle degrees counterclockwise.
            theta = angle*pi/180;
            c = cos(theta);
            s = sin(theta);
            x = ThisPoint.x;
            y = ThisPoint.y;
            if nargout == 1
               Q = Point(c*x - s*y, s*x + c*y);
            else
                ThisPoint.x = c*x - s*y;
                ThisPoint.y = s*x + c*y;
            end       
        end
        
        function d = Dist(ThisPoint,Q)
            % The distance from ThisPoint to object Q.
            % Q must be either a Point or a Circle
            if strcmp(class(Q),'Point')
                d = sqrt((ThisPoint.x-Q.x)^2 + (ThisPoint.y-Q.y)^2);
            elseif strcmp(class(Q),'Circle')
                d = abs(ThisPoint.Dist(Q.center) - Q.r);
            end
        end
        
        function Show(ThisPoint,color)
            % Display ThisPoint in the current figure window with
            % color c. The value of c is one of the characters in
            % 'kwrgbmcy'.
            plot(ThisPoint.x,ThisPoint.y,['.' color], 'Markersize',30)
        end
        
        
    end %methods
    
end %classdef