% Solutions to Lab12...

% Q1

function Q = Reflect(ThisPoint)
% Q is the reflection of ThisPoint across the 45-degree line
Q = Point(ThisPoint.y,ThisPoint.x);
end

% Q2
function [P,Q] = Diameter(ThisPointSet)
% P and Q are the maximally separated points in ThisPointSet

d = 0;
% Consider all possible pairs of points
n = length(ThisPointSet.v);
for i=1:n-1
for j=i+1:n
% See if the ith and jth points are further apart
% than d...
Pi = ThisPointSet.v(i);
Pj = ThisPointSet.v(j);
dij = Pi.Dist(Pj);
if dij>d
P = Pi;
Q = Pj;
d = dij;
end
end
end
end

% Q3

function alfa = Nested(ThisCircle,AnotherCircle)
% Returns true if and only if one circle encloses the other

C1 = ThisCircle;
C2 = AnotherCircle;

% C1's center is inside C2..
T1 = C1.center.Dist(C2.center) <= C2.r;
% C1's Distance to C2 is greater than its radius...
T2 = C2.Dist(C1.center) >= C1.r;
% Is C1 inside C2?
C1_Is_Inside_C2 = T1 && T2;

% C2's center is inside C1..
S1 = C2.center.Dist(C1.center) <= C1.r;
% C2's Distance to C1 is greater than its radius...
S2 = C1.Dist(C2.center) >= C2.r;
% Is C1 inside C2?
C2_Is_Inside_C1 = S1 && S2;

alfa = C1_Is_Inside_C2 || C2_Is_Inside_C1;
end