I will define two variables:
ca=Math.atan2(y,x);
cb=Math.atan2(ys,xs);

And replace all the Math.atan2(y,x) with ca, and Math.atan2(ys,xs) with cb.
So that the code do not to call Math.atan2 a lot of times (especially inside loops).

Try to reduce calculation inside any loop. It will make the program more efficient.