Some quick and dirty C code for converting from cartesian to polar coordinates.

dist  = sqrt( deltaX * deltaX + deltaY * deltaY );
angle = acos( deltaX / dist );

if( angle < 0 )
   angle = -angle;
else if( deltaX <=0 &&   deltaY  < 0  )
   angle=-angle;
else if( deltaX < 0 && !(deltaY <= 0) )
   angle=-angle;

And the other way:polar to cartesian

newX = dist * cos ( angle ); newY = dist * sin ( angle );