I apreciate your code help, now about the ang(x) im confused..

the ang(x) didn't worked for me, because when the angle is for example 351.. it will return -45 .. and i just want positive number so i have to do:
if(angle<0){angle+=360;}

i will check if your code works