use the distance formula
[tex]\sqrt{(x2-w1)^{2} +(y2-y1) ^{2} }[/tex]
You ll need to do it t times:
x1 y1 x2 y2
(-1, 5) (4, 2) = (-1, 5) (4, 2)
(4, 2) (0,0)
(0,0) (5,5)
(5,5) (-1, 5)
then add all your results