Calculating a compass angle?
float gScale = .92;  // Scale factor for +1.3Ga setting

            float adjx = x - xOffset; //set to 0 for testing
            float adjy = y - yOffset;//set to 0 for testing

            xs = adjx * gScale; 
            ys = adjy * gScale;
            zs = z * gScale;    

            float heading = atan2(ys, xs);
           if (heading &lt; 0)
            heading += 2*PI; // translate result atan2() from [-PI,PI] to [0, 2*PI]  

            heading += declination / 1000; // Declination for geo area
            if (heading &lt; 0) heading += 2*PI;;

            if (heading &gt; 2*PI) heading -= 2*PI;

            float angle = heading * 180/PI;