function drawChain(p)

% unpack the points into x and y
Np = length(p)/2;
x = p(1:Np);
y = p(Np+1:end);
x0 = 0; % first anchor x
y0 = 0; % first anchor y
xn = 1; % second anchor x
yn = 0; % second anchor y
xx = [x0; x(:); xn];
yy = [y0; y(:); yn];
N = Np + 2;
ms = 10; % markersize
plot(xx(1),yy(1),'bs','markersize',ms)
hold on
plot(xx(end),yy(end),'bs','markersize',ms)
for i=2:(N-1)
    plot(xx(i),yy(i),'rs','markersize',ms)
    plot([xx(i) xx(i-1)],[yy(i) yy(i-1)],'r-')
end
plot([xx(N-1) xx(N)],[yy(N-1) yy(N)],'r-')
plot([xx(1) xx(end)], [yy(1) yy(end)], 'k--')
hold off
ymin = -Np/2/10; ymax = Np/2/10;
axis([0 1 ymin ymax])
drawnow

end