function [xNew,yNew] = NewPoly(x,y)
% x and y are column vectors that encode the xy-coordinates
% of a polygon.
% xNew and yNew are column vectors that encode the xy-coordinates
% of a new polygon obtained by connecting midpoints of the edges
n = length(x);
xNew = zeros(1,n);
yNew = zeros(1,n);
for k=1:n-1
% Compute the midpoint of the k-the edge
xNew(k) = (x(k) + x(k+1))/2;
yNew(k) = (y(k) + y(k+1))/2;
end
% The last edge requires special treatment to avoid a subscript problem..
xNew(n) = (x(n) + x(1))/2;
yNew(n) = (y(n) + y(1))/2;
d = max(sqrt(xNew.^2 + yNew.^2));
xNew = xNew/d;
yNew = yNew/d;
%d = max(sqrt(xNew.^2+yNew.^2));
%xNew = xNew/d;
%yNew = yNew/d;