don't to worry! i did it!

done!

tn = Math.atan2(y,x);
tns =Math.atan2(ys,xs);

if (Math.abs(tn-tns)>pi) // test whether tn = +3.1 and tns = -2.9 , pi is an arbitrary large angle that i thought was convience
{
dcangle = (Math.atan2(y,x)[b][color=blue]-2*pi[/color][/b]-Math.atan2(ys,xs))/(n-2);
}
else
{
dcangle = (Math.atan2(y,x)-Math.atan2(ys,xs))/(n-2);// same as before
}