code: public static int getDirection (double theta)
      {
          theta = ((theta + Math.PI) * 4) / Math.PI;
          return (int)(Math.round(theta) + WEST) % 8;
      }
docs: Returns which of the eight compass directions is associated with the specified angle theta.
  <em>Note:</em> that the angle supplied is assumed to increase clockwise around the origin
  (which screen angles do) rather than counter-clockwise around the origin (which cartesian
  angles do) and <code>NORTH</code> is considered to point toward the top of the screen.