% ShowPointCircle
% Manipulating Point and Circle Objects
clc
clear
close all
figure
plot([-5 5],[0 0],':k',[0 0],[-5 5],':k') 
axis equal square
hold on
pause
% Create a point...
xlabel('P = Point(3,0);    P.Show(''r'')             ','fontsize',18)
pause
P = Point(3,0);
P.Show('r')
h = text(3.5,0,'P','fontsize',14);
xlabel('                                                            ')
pause

% Rotate it...
xlabel('P.Rotate(45);    P.Show(''r'')             ','fontsize',18)
pause
delete(h)
P.Rotate(45);
P.Show('r')
h = text(2.5,2,'P','fontsize',14);
xlabel('                                                              ')
pause

% Get a new point through translation...
xlabel('P1 = P.Translate(0,-5);    P1.Show(''g'')             ','fontsize',18)
pause
P1 = P.Translate(0,-5);
P1.Show('g')
h1 = text(2.5,-3,'P1','fontsize',14);
xlabel('                                                              ')
pause

% Get another new point through translation...
xlabel('P2 = P.Translate(-5,-4);    P2.Show(''g'')             ','fontsize',18)
pause
P2 = P.Translate(-5,-4);
P2.Show('g')
h2 = text(-3,-1.5,'P2','fontsize',14);
xlabel('                                                              ')
pause

% Find the nearest point on a line segment
plot([P1.x,P2.x],[P1.y P2.y],'g')
xlabel('R = Nearest(P,P1,P2);    R.Show(''b'')             ','fontsize',18)
pause
R = Nearest(P,P1,P2);
R.Show('b')
h3 = text(1,-3,'R','fontsize',14);
xlabel('                                                              ')
pause

% Create a circle...
xlabel('C1 = Circle(1,Point(0,0));             C1.Show(''m'')','fontsize',18)
pause
C1 = Circle(1,Point(0,0));
C1.Show('m')
h4 = text(-1,1,'C1','fontsize',14);
xlabel('                                                              ')
pause

% Create another circle through translation...
xlabel('C2 = C1.Translate(-R.x,-R.y);             C2.Show(''m'')','fontsize',18)
pause
C2 = C1.Translate(R.x,R.y);
C2.Show('m')
h5 = text(0,-2,'C2','fontsize',14);
xlabel('                                                              ')
pause

% Compute some distances...
xlabel('PtoR = P.Dist(R);     PtoC1 = P.Dist(C2)','fontsize',18)
pause
PtoR = P.Dist(R);
PtoC2 = P.Dist(C2);
title(sprintf('PtoR  = %5.3f    PtoC2 = %5.3f',PtoR,PtoC2),'fontsize',18)

