classdef PointSet < handle
% A PointSet object represents a collection of points in the plane.
properties
v = Point.empty(); % A vector of Point objects.
n % The number of points
end

methods
% Creates a PointSet Object...
function P = PointSet(n,x,y)
% x and y are length-n vectors
P.n = n;
for k=1:n
if nargin==3
P.v(k) = Point(x(k),y(k));
else
P.v(k) = Point(-5+10*rand(),-5+10*rand());
end
end
end

% Represents the centroid of the PointSet as a Point
function C = Centroid(ThisPointSet)
sx = 0; sy = 0;
n = ThisPointSet.n;
for k=1:n
sx = sx + ThisPointSet.v(k).x;
sy = sy + ThisPointSet.v(k).y;
end
C = Point(sx/n,sy/n);
end

function AddPoint(ThisPointSet,P)
% Adds Point P to ThisPointSet.
n = ThisPointSet.n;
ThisPointSet.v(n+1) = P;
ThisPointSet.n = n+1;
end

function Show(ThisPointSet,c)
% Displays ThisPointSet in color c where c is a character
% from 'kwrgbcmy'
n = ThisPointSet.n;
for k=1:n
ThisPointSet.v(k).Show(c)
end
end

end

end