classdef ConvexPoly < handle
% Operations on convex polygons

properties
% A convex polygon has n vertices that are points.
% The bounding circle is a circle that encloses the polygon.
v = Point.empty(); % A vector of polygon vertices.
n % The number of vertices.
C = Circle.empty(); % The bounding circle
end % properties

methods
function P = ConvexPoly(n)
% Construct a random convex polygon with n sides
m = n^2; u = -1+2*rand(m,1); v = -1+2*rand(m,1);
idx = convhull(u,v);
x = u(idx(1:n));
y = v(idx(1:n));
% Create the convex polygon object...
P.n = n;
for k=1:n
P.v(k) = Point(x(k),y(k));
end
% The bounding circle...
xc = mean(x);
yc = mean(x);
r = max(sqrt((x-xc).^2+(y-yc).^2));
P.C = Circle(r,Point(xc,yc));
end

function Translate(ThisConvexPoly,delX,delY)
% delX and delY are real numbers.
% For every vertex in ThisConvexPoly, delX is added to the
% x-coordinate and delY is added to the y-coordinate.
P = ThisConvexPoly;
for k=1:P.n
P.v(k).Translate(delX,delY);
end
P.C.Translate(delX,delY);
end

function Show(ThisConvexPoly,c)
% Plots ThisConvexPoly
% The color is specified by the character c.
% Assumes hold is on.
n = ThisConvexPoly.n;
x = zeros(1,n);
y = zeros(1,n);
for k=1:n
x(k) = ThisConvexPoly.v(k).x;
y(k) = ThisConvexPoly.v(k).y;
end
plot([x x(1)],[y y(1)],c)
end

function alfa = Disjoint(ThisConvexPoly,ThatConvexPoly)
% alfa is true if and only if ThisConvexPoly and ThatConvexPoly
% are disjoint.
end

end % methods
end % classdef